FIX: Don't send replies to flags that are ignored by expiry

FIX: Don’t send replies to flags that are ignored by expiry

The AutoQueueHandler will ignore really old flags. In that case, don’t notify the user that the moderator is looking into it. They probably never saw it because it didn’t meet the reviewable minimum priority.

diff --git a/app/jobs/scheduled/auto_queue_handler.rb b/app/jobs/scheduled/auto_queue_handler.rb
index bf498ad..659aa92 100644
--- a/app/jobs/scheduled/auto_queue_handler.rb
+++ b/app/jobs/scheduled/auto_queue_handler.rb
@@ -16,7 +16,7 @@ module Jobs
         .each do |reviewable|
 
         if reviewable.is_a?(ReviewableFlaggedPost)
-          reviewable.perform(Discourse.system_user, :ignore)
+          reviewable.perform(Discourse.system_user, :ignore, expired: true)
         elsif reviewable.is_a?(ReviewableQueuedPost)
           reviewable.perform(Discourse.system_user, :reject_post)
         elsif reviewable.is_a?(ReviewableUser)
diff --git a/app/models/reviewable_flagged_post.rb b/app/models/reviewable_flagged_post.rb
index a8eea80..cd65edc 100644
--- a/app/models/reviewable_flagged_post.rb
+++ b/app/models/reviewable_flagged_post.rb
@@ -101,7 +101,9 @@ class ReviewableFlaggedPost < Reviewable
       action.deferred_by_id = performed_by.id
       # so callback is called
       action.save
-      action.add_moderator_post_if_needed(performed_by, :ignored, args[:post_was_deleted])
+      unless args[:expired]
+        action.add_moderator_post_if_needed(performed_by, :ignored, args[:post_was_deleted])
+      end
     end
 
     if actions.first.present?
diff --git a/spec/jobs/auto_queue_handler_spec.rb b/spec/jobs/auto_queue_handler_spec.rb
index d073718..771651c 100644
--- a/spec/jobs/auto_queue_handler_spec.rb
+++ b/spec/jobs/auto_queue_handler_spec.rb
@@ -6,8 +6,24 @@ describe Jobs::AutoQueueHandler do
 
   subject { Jobs::AutoQueueHandler.new.execute({}) }
 
-  context "old flag" do
-    fab!(:old) { Fabricate(:reviewable_flagged_post, created_at: 61.days.ago) }
+  context "old flagged post" do
+    # fab!(:old) { Fabricate(:reviewable_flagged_post, created_at: 61.days.ago) }
+
+    fab!(:spam_result) do
+      PostActionCreator.new(
+        Fabricate(:user),
+        Fabricate(:post),
+        PostActionType.types[:spam],
+        message: 'this is the initial message'
+      ).perform
+    end
+
+    fab!(:post_action) { spam_result.post_action }
+    fab!(:old) {
+      spam_result.reviewable.update_column(:created_at, 61.days.ago)
+      spam_result.reviewable
+    }
+
     fab!(:not_old) { Fabricate(:reviewable_flagged_post, created_at: 59.days.ago) }
 
     it "defers the old flag if auto_handle_queued_age is 60" do
@@ -15,6 +31,7 @@ describe Jobs::AutoQueueHandler do
       subject
       expect(not_old.reload).to be_pending
       expect(old.reload).not_to be_pending
+      expect(post_action.related_post.topic.posts_count).to eq(1)
     end
 
     it "doesn't defer the old flag if auto_handle_queued_age is 0" do

GitHub sha: b85fa628

1 Like