Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don't display webhooks for inactive plugins (#9206)

Blake Erickson919e405c4832
diff --git a/app/controllers/admin/web_hooks_controller.rb b/app/controllers/admin/web_hooks_controller.rb
index f5aa0c979c9..084af1d085d 100644
--- a/app/controllers/admin/web_hooks_controller.rb
+++ b/app/controllers/admin/web_hooks_controller.rb
@@ -16,7 +16,7 @@ class Admin::WebHooksController < Admin::AdminController
json = {
web_hooks: serialize_data(web_hooks, AdminWebHookSerializer),
extras: {
- event_types: WebHookEventType.all,
+ event_types: WebHookEventType.active,
default_event_types: WebHook.default_event_types,
content_types: WebHook.content_types.map { |name, id| { id: id, name: name } },
delivery_statuses: WebHook.last_delivery_statuses.map { |name, id| { id: id, name: name.to_s } },
diff --git a/app/models/web_hook_event_type.rb b/app/models/web_hook_event_type.rb
index c40c7a21a90..d3822d1ede4 100644
--- a/app/models/web_hook_event_type.rb
+++ b/app/models/web_hook_event_type.rb
@@ -19,6 +19,15 @@ class WebHookEventType < ActiveRecord::Base
default_scope { order('id ASC') }
validates :name, presence: true, uniqueness: true
+
+ def self.active
+ ids_to_exclude = []
+ ids_to_exclude << SOLVED unless defined?(SiteSetting.solved_enabled) && SiteSetting.solved_enabled
+ ids_to_exclude << ASSIGN unless defined?(SiteSetting.assign_enabled) && SiteSetting.assign_enabled
+
+ self.where.not(id: ids_to_exclude)
+ end
+
end
# == Schema Information
diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb
index 8b0fbb0e52d..47b4c20bb72 100644
--- a/spec/models/web_hook_spec.rb
+++ b/spec/models/web_hook_spec.rb
@@ -44,6 +44,22 @@ describe WebHook do
expect(post_hook.payload_url).to eq("https://example.com")
end
+ it "excludes disabled plugin web_hooks" do
+ web_hook_event_types = WebHookEventType.active.find_by(name: 'solved')
+ expect(web_hook_event_types).to eq(nil)
+ end
+
+ it "includes non-plugin web_hooks" do
+ web_hook_event_types = WebHookEventType.active.where(name: 'topic')
+ expect(web_hook_event_types.count).to eq(1)
+ end
+
+ it "includes enabled plugin web_hooks" do
+ SiteSetting.stubs(:solved_enabled).returns(true)
+ web_hook_event_types = WebHookEventType.active.where(name: 'solved')
+ expect(web_hook_event_types.count).to eq(1)
+ end
+
describe '#active_web_hooks' do
it "returns unique hooks" do
post_hook.web_hook_event_types << WebHookEventType.find_by(name: 'topic')