Make topics invisible when first post is automatically hidden because of spam flags
This commit is contained in:
parent
77b218a142
commit
246148d4ff
|
@ -51,12 +51,16 @@ class SpamRulesEnforcer
|
|||
end
|
||||
|
||||
def punish_user
|
||||
Post.transaction do
|
||||
Post.update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Post.hidden_reasons[:new_user_spam_threshold_reached]], user_id: @user.id)
|
||||
topic_ids = Post.where('user_id = ? and post_number = ?', @user.id, 1).pluck(:topic_id)
|
||||
Topic.update_all({ visible: false }, id: topic_ids) unless topic_ids.empty?
|
||||
SystemMessage.create(@user, :too_many_spam_flags)
|
||||
GroupMessage.create(Group[:moderators].name, :user_automatically_blocked, {user: @user, limit_once_per: false})
|
||||
@user.blocked = true
|
||||
@user.save
|
||||
end
|
||||
end
|
||||
|
||||
def clear_user
|
||||
SystemMessage.create(@user, :unblocked)
|
||||
|
|
|
@ -112,6 +112,11 @@ describe SpamRulesEnforcer do
|
|||
expect(post.reload).to be_hidden
|
||||
end
|
||||
|
||||
it "hides the topic if the post was the first post" do
|
||||
subject.punish_user
|
||||
expect(post.topic.reload).to_not be_visible
|
||||
end
|
||||
|
||||
it 'prevents the user from making new posts' do
|
||||
subject.punish_user
|
||||
expect(Guardian.new(user).can_create_post?(nil)).to be_false
|
||||
|
|
Loading…
Reference in New Issue