From aa12f754d41a025de0d9b87602110ae97df9b19e Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Mon, 9 Oct 2023 14:26:19 +1100 Subject: [PATCH] FIX: granular webhooks (#159) After those core changes we need additional translations and separate logic to handle assigned and unassigned webhooks https://github.com/discourse/discourse/pull/23070 --- .discourse-compatibility | 1 + app/controllers/discourse_topic_voting/votes_controller.rb | 4 ++-- config/locales/client.en.yml | 7 ++++--- lib/discourse_topic_voting/web_hook_extension.rb | 2 +- spec/fabricators/topic_voting_hook_fabricator.rb | 6 ++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.discourse-compatibility b/.discourse-compatibility index c5ba939..b9b8ebe 100644 --- a/.discourse-compatibility +++ b/.discourse-compatibility @@ -1,3 +1,4 @@ +< 3.2.0.beta2-dev: ca2449f243ba3de5182fead8c66c2346cd25ed2c 3.1.999: 6449fc15658d972e20086a3f1fae3dbac9cd9eeb 3.1.0.beta3: a1ae9a4c55563516e8a7f8c040f6828066164f66 2.9.0.beta3: 2de1fe5df1a5c25ad1e0e31e8d28adca315d9092 diff --git a/app/controllers/discourse_topic_voting/votes_controller.rb b/app/controllers/discourse_topic_voting/votes_controller.rb index 68906a1..b872512 100644 --- a/app/controllers/discourse_topic_voting/votes_controller.rb +++ b/app/controllers/discourse_topic_voting/votes_controller.rb @@ -39,7 +39,7 @@ def vote votes_left: [(current_user.vote_limit - current_user.vote_count), 0].max, } - if WebHook.active_web_hooks(:topic_voting).exists? + if WebHook.active_web_hooks(:topic_upvote).exists? payload = { topic_id: topic_id, topic_slug: topic.slug, @@ -70,7 +70,7 @@ def unvote votes_left: [(current_user.vote_limit - current_user.vote_count), 0].max, } - if WebHook.active_web_hooks(:topic_voting).exists? + if WebHook.active_web_hooks(:topic_unvote).exists? payload = { topic_id: topic_id, topic_slug: topic.slug, diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 6a4a6bf..ac996c9 100755 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -45,6 +45,7 @@ en: label: "Minimum Vote Count" admin: web_hooks: - topic_voting_event: - name: "Topic Voting Event" - details: "When a user votes or unvotes on a topic" + voting_event: + group_name: "Topic Voting Event" + topic_upvote: "When a user votes on a topic" + topic_unvote: "When a user unvotes on a topic" diff --git a/lib/discourse_topic_voting/web_hook_extension.rb b/lib/discourse_topic_voting/web_hook_extension.rb index 6dcb215..a622002 100644 --- a/lib/discourse_topic_voting/web_hook_extension.rb +++ b/lib/discourse_topic_voting/web_hook_extension.rb @@ -5,7 +5,7 @@ module WebHookExtension def self.prepended(base) base.class_eval do def self.enqueue_topic_voting_hooks(event, topic, payload) - if active_web_hooks("topic_voting").exists? + if active_web_hooks(event).exists? WebHook.enqueue_hooks( :topic_voting, event, diff --git a/spec/fabricators/topic_voting_hook_fabricator.rb b/spec/fabricators/topic_voting_hook_fabricator.rb index 83e9a07..879bc5f 100644 --- a/spec/fabricators/topic_voting_hook_fabricator.rb +++ b/spec/fabricators/topic_voting_hook_fabricator.rb @@ -1,9 +1,7 @@ # frozen_string_literal: true Fabricator(:topic_voting_web_hook, from: :web_hook) do - transient topic_voting_hook: WebHookEventType.find_by(name: "topic_voting") - - after_build do |web_hook, transients| - web_hook.web_hook_event_types = [transients[:topic_voting_hook]] + after_build do |web_hook| + web_hook.web_hook_event_types = WebHookEventType.where(name: %w[topic_upvote topic_unvote]) end end