mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -05:00
FEATURE: automatically hide posts made by TL0 users when flagged by a TL3 user
This commit is contained in:
parent
98b6b9821a
commit
70884d2436
3 changed files with 31 additions and 5 deletions
|
@ -62,7 +62,12 @@ class Post < ActiveRecord::Base
|
|||
delegate :username, to: :user
|
||||
|
||||
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
|
||||
|
||||
def self.types
|
||||
|
|
|
@ -372,7 +372,7 @@ class PostAction < ActiveRecord::Base
|
|||
|
||||
def enforce_rules
|
||||
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
|
||||
end
|
||||
|
||||
|
@ -382,10 +382,16 @@ class PostAction < ActiveRecord::Base
|
|||
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
|
||||
|
||||
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
|
||||
|
||||
old_flags, new_flags = PostAction.flag_counts_for(post.id)
|
||||
|
|
|
@ -326,6 +326,21 @@ describe PostAction do
|
|||
post.topic.visible.should == false
|
||||
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
|
||||
post1 = create_post
|
||||
post2 = create_post(topic: post1.topic)
|
||||
|
|
Loading…
Reference in a new issue