Skip to content

Commit

Permalink
FIX: granular webhooks (#248)
Browse files Browse the repository at this point in the history
After those core changes we need additional translations

discourse/discourse#23070
  • Loading branch information
lis2 committed Oct 9, 2023
1 parent 9fbf43e commit 7e59ece
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
@@ -1,3 +1,4 @@
< 3.2.0.beta2-dev: 9fbf43e2f077e86f0a1ff769af6036d4e78bfff1
3.1.999: b5d487d6a5bfe2571d936eec5911d02a5f3fcc32
3.1.0.beta1: 62fe282c756ac7de43a22a09b0d675882a507743
2.9.0.beta11: 882dd61e11f9bab8e99510296938b0cdbc3269c4
Expand Down
5 changes: 3 additions & 2 deletions config/locales/client.en.yml
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions plugin.rb
Expand Up @@ -160,7 +160,7 @@ def self.accept_answer!(post, acting_user, topic: nil)
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
Expand Down Expand Up @@ -201,7 +201,7 @@ def self.unaccept_answer!(post, topic: nil)

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
Expand Down Expand Up @@ -420,7 +420,7 @@ def solved_count

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(
Expand Down Expand Up @@ -605,7 +605,7 @@ def topic_accepted_answer
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
Expand Down
7 changes: 4 additions & 3 deletions spec/fabricators/solved_hook_fabricator.rb
@@ -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

0 comments on commit 7e59ece

Please sign in to comment.