FIX: active webhook types exclude inactive plugins (#26022)

Bug introduced when webhooks were granularized in this PR - c468110929

Only active webhooks should be available when webhooks is configured.

https://meta.discourse.org/t/i18n-keys-showing-on-webhooks-edit-page/297701
This commit is contained in:
Krzysztof Kotlarek 2024-03-05 12:47:04 +11:00 committed by GitHub
parent 447ed2c06c
commit 28af4031ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 80 additions and 4 deletions

View File

@ -98,16 +98,23 @@ class WebHookEventType < ActiveRecord::Base
def self.active
ids_to_exclude = []
unless defined?(SiteSetting.solved_enabled) && SiteSetting.solved_enabled
ids_to_exclude << TYPES[:solved_accept_unaccept]
ids_to_exclude.concat([TYPES[:solved_accepted_solution], TYPES[:solved_unaccepted_solution]])
end
unless defined?(SiteSetting.assign_enabled) && SiteSetting.assign_enabled
ids_to_exclude << TYPES[:assign_assign_unassign]
ids_to_exclude.concat([TYPES[:assign_assigned], TYPES[:assign_unassigned]])
end
unless defined?(SiteSetting.voting_enabled) && SiteSetting.voting_enabled
ids_to_exclude << TYPES[:voting_voted_unvoted]
ids_to_exclude.concat([TYPES[:voting_topic_upvote], TYPES[:voting_topic_unvote]])
end
unless defined?(SiteSetting.chat_enabled) && SiteSetting.chat_enabled
ids_to_exclude << TYPES[:chat_message]
ids_to_exclude.concat(
[
TYPES[:chat_message_created],
TYPES[:chat_message_edited],
TYPES[:chat_message_trashed],
TYPES[:chat_message_restored],
],
)
end
self.where.not(id: ids_to_exclude)
end

View File

@ -0,0 +1,69 @@
# frozen_string_literal: true
RSpec.describe WebHookEventType do
describe "#active" do
it "returns only active types" do
core_event_types = WebHookEventType.active.map(&:name)
expect(core_event_types).to eq(
%w[
topic_created
topic_revised
topic_edited
topic_destroyed
topic_recovered
post_created
post_edited
post_destroyed
post_recovered
user_logged_in
user_logged_out
user_confirmed_email
user_created
user_approved
user_updated
user_destroyed
user_suspended
user_unsuspended
group_created
group_updated
group_destroyed
category_created
category_updated
category_destroyed
tag_created
tag_updated
tag_destroyed
reviewable_created
reviewable_updated
notification_created
user_badge_granted
user_badge_revoked
user_added_to_group
user_removed_from_group
post_liked
user_promoted
],
)
SiteSetting.stubs(:solved_enabled).returns(true)
SiteSetting.stubs(:assign_enabled).returns(true)
SiteSetting.stubs(:voting_enabled).returns(true)
SiteSetting.stubs(:chat_enabled).returns(true)
plugins_event_types = WebHookEventType.active.map(&:name) - core_event_types
expect(plugins_event_types).to eq(
%w[
accepted_solution
unaccepted_solution
assigned
unassigned
topic_upvote
topic_unvote
chat_message_created
chat_message_edited
chat_message_trashed
chat_message_restored
],
)
end
end
end