From c3bbf643b16ee81fadac738edef4698d9743267c Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 17 Sep 2019 15:58:30 -0400 Subject: [PATCH] FIX: Put back the TL3 -> TL0 spam thing We talked about it and decided it's still relevant in the score world. --- lib/post_action_creator.rb | 9 +++++++++ spec/models/post_action_spec.rb | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/post_action_creator.rb b/lib/post_action_creator.rb index 47538b1b459..215345c4250 100644 --- a/lib/post_action_creator.rb +++ b/lib/post_action_creator.rb @@ -156,6 +156,15 @@ private return if @post.hidden? return if !@created_by.staff? && @post.user&.staff? + # Special case: If you have TL3 and the user is TL0, and the flag is spam, + # hide it immediately. + if @post_action_name == :spam && + @created_by.has_trust_level?(TrustLevel[3]) && + @post.user&.trust_level == TrustLevel[0] + @post.hide!(@post_action_type_id, Post.hidden_reasons[:flagged_by_tl3_user]) + return + end + score = ReviewableFlaggedPost.find_by(target: @post)&.score || 0 if score >= Reviewable.score_required_to_hide_post @post.hide!(@post_action_type_id) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index cc2f449b1ca..80ff626e6c3 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -608,6 +608,20 @@ describe PostAction do post.reload expect(post.hidden).to eq(true) end + it "hide tl0 posts that are flagged as spam by a tl3 user" do + newuser = Fabricate(:newuser) + post = create_post(user: newuser) + + Discourse.stubs(:site_contact_user).returns(admin) + + PostActionCreator.spam(Fabricate(:leader), post) + + post.reload + + expect(post.hidden).to eq(true) + expect(post.hidden_at).to be_present + expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flagged_by_tl3_user]) + end it "can flag the topic instead of a post" do post1 = create_post