FEATURE: automatically hide posts made by TL0 users when flagged by a TL3 user

This commit is contained in:
Régis Hanol 2014-10-01 18:53:17 +02:00
parent 98b6b9821a
commit 70884d2436
3 changed files with 31 additions and 5 deletions

View File

@ -62,7 +62,12 @@ class Post < ActiveRecord::Base
delegate :username, to: :user delegate :username, to: :user
def self.hidden_reasons def self.hidden_reasons
@hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again, :new_user_spam_threshold_reached) @hidden_reasons ||= Enum.new(
:flag_threshold_reached,
:flag_threshold_reached_again,
:new_user_spam_threshold_reached,
:flagged_by_tl3_user
)
end end
def self.types def self.types

View File

@ -372,7 +372,7 @@ class PostAction < ActiveRecord::Base
def enforce_rules def enforce_rules
post = Post.with_deleted.where(id: post_id).first post = Post.with_deleted.where(id: post_id).first
PostAction.auto_hide_if_needed(post, post_action_type_key) PostAction.auto_hide_if_needed(user, post, post_action_type_key)
SpamRulesEnforcer.enforce!(post.user) if post_action_type_key == :spam SpamRulesEnforcer.enforce!(post.user) if post_action_type_key == :spam
end end
@ -382,10 +382,16 @@ class PostAction < ActiveRecord::Base
end end
end end
def self.auto_hide_if_needed(post, post_action_type) def self.auto_hide_if_needed(acting_user, post, post_action_type)
return if post.hidden return if post.hidden
if PostActionType.auto_action_flag_types.include?(post_action_type) && if post_action_type == :spam &&
acting_user.trust_level == TrustLevel[3] &&
post.user.trust_level == TrustLevel[0]
hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user])
elsif PostActionType.auto_action_flag_types.include?(post_action_type) &&
SiteSetting.flags_required_to_hide_post > 0 SiteSetting.flags_required_to_hide_post > 0
old_flags, new_flags = PostAction.flag_counts_for(post.id) old_flags, new_flags = PostAction.flag_counts_for(post.id)

View File

@ -326,6 +326,21 @@ describe PostAction do
post.topic.visible.should == false post.topic.visible.should == false
end 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)
PostAction.act(Fabricate(:leader), post, PostActionType.types[:spam])
post.reload
post.hidden.should == true
post.hidden_at.should be_present
post.hidden_reason_id.should == Post.hidden_reasons[:flagged_by_tl3_user]
end
it "can flag the topic instead of a post" do it "can flag the topic instead of a post" do
post1 = create_post post1 = create_post
post2 = create_post(topic: post1.topic) post2 = create_post(topic: post1.topic)