Disable flagging behaviour in favor of the new reviewable API (#34)

approved
#1

Disable flagging behaviour in favor of the new reviewable API (#34)

diff --git a/plugin.rb b/plugin.rb
index e49f8d9..d08efd7 100644
--- a/plugin.rb
+++ b/plugin.rb
@@ -30,9 +30,24 @@ after_initialize do
   require 'topic_assigner'
   require 'pending_assigns_reminder'
 
+=begin
+  TODO: Remove this once 2.3 becomes the new stable.
+  Also remove:
+    - flagged-* connectors
+    - flagged queue code inside the JS initializer
+=end
+  reviewable_api_enabled = begin
+    'Reviewable'.constantize
+    true
+  rescue NameError
+    false
+  end
+
   # Raise an invalid access error if a user tries to act on something
   # not assigned to them
   DiscourseEvent.on(:before_staff_flag_action) do |args|
+    return if reviewable_api_enabled
+
     if SiteSetting.assign_locks_flags?
 
       if custom_fields = args[:post].topic&.custom_fields
@@ -247,6 +262,8 @@ after_initialize do
 
   # Unassign if there are no more flags in the topic
   on(:flag_reviewed) do |post|
+    return if reviewable_api_enabled
+
     if SiteSetting.assign_locks_flags? &&
       post.topic &&
       FlagQuery.flagged_post_actions(topic_id: post.topic_id, filter: "old").count > 0 &&
diff --git a/spec/integration/assign_spec.rb b/spec/integration/assign_spec.rb
index a359c40..46cec29 100644
--- a/spec/integration/assign_spec.rb
+++ b/spec/integration/assign_spec.rb
@@ -75,7 +75,7 @@ describe 'integration tests' do
       )
     end
 
-    it "do not raise error if topic is deleted" do
+    it "do not raise error if topic is deleted", unless: defined?(Reviewable) do
       expect { DiscourseEvent.trigger(:before_staff_flag_action, args) }
         .to raise_error(Discourse::InvalidAccess)

GitHub sha: 4b7a99f0

#2

Is it possible to use defined?(Reviewable) here too?

#3

Done here:

2 Likes
Approved #4