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

[38085] Also send ATTACHMENT_CREATED on direct upload completed

Oliver Günther7382822e121f
diff --git a/app/workers/attachments/finish_direct_upload_job.rb b/app/workers/attachments/finish_direct_upload_job.rb
index 0b319208d16..7339ab7b944 100644
--- a/app/workers/attachments/finish_direct_upload_job.rb
+++ b/app/workers/attachments/finish_direct_upload_job.rb
@@ -46,6 +46,7 @@ class Attachments::FinishDirectUploadJob < ApplicationJob
set_attributes_from_file(attachment, local_file)
save_attachment(attachment)
journalize_container(attachment)
+ attachment_created_event(attachment)
ensure
File.unlink(local_file.path) if File.exist?(local_file.path)
end
@@ -93,4 +94,11 @@ class Attachments::FinishDirectUploadJob < ApplicationJob
timestamps = attributes.index_with { Time.now }
journable.update_columns(timestamps) if timestamps.any?
end
+
+ def attachment_created_event(attachment)
+ OpenProject::Notifications.send(
+ OpenProject::Events::ATTACHMENT_CREATED,
+ attachment: attachment
+ )
+ end
end
diff --git a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
index ea16e4d3099..e323d1ca9be 100644
--- a/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
+++ b/spec/workers/attachments/finish_direct_upload_job_integration_spec.rb
@@ -96,6 +96,26 @@ describe Attachments::FinishDirectUploadJob, 'integration', type: :job do
expect(container.lock_version)
.to eql 0
end
+
+ describe 'attachment created event' do
+ let(:attachment_ids) { [] }
+
+ let!(:subscription) do
+ OpenProject::Notifications.subscribe(OpenProject::Events::ATTACHMENT_CREATED) do |payload|
+ attachment_ids << payload[:attachment].id
+ end
+ end
+
+ after do
+ OpenProject::Notifications.unsubscribe(OpenProject::Events::ATTACHMENT_CREATED, subscription)
+ end
+
+ it "is triggered" do
+ job.perform(pending_attachment.id)
+ pending_attachment.reload
+ expect(attachment_ids).to include(pending_attachment.id)
+ end
+ end
end
context 'for a non journalized container' do