From 6089d396ea5cee89825837722526080f8551ae9a Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 15 Aug 2023 14:57:20 +1000 Subject: [PATCH 1/3] FIX: granular webhooks After those core changes we need additional translations and separate logic to handle assigned and unassigned webhooks https://github.com/discourse/discourse/pull/23070 --- 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 | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) 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..3559c36 100644 --- a/spec/fabricators/topic_voting_hook_fabricator.rb +++ b/spec/fabricators/topic_voting_hook_fabricator.rb @@ -1,7 +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") + transient topic_voting_hook: WebHookEventType.find_by(name: "topic_upvote") after_build do |web_hook, transients| web_hook.web_hook_event_types = [transients[:topic_voting_hook]] From b41cee2941be91d88487226158d799a7488dd24e Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Tue, 26 Sep 2023 11:35:09 +1000 Subject: [PATCH 2/3] FIX: update after changes --- spec/fabricators/topic_voting_hook_fabricator.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/spec/fabricators/topic_voting_hook_fabricator.rb b/spec/fabricators/topic_voting_hook_fabricator.rb index 3559c36..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_upvote") - - 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 From f75d49db83118c8f0bd85d41b6caa95015b9a591 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Fri, 6 Oct 2023 12:12:24 +1100 Subject: [PATCH 3/3] FIX: discourse compatibility --- .discourse-compatibility | 1 + 1 file changed, 1 insertion(+) 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