Merge pull request #6476 from vinothkannans/tl4-flag
FEATURE: automatically hide non-TL4 posts when flagged by a TL4 user
This commit is contained in:
commit
6a444eee56
|
@ -117,7 +117,8 @@ class Post < ActiveRecord::Base
|
||||||
flag_threshold_reached_again: 2,
|
flag_threshold_reached_again: 2,
|
||||||
new_user_spam_threshold_reached: 3,
|
new_user_spam_threshold_reached: 3,
|
||||||
flagged_by_tl3_user: 4,
|
flagged_by_tl3_user: 4,
|
||||||
email_spam_header_found: 5)
|
email_spam_header_found: 5,
|
||||||
|
flagged_by_tl4_user: 6)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.types
|
def self.types
|
||||||
|
|
|
@ -583,13 +583,19 @@ class PostAction < ActiveRecord::Base
|
||||||
|
|
||||||
hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user])
|
hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl3_user])
|
||||||
|
|
||||||
elsif PostActionType.auto_action_flag_types.include?(post_action_type) &&
|
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)
|
if acting_user.has_trust_level?(TrustLevel[4]) &&
|
||||||
|
post.user&.trust_level != TrustLevel[4]
|
||||||
|
|
||||||
if new_flags >= SiteSetting.flags_required_to_hide_post
|
hide_post!(post, post_action_type, Post.hidden_reasons[:flagged_by_tl4_user])
|
||||||
hide_post!(post, post_action_type, guess_hide_reason(post))
|
elsif SiteSetting.flags_required_to_hide_post > 0
|
||||||
|
|
||||||
|
_old_flags, new_flags = PostAction.flag_counts_for(post.id)
|
||||||
|
|
||||||
|
if new_flags >= SiteSetting.flags_required_to_hide_post
|
||||||
|
hide_post!(post, post_action_type, guess_hide_reason(post))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -153,7 +153,7 @@ module DiscourseNarrativeBot
|
||||||
flag = PostAction.create!(
|
flag = PostAction.create!(
|
||||||
user: self.discobot_user,
|
user: self.discobot_user,
|
||||||
post: post, post_action_type_id:
|
post: post, post_action_type_id:
|
||||||
PostActionType.types[:off_topic]
|
PostActionType.types[:notify_moderators]
|
||||||
)
|
)
|
||||||
|
|
||||||
PostAction.defer_flags!(post, self.discobot_user)
|
PostAction.defer_flags!(post, self.discobot_user)
|
||||||
|
|
|
@ -501,6 +501,37 @@ describe PostAction do
|
||||||
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flagged_by_tl3_user])
|
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flagged_by_tl3_user])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "hide non-tl4 posts that are flagged by a tl4 user" do
|
||||||
|
SiteSetting.site_contact_username = admin.username
|
||||||
|
|
||||||
|
post_action_type = PostActionType.types[:spam]
|
||||||
|
tl4_user = Fabricate(:trust_level_4)
|
||||||
|
|
||||||
|
user = Fabricate(:leader)
|
||||||
|
post = create_post(user: user)
|
||||||
|
|
||||||
|
PostAction.act(tl4_user, post, post_action_type)
|
||||||
|
|
||||||
|
post.reload
|
||||||
|
|
||||||
|
expect(post.hidden).to be_truthy
|
||||||
|
expect(post.hidden_at).to be_present
|
||||||
|
expect(post.hidden_reason_id).to eq(Post.hidden_reasons[:flagged_by_tl4_user])
|
||||||
|
|
||||||
|
post = create_post(user: user)
|
||||||
|
PostAction.act(Fabricate(:leader), post, post_action_type)
|
||||||
|
post.reload
|
||||||
|
|
||||||
|
expect(post.hidden).to be_falsey
|
||||||
|
|
||||||
|
user = Fabricate(:trust_level_4)
|
||||||
|
post = create_post(user: user)
|
||||||
|
PostAction.act(tl4_user, post, post_action_type)
|
||||||
|
post.reload
|
||||||
|
|
||||||
|
expect(post.hidden).to be_falsey
|
||||||
|
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)
|
||||||
|
|
Loading…
Reference in New Issue