diff --git a/app/services/spam_rules_enforcer.rb b/app/services/spam_rules_enforcer.rb index d98c0ae38f6..afda275c364 100644 --- a/app/services/spam_rules_enforcer.rb +++ b/app/services/spam_rules_enforcer.rb @@ -51,11 +51,15 @@ class SpamRulesEnforcer end def punish_user - Post.update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", Post.hidden_reasons[:new_user_spam_threshold_reached]], user_id: @user.id) - 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 + 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 diff --git a/spec/services/spam_rules_enforcer_spec.rb b/spec/services/spam_rules_enforcer_spec.rb index 34abfebfedb..00c1dc2f7db 100644 --- a/spec/services/spam_rules_enforcer_spec.rb +++ b/spec/services/spam_rules_enforcer_spec.rb @@ -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