From 0ee07f80c0ee2186cc6ab72bc173b9c1a134adb6 Mon Sep 17 00:00:00 2001 From: Simon Tharby Date: Thu, 29 Aug 2024 21:34:19 +0100 Subject: [PATCH 1/3] [TAN-2512] dependent destroy idea_import_files & children when project deleted --- back/app/models/project.rb | 1 + .../app/models/bulk_import_ideas/idea_import_file.rb | 2 +- .../app/models/bulk_import_ideas/patches/project.rb | 7 +++++++ env_files/back-safe.env | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/patches/project.rb diff --git a/back/app/models/project.rb b/back/app/models/project.rb index 33a19d06db24..58eb18d4be05 100644 --- a/back/app/models/project.rb +++ b/back/app/models/project.rb @@ -287,3 +287,4 @@ def old_folder_moderators Project.include(ContentBuilder::Patches::Project) Project.include(Analysis::Patches::Project) Project.include(EmailCampaigns::Extensions::Project) +Project.include(BulkImportIdeas::Patches::Project) diff --git a/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/idea_import_file.rb b/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/idea_import_file.rb index 741e9a1fe744..21c61fd2e685 100644 --- a/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/idea_import_file.rb +++ b/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/idea_import_file.rb @@ -35,7 +35,7 @@ class IdeaImportFile < ApplicationRecord belongs_to :project, optional: true belongs_to :parent, class_name: 'BulkImportIdeas::IdeaImportFile', optional: true - has_many :children, class_name: 'BulkImportIdeas::IdeaImportFile', foreign_key: 'parent_id' + has_many :children, class_name: 'BulkImportIdeas::IdeaImportFile', foreign_key: 'parent_id', dependent: :destroy validates :name, presence: true validates :file, presence: true, unless: proc { Current.loading_tenant_template } diff --git a/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/patches/project.rb b/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/patches/project.rb new file mode 100644 index 000000000000..c150b612ba1a --- /dev/null +++ b/back/engines/commercial/bulk_import_ideas/app/models/bulk_import_ideas/patches/project.rb @@ -0,0 +1,7 @@ +module BulkImportIdeas::Patches::Project + def self.included(base) + base.class_eval do + has_many :idea_import_files, class_name: 'BulkImportIdeas::IdeaImportFile', dependent: :destroy + end + end +end diff --git a/env_files/back-safe.env b/env_files/back-safe.env index 67993caf5781..42e51e3eec32 100644 --- a/env_files/back-safe.env +++ b/env_files/back-safe.env @@ -21,7 +21,7 @@ AWS_TOXICITY_DETECTION_REGION=eu-central-1 # ==== Development experience configuration ==== SEED_SIZE=small # Tenant is fetched by this host name: -OVERRIDE_HOST=localhost +OVERRIDE_HOST=yourvoice_westoxon_gov_uk # Set to `true` if you want to upload/download files to/from AWS S3: USE_AWS_S3_IN_DEV=false # If USE_AWS_S3_IN_DEV=false, this host is used in file URLs (find it in the code for details): From 880a6b9086ef1676b128e2be9b29335fd14bbc2c Mon Sep 17 00:00:00 2001 From: Simon Tharby Date: Thu, 29 Aug 2024 21:44:22 +0100 Subject: [PATCH 2/3] [TAN-2512] revert temporary change to back-safe.env --- env_files/back-safe.env | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env_files/back-safe.env b/env_files/back-safe.env index 42e51e3eec32..67993caf5781 100644 --- a/env_files/back-safe.env +++ b/env_files/back-safe.env @@ -21,7 +21,7 @@ AWS_TOXICITY_DETECTION_REGION=eu-central-1 # ==== Development experience configuration ==== SEED_SIZE=small # Tenant is fetched by this host name: -OVERRIDE_HOST=yourvoice_westoxon_gov_uk +OVERRIDE_HOST=localhost # Set to `true` if you want to upload/download files to/from AWS S3: USE_AWS_S3_IN_DEV=false # If USE_AWS_S3_IN_DEV=false, this host is used in file URLs (find it in the code for details): From 8b8b7a4639a5d89e3d390c0395e95e9bad1893e7 Mon Sep 17 00:00:00 2001 From: Simon Tharby Date: Fri, 30 Aug 2024 09:55:17 +0100 Subject: [PATCH 3/3] [TAN-2512] Regression test --- .../spec/acceptance/projects_spec.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 back/engines/commercial/bulk_import_ideas/spec/acceptance/projects_spec.rb diff --git a/back/engines/commercial/bulk_import_ideas/spec/acceptance/projects_spec.rb b/back/engines/commercial/bulk_import_ideas/spec/acceptance/projects_spec.rb new file mode 100644 index 000000000000..438beeca1264 --- /dev/null +++ b/back/engines/commercial/bulk_import_ideas/spec/acceptance/projects_spec.rb @@ -0,0 +1,24 @@ +require 'rails_helper' +require 'rspec_api_documentation/dsl' + +resource 'Projects' do + before do + @user = create(:admin) + header_token_for @user + header 'Content-Type', 'application/json' + end + + delete 'web_api/v1/projects/:id' do + let(:project) { create(:project) } + let!(:idea_import_file1) { create(:idea_import_file, project: project) } + let!(:idea_import_file2) { create(:idea_import_file, project: project, parent: idea_import_file1) } + let(:id) { project.id } + + example_request 'Delete a project that has associated idea_import_files' do + expect(response_status).to eq 200 + expect { Project.find(id) }.to raise_error(ActiveRecord::RecordNotFound) + expect { BulkImportIdeas::IdeaImportFile.find(idea_import_file1.id) }.to raise_error(ActiveRecord::RecordNotFound) + expect { BulkImportIdeas::IdeaImportFile.find(idea_import_file2.id) }.to raise_error(ActiveRecord::RecordNotFound) + end + end +end