diff --git a/app/models/issue.rb b/app/models/issue.rb index e920aea56..b4113b9fe 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1958,6 +1958,8 @@ class Issue < ApplicationRecord if current_journal && !attachment.new_record? current_journal.journalize_attachment(attachment, :removed) current_journal.save + # Attachment removal via AJAX saves only the journal, so the usual issue update callback does not fire. + Webhook.trigger(event_name('updated'), self) unless saved_changes? end end diff --git a/test/unit/webhook_test.rb b/test/unit/webhook_test.rb index b9c6f2ad2..594d24c27 100644 --- a/test/unit/webhook_test.rb +++ b/test/unit/webhook_test.rb @@ -219,6 +219,20 @@ class WebhookTest < ActiveSupport::TestCase assert_equal @issue.id, payload.dig(:data, :issue, :id) end + test "should trigger issue updated webhook when attachment removal creates a journal without saving issue" do + issue = Issue.find(3) + attachment = Attachment.find(1) + issue.init_journal(@dlopper) + + Webhook.expects(:trigger).with('issue.updated', issue).once + issue.attachments.delete(attachment) + + journal = issue.journals.order(:id).last + assert_equal attachment.id.to_s, journal.details.last.prop_key + assert_equal 'attachment', journal.details.last.property + assert_equal attachment.filename, journal.details.last.old_value + end + test "should compute correct signature" do # we're implementing the same signature mechanism as GitHub, so might as well re-use their # example. https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries