From fb15da43da1a4f8f733812dc4af455f27e756418 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 20 May 2020 12:07:48 +0300 Subject: [PATCH] Remove old web hooks in favor of 'reviewable' web hook (#9776) * FIX: Emit web hooks for flags * FEATURE: Remove 'flag' web hook in favor of 'reviewable' web hook * FEATURE: Remove 'queued post' web hook in favor of 'reviewable' web hook * FIX: Do not set a default value for web hooks with no events --- .../admin/routes/admin-web-hooks-show.js | 3 +-- app/models/web_hook_event_type.rb | 2 -- config/locales/client.en.yml | 6 ------ db/fixtures/007_web_hook_event_types.rb | 10 --------- .../20200514075356_remove_flag_web_hooks.rb | 21 +++++++++++++++++++ ...0514075407_remove_queued_post_web_hooks.rb | 21 +++++++++++++++++++ spec/fabricators/web_hook_fabricator.rb | 16 -------------- 7 files changed, 43 insertions(+), 36 deletions(-) create mode 100644 db/migrate/20200514075356_remove_flag_web_hooks.rb create mode 100644 db/migrate/20200514075407_remove_queued_post_web_hooks.rb diff --git a/app/assets/javascripts/admin/routes/admin-web-hooks-show.js b/app/assets/javascripts/admin/routes/admin-web-hooks-show.js index 34aed775cc5..f0860e79f71 100644 --- a/app/assets/javascripts/admin/routes/admin-web-hooks-show.js +++ b/app/assets/javascripts/admin/routes/admin-web-hooks-show.js @@ -1,5 +1,4 @@ import { get } from "@ember/object"; -import { isEmpty } from "@ember/utils"; import DiscourseRoute from "discourse/routes/discourse"; export default DiscourseRoute.extend({ @@ -15,7 +14,7 @@ export default DiscourseRoute.extend({ }, setupController(controller, model) { - if (model.get("isNew") || isEmpty(model.get("web_hook_event_types"))) { + if (model.get("isNew")) { model.set("web_hook_event_types", controller.get("defaultEventTypes")); } diff --git a/app/models/web_hook_event_type.rb b/app/models/web_hook_event_type.rb index 952c1c2062c..442f14cb8ce 100644 --- a/app/models/web_hook_event_type.rb +++ b/app/models/web_hook_event_type.rb @@ -7,8 +7,6 @@ class WebHookEventType < ActiveRecord::Base GROUP = 4 CATEGORY = 5 TAG = 6 - FLAG = 7 - QUEUED_POST = 8 REVIEWABLE = 9 NOTIFICATION = 10 SOLVED = 11 diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index a647dc5cde1..0da7d673427 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -3598,12 +3598,6 @@ en: tag_event: name: "Tag Event" details: "When a tag is created, updated or destroyed." - flag_event: - name: "Flag Event" - details: "When a flag is created, agreed, disagreed or ignored." - queued_post_event: - name: "Post Approval Event" - details: "When a new queued post is created, approved or rejected." reviewable_event: name: "Reviewable Event" details: "When a new item is ready for review and when its status is updated." diff --git a/db/fixtures/007_web_hook_event_types.rb b/db/fixtures/007_web_hook_event_types.rb index 8bf8e938055..ec666ec5ad2 100644 --- a/db/fixtures/007_web_hook_event_types.rb +++ b/db/fixtures/007_web_hook_event_types.rb @@ -30,16 +30,6 @@ WebHookEventType.seed do |b| b.name = "tag" end -WebHookEventType.seed do |b| - b.id = WebHookEventType::FLAG - b.name = "flag" -end - -WebHookEventType.seed do |b| - b.id = WebHookEventType::QUEUED_POST - b.name = "queued_post" -end - WebHookEventType.seed do |b| b.id = WebHookEventType::REVIEWABLE b.name = "reviewable" diff --git a/db/migrate/20200514075356_remove_flag_web_hooks.rb b/db/migrate/20200514075356_remove_flag_web_hooks.rb new file mode 100644 index 00000000000..448b7fb771b --- /dev/null +++ b/db/migrate/20200514075356_remove_flag_web_hooks.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveFlagWebHooks < ActiveRecord::Migration[6.0] + def up + flag_event_type_id = 7 + + DB.exec <<~SQL + DELETE FROM web_hook_event_types_hooks + WHERE web_hook_event_type_id = #{flag_event_type_id} + SQL + + DB.exec <<~SQL + DELETE FROM web_hook_event_types + WHERE id = #{flag_event_type_id} + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20200514075407_remove_queued_post_web_hooks.rb b/db/migrate/20200514075407_remove_queued_post_web_hooks.rb new file mode 100644 index 00000000000..632e5013dc9 --- /dev/null +++ b/db/migrate/20200514075407_remove_queued_post_web_hooks.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +class RemoveQueuedPostWebHooks < ActiveRecord::Migration[6.0] + def up + queued_post_event_type_id = 8 + + DB.exec <<~SQL + DELETE FROM web_hook_event_types_hooks + WHERE web_hook_event_type_id = #{queued_post_event_type_id} + SQL + + DB.exec <<~SQL + DELETE FROM web_hook_event_types + WHERE id = #{queued_post_event_type_id} + SQL + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/spec/fabricators/web_hook_fabricator.rb b/spec/fabricators/web_hook_fabricator.rb index 46472510808..9edc591791f 100644 --- a/spec/fabricators/web_hook_fabricator.rb +++ b/spec/fabricators/web_hook_fabricator.rb @@ -71,22 +71,6 @@ Fabricator(:tag_web_hook, from: :web_hook) do end end -Fabricator(:flag_web_hook, from: :web_hook) do - transient flag_hook: WebHookEventType.find_by(name: 'flag') - - after_build do |web_hook, transients| - web_hook.web_hook_event_types = [transients[:flag_hook]] - end -end - -Fabricator(:queued_post_web_hook, from: :web_hook) do - transient queued_post_hook: WebHookEventType.find_by(name: 'queued_post') - - after_build do |web_hook, transients| - web_hook.web_hook_event_types = [transients[:queued_post_hook]] - end -end - Fabricator(:reviewable_web_hook, from: :web_hook) do transient reviewable_hook: WebHookEventType.find_by(name: 'reviewable')