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
set the copying user to be the author of attachments (#8822)
ulfertsd5e490efda94
diff --git a/app/services/copy/concerns/copy_attachments.rb b/app/services/copy/concerns/copy_attachments.rbindex 4dd53ca73df..d289db547b0 100644--- a/app/services/copy/concerns/copy_attachments.rb+++ b/app/services/copy/concerns/copy_attachments.rb@@ -4,12 +4,13 @@ module Copy### Tries to copy the given attachment between containers- def copy_attachments(from_container_id, to_container_id, container_type)- Attachment.where(container_id: from_container_id, container_type: container_type).find_each do |old_attachment|+ def copy_attachments(from_container, to_container_id)+ Attachment.where(container: from_container).find_each do |old_attachment|copied = old_attachment.dupold_attachment.file.copy_to(copied)- copied.container_type = container_type+ copied.author = user+ copied.container_type = from_container.class.namecopied.container_id = to_container_idunless copied.savediff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rbindex eb74a657056..11baf825838 100644--- a/app/services/projects/copy/wiki_dependent_service.rb+++ b/app/services/projects/copy/wiki_dependent_service.rb@@ -65,7 +65,7 @@ module Projects::Copywiki_pages_map.each do |old_page, new_page|next unless old_page && new_page- copy_attachments(old_page.id, new_page.id, new_page.class.name)+ copy_attachments(old_page, new_page.id)endendend@@ -77,7 +77,7 @@ module Projects::Copy# Relying on ActionMailer::Base.perform_deliveries is violating cohesion# but the value is currently not otherwise providedservice_call = WikiPages::CopyService- .new(user: User.current, model: source_page, contract_class: WikiPages::CopyContract)+ .new(user: user, model: source_page, contract_class: WikiPages::CopyContract).call(wiki: target.wiki,parent: new_parent,send_notifications: ActionMailer::Base.perform_deliveries)diff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rbindex 434cb325ecb..7a0dc22f009 100644--- a/app/services/projects/copy/work_packages_dependent_service.rb+++ b/app/services/projects/copy/work_packages_dependent_service.rb@@ -68,7 +68,7 @@ module Projects::Copy# Attachmentsif should_copy?(params, :work_package_attachments)- copy_attachments(wp.id, new_wp_id, 'WorkPackage')+ copy_attachments(wp, new_wp_id)endcopy_relations(wp, new_wp_id, work_packages_map)diff --git a/spec/services/projects/copy_service_integration_spec.rb b/spec/services/projects/copy_service_integration_spec.rbindex d8a3c8cb62f..24819f3a8ca 100644--- a/spec/services/projects/copy_service_integration_spec.rb+++ b/spec/services/projects/copy_service_integration_spec.rb@@ -319,6 +319,7 @@ describe Projects::CopyService, 'integration', type: :model dowp = project_copy.work_packages.find_by(subject: work_package.subject)expect(wp.attachments.count).to eq(1)+ expect(wp.attachments.first.author).to eql(current_user)endend