From 15d41550f7f8503e0269b09622fe4c62b73b90ec Mon Sep 17 00:00:00 2001 From: tooyosi Date: Fri, 26 Jan 2024 16:57:30 +0000 Subject: [PATCH 1/4] implement logic to append deleted to inactive project slug --- app/controllers/api/v1/projects_controller.rb | 9 +++++++++ spec/controllers/api/v1/projects_controller_spec.rb | 5 +++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index c28b62435..f4bd9f74a 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -63,6 +63,15 @@ def update end end + def destroy + super do |resource| + split_display_name = resource.display_name.split('_') + if split_display_name[split_display_name.length - 1] != 'deleted' + resource.update(display_name: "#{resource.display_name}_deleted") + end + end + end + def create_classifications_export medium = CreateClassificationsExport.with( api_user: api_user, object: controlled_resource ).run!(params) export_medium_response(medium) diff --git a/spec/controllers/api/v1/projects_controller_spec.rb b/spec/controllers/api/v1/projects_controller_spec.rb index 96f6540e8..0ffc23630 100644 --- a/spec/controllers/api/v1/projects_controller_spec.rb +++ b/spec/controllers/api/v1/projects_controller_spec.rb @@ -846,6 +846,11 @@ def tag_request let(:instances_to_disable) { [resource] } it_behaves_like 'is deactivatable' + + it "should append 'delete' to display_name" do + delete :destroy, params: {id: resource.id} + expect(resource.display_name).to end_with('delete') + end end describe '#copy' do From a7b16ed1e6e3dc7532789ed8f3db35e70d48c9ce Mon Sep 17 00:00:00 2001 From: tooyosi Date: Fri, 26 Jan 2024 18:21:26 +0000 Subject: [PATCH 2/4] fix test --- spec/controllers/api/v1/projects_controller_spec.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/controllers/api/v1/projects_controller_spec.rb b/spec/controllers/api/v1/projects_controller_spec.rb index 0ffc23630..7467ba453 100644 --- a/spec/controllers/api/v1/projects_controller_spec.rb +++ b/spec/controllers/api/v1/projects_controller_spec.rb @@ -847,10 +847,12 @@ def tag_request it_behaves_like 'is deactivatable' - it "should append 'delete' to display_name" do + it "appends 'deleted' to display_name" do + stub_token(scopes: scopes, user_id: authorized_user.id) + set_preconditions delete :destroy, params: {id: resource.id} - expect(resource.display_name).to end_with('delete') - end + expect(resource.reload.display_name).to end_with('deleted') + end end describe '#copy' do From 0096a7a7a454b192a54904b15aa61eac06e1544d Mon Sep 17 00:00:00 2001 From: tooyosi Date: Mon, 29 Jan 2024 09:38:21 +0000 Subject: [PATCH 3/4] modifications to code style --- app/controllers/api/v1/projects_controller.rb | 4 +--- spec/controllers/api/v1/projects_controller_spec.rb | 9 ++++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index f4bd9f74a..c1a8b1ccf 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -66,9 +66,7 @@ def update def destroy super do |resource| split_display_name = resource.display_name.split('_') - if split_display_name[split_display_name.length - 1] != 'deleted' - resource.update(display_name: "#{resource.display_name}_deleted") - end + resource.update(display_name: "#{resource.display_name}_deleted") unless split_display_name[split_display_name.length - 1] == 'deleted' end end diff --git a/spec/controllers/api/v1/projects_controller_spec.rb b/spec/controllers/api/v1/projects_controller_spec.rb index 7467ba453..c972c3d3e 100644 --- a/spec/controllers/api/v1/projects_controller_spec.rb +++ b/spec/controllers/api/v1/projects_controller_spec.rb @@ -845,14 +845,13 @@ def tag_request let(:resource) { create(:full_project, owner: user) } let(:instances_to_disable) { [resource] } - it_behaves_like 'is deactivatable' - + it_behaves_like 'is deactivatable' it "appends 'deleted' to display_name" do stub_token(scopes: scopes, user_id: authorized_user.id) set_preconditions - delete :destroy, params: {id: resource.id} - expect(resource.reload.display_name).to end_with('deleted') - end + delete :destroy, params: { id: resource.id } + expect(resource.reload.display_name).to end_with('deleted') + end end describe '#copy' do From feae08e7b75fc883d2b5ea2d7f47dc886d980bc8 Mon Sep 17 00:00:00 2001 From: tooyosi Date: Mon, 29 Jan 2024 09:39:50 +0000 Subject: [PATCH 4/4] modifications to code style --- spec/controllers/api/v1/projects_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/controllers/api/v1/projects_controller_spec.rb b/spec/controllers/api/v1/projects_controller_spec.rb index c972c3d3e..0a4dd74cd 100644 --- a/spec/controllers/api/v1/projects_controller_spec.rb +++ b/spec/controllers/api/v1/projects_controller_spec.rb @@ -845,7 +845,7 @@ def tag_request let(:resource) { create(:full_project, owner: user) } let(:instances_to_disable) { [resource] } - it_behaves_like 'is deactivatable' + it_behaves_like 'is deactivatable' it "appends 'deleted' to display_name" do stub_token(scopes: scopes, user_id: authorized_user.id) set_preconditions