Defect #43889 ยป 43889-fix-webhook-when-attachment-deleted.patch
| app/models/issue.rb | ||
|---|---|---|
| 1958 | 1958 |
if current_journal && !attachment.new_record? |
| 1959 | 1959 |
current_journal.journalize_attachment(attachment, :removed) |
| 1960 | 1960 |
current_journal.save |
| 1961 |
# Attachment removal via AJAX saves only the journal, so the usual issue update callback does not fire. |
|
| 1962 |
Webhook.trigger(event_name('updated'), self) unless saved_changes?
|
|
| 1961 | 1963 |
end |
| 1962 | 1964 |
end |
| 1963 | 1965 | |
| test/unit/webhook_test.rb | ||
|---|---|---|
| 219 | 219 |
assert_equal @issue.id, payload.dig(:data, :issue, :id) |
| 220 | 220 |
end |
| 221 | 221 | |
| 222 |
test "should trigger issue updated webhook when attachment removal creates a journal without saving issue" do |
|
| 223 |
issue = Issue.find(3) |
|
| 224 |
attachment = Attachment.find(1) |
|
| 225 |
issue.init_journal(@dlopper) |
|
| 226 | ||
| 227 |
Webhook.expects(:trigger).with('issue.updated', issue).once
|
|
| 228 |
issue.attachments.delete(attachment) |
|
| 229 | ||
| 230 |
journal = issue.journals.order(:id).last |
|
| 231 |
assert_equal attachment.id.to_s, journal.details.last.prop_key |
|
| 232 |
assert_equal 'attachment', journal.details.last.property |
|
| 233 |
assert_equal attachment.filename, journal.details.last.old_value |
|
| 234 |
end |
|
| 235 | ||
| 222 | 236 |
test "should compute correct signature" do |
| 223 | 237 |
# we're implementing the same signature mechanism as GitHub, so might as well re-use their |
| 224 | 238 |
# example. https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries |