Skip to content

Commit

Permalink
FIX: granular webhooks (#159)
Browse files Browse the repository at this point in the history
After those core changes we need additional translations and separate logic to handle assigned and unassigned webhooks

discourse/discourse#23070
  • Loading branch information
lis2 authored Oct 9, 2023
1 parent ca2449f commit aa12f75
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.2.0.beta2-dev: ca2449f243ba3de5182fead8c66c2346cd25ed2c
3.1.999: 6449fc15658d972e20086a3f1fae3dbac9cd9eeb
3.1.0.beta3: a1ae9a4c55563516e8a7f8c040f6828066164f66
2.9.0.beta3: 2de1fe5df1a5c25ad1e0e31e8d28adca315d9092
4 changes: 2 additions & 2 deletions app/controllers/discourse_topic_voting/votes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion lib/discourse_topic_voting/web_hook_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions spec/fabricators/topic_voting_hook_fabricator.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aa12f75

Please sign in to comment.