1
0
mirror of https://github.com/meineerde/redmine.git synced 2026-02-01 03:57:15 +00:00

Adds webhook events for WikiPage (#29664).

git-svn-id: https://svn.redmine.org/redmine/trunk@24198 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu 2025-12-03 22:31:03 +00:00
parent 8a79459996
commit 8c229711d5
4 changed files with 80 additions and 1 deletions

View File

@ -28,7 +28,8 @@ class WebhookPayload
end
EVENTS = {
issue: %w[created updated deleted]
issue: %w[created updated deleted],
wiki_page: %w[created updated deleted]
}
def to_h
@ -88,6 +89,27 @@ class WebhookPayload
}
end
def wiki_page_payload(action)
wiki_page = object
ts = case action
when 'created'
wiki_page.created_on
when 'deleted'
Time.now
else
wiki_page.updated_on
end
{
type: event,
timestamp: ts.iso8601,
data: {
wiki_page: ApiRenderer.new("app/views/wiki/show.api.rsb", user).to_h(page: wiki_page, content: wiki_page.content)
}
}
end
# given a path to an API template (relative to RAILS_ROOT), renders it and returns the resulting hash
class ApiRenderer
include ApplicationHelper

View File

@ -62,6 +62,10 @@ class WikiPage < ApplicationRecord
before_destroy :delete_redirects
after_save :handle_children_move, :delete_selected_attachments
after_create_commit ->{ Webhook.trigger('wiki_page.created', self) }
after_update_commit ->{ Webhook.trigger('wiki_page.updated', self) }
after_destroy_commit ->{ Webhook.trigger('wiki_page.deleted', self) }
# eager load information about last updates, without loading text
scope :with_updated_on, lambda {preload(:content_without_text)}
@ -192,6 +196,10 @@ class WikiPage < ApplicationRecord
wiki.try(:project)
end
def project_id
wiki&.project_id
end
def text
content.text if content
end

View File

@ -1189,6 +1189,10 @@ en:
webhook_events_issue_created: Issue created
webhook_events_issue_updated: Issue updated
webhook_events_issue_deleted: Issue deleted
webhook_events_wiki_page: Wiki pages
webhook_events_wiki_page_created: Wiki page created
webhook_events_wiki_page_updated: Wiki page updated
webhook_events_wiki_page_deleted: Wiki page deleted
webhook_url_info: Redmine will send a POST request to this URL whenever one of the selected events occurs in one of the selected projects.
webhook_secret_info_html: If provided, Redmine will use this to create a hash signature that is sent with each delivery as the value of the X-Redmine-Signature-256 header.

View File

@ -50,4 +50,49 @@ class WebhookPayloadTest < ActiveSupport::TestCase
assert i = h.dig(:data, :issue)
assert_equal @issue.subject, i[:subject], i.inspect
end
test "wiki page created payload should contain page details" do
wiki = @project.wiki
page = WikiPage.new(:title => 'Test Page', :wiki => wiki)
page.content = WikiContent.new(text: 'Test content', author: @dlopper)
page.save!
p = WebhookPayload.new('wiki_page.created', page, @dlopper)
assert h = p.to_h
assert_equal 'wiki_page.created', h[:type]
assert_equal 'Test_Page', h.dig(:data, :wiki_page, :title)
assert_equal 'Test content', h.dig(:data, :wiki_page, :text)
assert_equal @dlopper.name, h.dig(:data, :wiki_page, :author, :name)
end
test "wiki page updated payload should contain updated timestamp" do
wiki = @project.wiki
page = WikiPage.new(wiki: wiki, title: 'Test Page')
page.content = WikiContent.new(text: 'Initial content', author: @dlopper)
page.save!
page.content.text = 'Updated content'
page.content.save!
page.reload
p = WebhookPayload.new('wiki_page.updated', page, @dlopper)
h = p.to_h
assert_equal 'wiki_page.updated', h[:type]
assert_equal 'Updated content', h.dig(:data, :wiki_page, :text)
end
test "wiki page deleted payload should contain basic info" do
wiki = @project.wiki
page = WikiPage.new(wiki: wiki, title: 'Test Page')
page.content = WikiContent.new(text: 'Test content', author: @dlopper)
page.save!
page.destroy
p = WebhookPayload.new('wiki_page.deleted', page, @dlopper)
h = p.to_h
assert_equal 'wiki_page.deleted', h[:type]
assert_equal 'Test_Page', h.dig(:data, :wiki_page, :title)
assert_equal @project.id, h.dig(:data, :wiki_page, :project, :id)
end
end