FEATURE: granular webhooks (#23070)

Before this change, webhooks could be only configured for specific groups like for example, all topic events.

We would like to have more granular control like for example topic_created or topic_destroyed.

Test are failing because plugins changed has to be merged as well:
discourse/discourse-assign#498
discourse/discourse-solved#248
discourse/discourse-topic-voting#159
This commit is contained in:
Krzysztof Kotlarek
2023-10-09 14:35:31 +11:00
committed by GitHub
parent 1d3b2d6bd4
commit c468110929
23 changed files with 705 additions and 198 deletions

View File

@@ -20,9 +20,12 @@ en:
chat:
create_message: "Create a chat message in a specified channel."
web_hooks:
chat_message_event:
name: "Chat message event"
details: "When a chat message is created, edited, trashed or restored."
chat_event:
group_name: "Chat events"
chat_message_created: "Message is created"
chat_message_edited: "Message is edited"
chat_message_trashed: "Message is trashed"
chat_message_restored: "Message is restored"
about:
chat_messages_count: "Chat messages"
chat_channels_count: "Chat channels"

View File

@@ -4,7 +4,7 @@ module Chat
module OutgoingWebHookExtension
def self.prepended(base)
def base.enqueue_chat_message_hooks(event, payload, opts = {})
if active_web_hooks("chat_message").exists?
if active_web_hooks(event).exists?
WebHook.enqueue_hooks(:chat_message, event, payload: payload, **opts)
end
end

View File

@@ -1,9 +1,15 @@
# frozen_string_literal: true
Fabricator(:outgoing_chat_message_web_hook, from: :web_hook) do
transient chat_message_hook: WebHookEventType.find_by(name: "chat_message")
after_build do |web_hook, transients|
web_hook.web_hook_event_types = [transients[:chat_message_hook]]
after_build do |web_hook|
web_hook.web_hook_event_types =
WebHookEventType.where(
name: %w[
chat_message_created
chat_message_edited
chat_message_trashed
chat_message_restored
],
)
end
end