Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: granular webhooks #159

Merged
merged 3 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading