A platform for community discussion. Free, open, simple.
FIX: Wildcard webhooks could send duplicated events.
Guo Xiang Tan9644569a289a
diff --git a/app/models/web_hook.rb b/app/models/web_hook.rbindex 493bdc22c00..de0db8bbf97 100644--- a/app/models/web_hook.rb+++ b/app/models/web_hook.rb@@ -34,6 +34,7 @@ class WebHook < ActiveRecord::BaseWebHook.where(active: true).joins(:web_hook_event_types).where("web_hooks.wildcard_web_hook = ? OR web_hook_event_types.name = ?", true, type.to_s)+ .uniqenddef self.enqueue_hooks(type, opts = {})diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rbindex 0f9af9d966f..dbb53ca8371 100644--- a/spec/models/web_hook_spec.rb+++ b/spec/models/web_hook_spec.rb@@ -43,6 +43,13 @@ describe WebHook doenddescribe '#find_by_type' do+ it "returns unique hooks" do+ post_hook.web_hook_event_types << WebHookEventType.find_by(name: 'topic')+ post_hook.update!(wildcard_web_hook: true)++ expect(WebHook.find_by_type(:post)).to eq([post_hook])+ end+it 'find relevant hooks' doexpect(WebHook.find_by_type(:post)).to eq([post_hook])expect(WebHook.find_by_type(:topic)).to eq([topic_hook])