Skip to content

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

cleanup attachment copy signaling

ulfertsac14c5b0f120
diff --git a/app/services/projects/copy/wiki_dependent_service.rb b/app/services/projects/copy/wiki_dependent_service.rb
index e624e3daf9b..62e46f23d73 100644
--- a/app/services/projects/copy/wiki_dependent_service.rb
+++ b/app/services/projects/copy/wiki_dependent_service.rb
@@ -79,7 +79,7 @@ module Projects::Copy
.call(wiki: target.wiki,
parent_id: new_parent_id,
send_notifications: ActionMailer::Base.perform_deliveries,
- attachments: copy_attachments?)
+ copy_attachments: copy_attachments?)
if service_call.success?
service_call.result
diff --git a/app/services/projects/copy/work_packages_dependent_service.rb b/app/services/projects/copy/work_packages_dependent_service.rb
index 7539d55b8ef..b022fdac413 100644
--- a/app/services/projects/copy/work_packages_dependent_service.rb
+++ b/app/services/projects/copy/work_packages_dependent_service.rb
@@ -85,7 +85,7 @@ module Projects::Copy
.new(user:,
work_package: source_work_package,
contract_class: WorkPackages::CopyProjectContract)
- .call(attachments: copy_attachments?, **overrides)
+ .call(copy_attachments: copy_attachments?, **overrides)
if service_call.success?
service_call.result
diff --git a/app/services/wiki_pages/copy_service.rb b/app/services/wiki_pages/copy_service.rb
index ccf27755fa2..dbd2dbb711a 100644
--- a/app/services/wiki_pages/copy_service.rb
+++ b/app/services/wiki_pages/copy_service.rb
@@ -41,24 +41,21 @@ class WikiPages::CopyService
self.contract_class = contract_class
end
- def call(send_notifications: true, attachments: true, **attributes)
+ def call(send_notifications: true, copy_attachments: true, **attributes)
in_context(model, send_notifications) do
- copy(attributes, attachments)
+ copy(attributes, copy_attachments)
end
end
protected
- def copy(attribute_override, attachments)
+ def copy(attribute_override, copy_attachments)
attributes = copied_attributes(attribute_override)
- copied_call = create(attributes)
-
- if copied_call.success? && attachments
- copy_attachments('WikiPage', from_id: model.id, to_id: copied_call.result.id)
+ create(attributes)
+ .on_success do |call|
+ copy_wiki_page_attachments(call.result) if copy_attachments
end
-
- copied_call
end
def create(attributes)
@@ -81,4 +78,8 @@ class WikiPages::CopyService
instantiate_contract(model, user)
.writable_attributes
end
+
+ def copy_wiki_page_attachments(copy)
+ copy_attachments('WikiPage', from_id: model.id, to_id: copy.id)
+ end
end
diff --git a/app/services/work_packages/copy_service.rb b/app/services/work_packages/copy_service.rb
index 9b1b0e0e311..ff5cba6cf29 100644
--- a/app/services/work_packages/copy_service.rb
+++ b/app/services/work_packages/copy_service.rb
@@ -41,27 +41,23 @@ class WorkPackages::CopyService
self.contract_class = contract_class
end
- def call(send_notifications: true, attachments: true, **attributes)
+ def call(send_notifications: true, copy_attachments: true, **attributes)
in_context(work_package, send_notifications) do
- copy(attributes, attachments, send_notifications)
+ copy(attributes, copy_attachments, send_notifications)
end
end
protected
- def copy(attribute_override, attachments, send_notifications)
+ def copy(attribute_override, copy_attachments, send_notifications)
copied = create(work_package,
attribute_override,
send_notifications)
-
- if copied.success?
- remove_author_watcher(copied.result)
- copy_watchers(copied.result)
-
- if attachments
- copy_attachments('WorkPackage', from_id: work_package.id, to_id: copied.result.id)
+ .on_success do |copy_call|
+ remove_author_watcher(copy_call.result)
+ copy_watchers(copy_call.result)
+ copy_work_package_attachments(copy_call.result) if copy_attachments
end
- end
copied.state.copied_from_work_package_id = work_package&.id
@@ -107,4 +103,8 @@ class WorkPackages::CopyService
copied.add_watcher(user) if user.active?
end
end
+
+ def copy_work_package_attachments(copy)
+ copy_attachments('WorkPackage', from_id: work_package.id, to_id: copy.id)
+ end
end
diff --git a/spec/services/wiki_pages/copy_service_integration_spec.rb b/spec/services/wiki_pages/copy_service_integration_spec.rb
index 38910f1befa..d2711ffd2db 100644
--- a/spec/services/wiki_pages/copy_service_integration_spec.rb
+++ b/spec/services/wiki_pages/copy_service_integration_spec.rb
@@ -116,7 +116,7 @@ describe WikiPages::CopyService, 'integration', type: :model do
end
context 'when specifying to not copy attachments' do
- let(:attributes) { { attachments: false } }
+ let(:attributes) { { copy_attachments: false } }
it 'copies the attachment' do
expect(copy.attachments.length)
diff --git a/spec/services/work_packages/copy_service_integration_spec.rb b/spec/services/work_packages/copy_service_integration_spec.rb
index 657b784b5b6..cb85cef9410 100644
--- a/spec/services/work_packages/copy_service_integration_spec.rb
+++ b/spec/services/work_packages/copy_service_integration_spec.rb
@@ -320,7 +320,7 @@ describe WorkPackages::CopyService, 'integration', type: :model do
end
context 'when specifying to not copy attachments' do
- let(:attributes) { { attachments: false } }
+ let(:attributes) { { copy_attachments: false } }
it 'copies the attachment' do
expect(copy.attachments.length)