FIX: granular webhooks (#248)

After those core changes we need additional translations

https://github.com/discourse/discourse/pull/23070
This commit is contained in:
Krzysztof Kotlarek 2023-10-09 14:26:29 +11:00 committed by GitHub
parent 9fbf43e2f0
commit 7e59ece789
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -1,3 +1,4 @@
< 3.2.0.beta2-dev: 9fbf43e2f077e86f0a1ff769af6036d4e78bfff1
3.1.999: b5d487d6a5bfe2571d936eec5911d02a5f3fcc32
3.1.0.beta1: 62fe282c756ac7de43a22a09b0d675882a507743
2.9.0.beta11: 882dd61e11f9bab8e99510296938b0cdbc3269c4

View File

@ -48,8 +48,9 @@ en:
admin:
web_hooks:
solved_event:
name: "Solved Event"
details: "When a user marks a post as the accepted or unaccepted answer."
group_name: "Solved Event"
accepted_solution: "When an user marks a post as the accepted answer"
unaccepted_solution: "When an user marks a post as the unaccepted answer"
api:
scopes:
descriptions:

View File

@ -160,7 +160,7 @@ SQL
topic.save!
post.save!
if WebHook.active_web_hooks(:solved).exists?
if WebHook.active_web_hooks(:accepted_solution).exists?
payload = WebHook.generate_payload(:post, post)
WebHook.enqueue_solved_hooks(:accepted_solution, post, payload)
end
@ -201,7 +201,7 @@ SQL
notification.destroy! if notification
if WebHook.active_web_hooks(:solved).exists?
if WebHook.active_web_hooks(:unaccepted_solution).exists?
payload = WebHook.generate_payload(:post, post)
WebHook.enqueue_solved_hooks(:unaccepted_solution, post, payload)
end
@ -420,7 +420,7 @@ SQL
class ::WebHook
def self.enqueue_solved_hooks(event, post, payload = nil)
if active_web_hooks("solved").exists? && post.present?
if active_web_hooks(event).exists? && post.present?
payload ||= WebHook.generate_payload(:post, post)
WebHook.enqueue_hooks(
@ -605,7 +605,7 @@ SQL
WHERE tc.name = '#{::DiscourseSolved::ACCEPTED_ANSWER_POST_ID_CUSTOM_FIELD}' AND
tc.value IS NOT NULL
) AND topics.id IN (
SELECT top.id
SELECT top.id
FROM topics top
INNER JOIN category_custom_fields cc
ON top.category_id = cc.category_id

View File

@ -1,7 +1,8 @@
# frozen_string_literal: true
Fabricator(:solved_web_hook, from: :web_hook) do
transient solved_hook: WebHookEventType.find_by(name: "solved")
after_build { |web_hook, transients| web_hook.web_hook_event_types = [transients[:solved_hook]] }
after_build do |web_hook|
web_hook.web_hook_event_types =
WebHookEventType.where(name: %w[accepted_solution unaccepted_solution])
end
end