Skip to content

A platform for community discussion. Free, open, simple.

FIX: Don’t automatically approve illegal reviewables on post deletion (#37015)

Loïc Guitautfd04f690b15b
diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rb
index 7df726cb430..6aae1aff5e0 100644
--- a/lib/post_destroyer.rb
+++ b/lib/post_destroyer.rb
@@ -249,7 +249,11 @@ class PostDestroyer
ignore(@post.reviewable_flag)
end
elsif reviewable = @post.reviewable_flag
- @opts[:defer_flags] ? ignore(reviewable) : agree(reviewable)
+ if @opts[:defer_flags]
+ ignore(reviewable)
+ else
+ agree(reviewable) unless reviewable.potentially_illegal?
+ end
end
end
end
diff --git a/spec/lib/post_destroyer_spec.rb b/spec/lib/post_destroyer_spec.rb
index 7cfb726763d..8dd22cfdc88 100644
--- a/spec/lib/post_destroyer_spec.rb
+++ b/spec/lib/post_destroyer_spec.rb
@@ -983,6 +983,17 @@ RSpec.describe PostDestroyer do
expect(ReviewableFlaggedPost.pending.count).to eq(0)
end
+ context "when the flagged post is potentially illegal" do
+ before { ReviewableFlaggedPost.pending.update_all(potentially_illegal: true) }
+
+ it "does not automatically mark it as ignored or approved" do
+ expect { PostDestroyer.new(moderator, second_post).destroy }.not_to change {
+ ReviewableFlaggedPost.pending.count
+ }
+ expect(Jobs::SendSystemMessage.jobs).to be_empty
+ end
+ end
+
context "when custom flags" do
fab!(:custom_flag) { Fabricate(:flag, name: "custom flag", notify_type: true) }
let(:third_post) { Fabricate(:post, topic_id: post.topic_id) }