FIX: Don't notify of pending flags if min_flags_staff_visibility not met

FIX: Don’t notify of pending flags if min_flags_staff_visibility not met

diff --git a/app/jobs/scheduled/pending_flags_reminder.rb b/app/jobs/scheduled/pending_flags_reminder.rb
index 05ab123..50f02a5 100644
--- a/app/jobs/scheduled/pending_flags_reminder.rb
+++ b/app/jobs/scheduled/pending_flags_reminder.rb
@@ -15,7 +15,7 @@ module Jobs
 
         flag_ids = pending_flag_ids
 
-        if flag_ids.size > 0 && last_notified_id.to_i < flag_ids.max
+        if flag_ids.size >= SiteSetting.min_flags_staff_visibility && last_notified_id.to_i < flag_ids.max
 
           usernames = active_moderator_usernames
           mentions = usernames.size > 0 ? "@#{usernames.join(', @')} " : ""
diff --git a/spec/jobs/pending_flags_reminder_spec.rb b/spec/jobs/pending_flags_reminder_spec.rb
index a99852b..6a69def 100644
--- a/spec/jobs/pending_flags_reminder_spec.rb
+++ b/spec/jobs/pending_flags_reminder_spec.rb
@@ -28,13 +28,6 @@ describe Jobs::PendingFlagsReminder do
       described_class.new.execute({})
     end
 
-    it "sends message when there is a flag older than 48 hours" do
-      Fabricate(:flag, created_at: 49.hours.ago)
-      PostAction.stubs(:flagged_posts_count).returns(1)
-      PostCreator.expects(:create).once.returns(true)
-      described_class.new.execute({})
-    end
-
     it "doesn't send a message if there are no new flags older than 48 hours old" do
       old_flag = Fabricate(:flag, created_at: 50.hours.ago)
       new_flag = Fabricate(:flag, created_at: 47.hours.ago)
@@ -45,5 +38,21 @@ describe Jobs::PendingFlagsReminder do
       job.execute({})
       expect(job.last_notified_id).to eq(old_flag.id)
     end
+
+    it "doesn't send a message when min_flags_staff_visibility is not met" do
+      SiteSetting.min_flags_staff_visibility = 2
+      Fabricate(:flag, created_at: 49.hours.ago)
+      PostAction.stubs(:flagged_posts_count).returns(1)
+      PostCreator.expects(:create).never
+      described_class.new.execute({})
+    end
+
+    it "sends message when there is a flag older than 48 hours" do
+      Fabricate(:flag, created_at: 49.hours.ago)
+      PostAction.stubs(:flagged_posts_count).returns(1)
+      PostCreator.expects(:create).once.returns(true)
+      described_class.new.execute({})
+    end
+
   end
 end

GitHub sha: f32de88d

1 Like