DEV: Delete plugin specific webhook event types (#29374)

Background
When creating webhooks on a site without the Discourse Category Experts plugin installed, the category_experts_unapproved_event and category_experts_approved_event webhook events are getting automatically added to webhooks without a way to disable them.

The category_experts_unapproved_event and category_experts_approved_event webhook events are associated with the Discourse Category Experts plugin so I am moving these webhook events into the Category Experts plugin.

Changes
This PR deletes Category Experts plugin specific webhook event types added into core.
This commit is contained in:
Guhyoun Nam 2024-10-24 11:02:58 -05:00 committed by GitHub
parent 0ecad3a7c9
commit 82ad7f9d17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 10 additions and 24 deletions

View File

@ -40,8 +40,6 @@ class WebHook < ActiveRecord::Base
WebHookEventType::TYPES[:post_edited], WebHookEventType::TYPES[:post_edited],
WebHookEventType::TYPES[:post_destroyed], WebHookEventType::TYPES[:post_destroyed],
WebHookEventType::TYPES[:post_recovered], WebHookEventType::TYPES[:post_recovered],
WebHookEventType::TYPES[:category_experts_approved],
WebHookEventType::TYPES[:category_experts_unapproved],
], ],
) )
end end

View File

@ -85,8 +85,6 @@ class WebHookEventType < ActiveRecord::Base
chat_message_edited: 1802, chat_message_edited: 1802,
chat_message_trashed: 1803, chat_message_trashed: 1803,
chat_message_restored: 1804, chat_message_restored: 1804,
category_experts_approved: 1901,
category_experts_unapproved: 1902,
} }
has_and_belongs_to_many :web_hooks has_and_belongs_to_many :web_hooks
@ -118,11 +116,6 @@ class WebHookEventType < ActiveRecord::Base
], ],
) )
end end
unless defined?(SiteSetting.enable_category_experts) && SiteSetting.enable_category_experts
ids_to_exclude.concat(
[TYPES[:category_experts_approved], TYPES[:category_experts_unapproved]],
)
end
self.where.not(id: ids_to_exclude) self.where.not(id: ids_to_exclude)
end end
end end

View File

@ -5442,8 +5442,6 @@ en:
post_edited: "Post is updated" post_edited: "Post is updated"
post_destroyed: "Post is deleted" post_destroyed: "Post is deleted"
post_recovered: "Post is recovered" post_recovered: "Post is recovered"
category_experts_approved: "Post marked as category experts post"
category_experts_unapproved: "Post unmarked as category experts post"
group_event: group_event:
group_name: "Group Events" group_name: "Group Events"
group_created: "Group is created" group_created: "Group is created"

View File

@ -230,13 +230,3 @@ WebHookEventType.seed do |b|
b.name = "chat_message_restored" b.name = "chat_message_restored"
b.group = WebHookEventType.groups[:chat] b.group = WebHookEventType.groups[:chat]
end end
WebHookEventType.seed do |b|
b.id = WebHookEventType::TYPES[:category_experts_approved]
b.name = "category_experts_approved"
b.group = WebHookEventType.groups[:post]
end
WebHookEventType.seed do |b|
b.id = WebHookEventType::TYPES[:category_experts_unapproved]
b.name = "category_experts_unapproved"
b.group = WebHookEventType.groups[:post]
end

View File

@ -0,0 +1,10 @@
# frozen_string_literal: true
class RemoveCategoryExpertsWebHookEventTypes < ActiveRecord::Migration[7.1]
def up
execute "DELETE FROM web_hook_event_types WHERE (name, id) IN (('category_experts_approved', 1901), ('category_experts_unapproved', 1902))"
end
def down
raise ActiveRecord::IrreversibleMigration
end
end

View File

@ -49,7 +49,6 @@ RSpec.describe WebHookEventType do
SiteSetting.stubs(:assign_enabled).returns(true) SiteSetting.stubs(:assign_enabled).returns(true)
SiteSetting.stubs(:topic_voting_enabled).returns(true) SiteSetting.stubs(:topic_voting_enabled).returns(true)
SiteSetting.stubs(:chat_enabled).returns(true) SiteSetting.stubs(:chat_enabled).returns(true)
SiteSetting.stubs(:enable_category_experts).returns(true)
plugins_event_types = WebHookEventType.active.map(&:name) - core_event_types plugins_event_types = WebHookEventType.active.map(&:name) - core_event_types
expect(plugins_event_types).to match_array( expect(plugins_event_types).to match_array(
%w[ %w[
@ -63,8 +62,6 @@ RSpec.describe WebHookEventType do
chat_message_edited chat_message_edited
chat_message_trashed chat_message_trashed
chat_message_restored chat_message_restored
category_experts_approved
category_experts_unapproved
], ],
) )
end end