OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
apply NoCreate to WikiPageAttachmentDependentService
ulferts9d8c2932fe44
diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rbindex bc71ed2383a..88c1f336e00 100644--- a/app/services/projects/copy/wiki_dependent_service.rb+++ b/app/services/projects/copy/wiki_dependent_service.rb@@ -74,7 +74,8 @@ module Projects::Copy.new(user:, model: source_page, contract_class: WikiPages::CopyContract).call(wiki: target.wiki,parent_id: new_parent_id,- send_notifications: ActionMailer::Base.perform_deliveries)+ send_notifications: ActionMailer::Base.perform_deliveries,+ attachments: copy_attachments?)if service_call.success?service_call.result@@ -125,5 +126,9 @@ module Projects::Copyendendend++ def copy_attachments?+ (params.dig(:params, :only) || []).any? { |k| k.to_sym == :wiki_page_attachments }+ endendenddiff --git a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb b/app/services/projects/copy/wiki_page_attachments_dependent_service.rbindex d4f18c75bd0..8429b203a55 100644--- a/app/services/projects/copy/wiki_page_attachments_dependent_service.rb+++ b/app/services/projects/copy/wiki_page_attachments_dependent_service.rb@@ -28,7 +28,7 @@module Projects::Copyclass WikiPageAttachmentsDependentService < Dependency- include ::Copy::Concerns::CopyAttachments+ include ::Projects::Copy::NoCreatedef self.human_nameI18n.t(:label_wiki_page_attachments)@@ -37,16 +37,5 @@ module Projects::Copydef source_countsource.wiki && source.wiki.pages.joins(:attachments).count('attachments.id')end-- protected-- def copy_dependency(params:)- # If no wiki pages copied, we cannot copy their attachments- return unless state.wiki_page_id_lookup-- state.wiki_page_id_lookup.each do |old_id, new_id|- copy_attachments('WikiPage', from_id: old_id, to_id: new_id)- end- endendenddiff --git a/app/services/wiki_pages/copy_service.rb b/app/services/wiki_pages/copy_service.rbindex 4730801629e..ccf27755fa2 100644--- a/app/services/wiki_pages/copy_service.rb+++ b/app/services/wiki_pages/copy_service.rb@@ -29,6 +29,7 @@class WikiPages::CopyServiceinclude ::Shared::ServiceContextinclude Contracted+ include ::Copy::Concerns::CopyAttachmentsattr_accessor :user,:model,@@ -40,18 +41,24 @@ class WikiPages::CopyServiceself.contract_class = contract_classend- def call(send_notifications: true, **attributes)+ def call(send_notifications: true, attachments: true, **attributes)in_context(model, send_notifications) do- copy(attributes)+ copy(attributes, attachments)endendprotected- def copy(attribute_override)+ def copy(attribute_override, attachments)attributes = copied_attributes(attribute_override)- create(attributes)+ copied_call = create(attributes)++ if copied_call.success? && attachments+ copy_attachments('WikiPage', from_id: model.id, to_id: copied_call.result.id)+ end++ copied_callenddef create(attributes)diff --git a/spec/services/wiki_pages/copy_service_integration_spec.rb b/spec/services/wiki_pages/copy_service_integration_spec.rbindex 7a76460cdbd..38910f1befa 100644--- a/spec/services/wiki_pages/copy_service_integration_spec.rb+++ b/spec/services/wiki_pages/copy_service_integration_spec.rb@@ -95,6 +95,35 @@ describe WikiPages::CopyService, 'integration', type: :model doit 'sets the author to be the current user' doexpect(copy.content.author).to eq(user)end++ context 'with attachments' do+ let!(:attachment) do+ create(:attachment,+ container: wiki_page)+ end++ context 'when specifying to copy attachments (default)' do+ it 'copies the attachment' do+ expect(copy.attachments.length)+ .to eq 1++ expect(copy.attachments.first.attributes.slice(:digest, :file, :filesize))+ .to eq attachment.attributes.slice(:digest, :file, :filesize)++ expect(copy.attachments.first.id)+ .not_to eq attachment.id+ end+ end++ context 'when specifying to not copy attachments' do+ let(:attributes) { { attachments: false } }++ it 'copies the attachment' do+ expect(copy.attachments.length)+ .to eq 0+ end+ end+ endenddescribe 'to a different wiki' do