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

Reuse existing attachment replacements override

Kabiru Mwenja527a8ad02a83
diff --git a/app/services/attachments/set_replacements.rb b/app/services/attachments/set_replacements.rb
index 9b12601bd08..70b43d65a0f 100644
--- a/app/services/attachments/set_replacements.rb
+++ b/app/services/attachments/set_replacements.rb
@@ -41,7 +41,8 @@ module Attachments
def set_attachments_attributes(attributes)
attachment_ids = attributes.delete(:attachment_ids)
- return if attachment_ids.blank?
+
+ return unless attachment_ids
model.attachments_replacements = Attachment.where(id: attachment_ids)
end
diff --git a/app/services/work_packages/activities_tab/comment_attachments_claims/claims_service.rb b/app/services/work_packages/activities_tab/comment_attachments_claims/claims_service.rb
index 57bf9f51dbd..fddac660a92 100644
--- a/app/services/work_packages/activities_tab/comment_attachments_claims/claims_service.rb
+++ b/app/services/work_packages/activities_tab/comment_attachments_claims/claims_service.rb
@@ -32,13 +32,7 @@ module WorkPackages
module ActivitiesTab
module CommentAttachmentsClaims
class ClaimsService < BaseServices::Update
- def persist(service_result)
- if service_result.result.attachments_replacements.present?
- service_result.result.attachments = service_result.result.attachments_replacements
- end
-
- super
- end
+ include Attachments::ReplaceAttachments
private
diff --git a/spec/services/work_packages/activities_tab/comment_attachments_claims/set_attributes_service_spec.rb b/spec/services/work_packages/activities_tab/comment_attachments_claims/set_attributes_service_spec.rb
index 5dc24bd8766..3bac1e4e67d 100644
--- a/spec/services/work_packages/activities_tab/comment_attachments_claims/set_attributes_service_spec.rb
+++ b/spec/services/work_packages/activities_tab/comment_attachments_claims/set_attributes_service_spec.rb
@@ -72,18 +72,18 @@ RSpec.describe WorkPackages::ActivitiesTab::CommentAttachmentsClaims::SetAttribu
context "when the journal notes have no attachments" do
let(:notes) { "Lorem ipsum dolor sit amet" }
- it "does not set the attachments" do
+ it "defines empty attachments" do
expect(set_attributes_service).to be_success
- expect(set_attributes_service.result.attachments_replacements).to be_nil
+ expect(set_attributes_service.result.attachments_replacements).to be_empty
end
end
context "when the journal notes are nil" do
let(:notes) { nil }
- it "does not set the attachments" do
+ it "defines atttachments as empty" do
expect(set_attributes_service).to be_success
- expect(set_attributes_service.result.attachments_replacements).to be_nil
+ expect(set_attributes_service.result.attachments_replacements).to be_empty
end
end
end