Remove old web hooks in favor of 'reviewable' web hook (#9776)

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

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 34aed77..f0860e7 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 952c1c2..442f14c 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 a647dc5..0da7d67 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 8bf8e93..ec666ec 100644
--- a/db/fixtures/007_web_hook_event_types.rb
+++ b/db/fixtures/007_web_hook_event_types.rb
@@ -31,16 +31,6 @@ WebHookEventType.seed do |b|
 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"
 end
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 0000000..448b7fb
--- /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 0000000..632e501
--- /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 4647251..9edc591 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')
 

GitHub sha: fb15da43

1 Like

This commit appears in #9776 which was approved by eviltrout. It was merged by nbianca.