From 9e55767f6afc886f59a124dea1c1b64dd878b9e2 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Fri, 15 Jun 2018 10:45:53 -0700 Subject: [PATCH] FIX: don't punish a user for being previously staged for spam flags. --- app/models/post.rb | 2 +- lib/validators/post_validator.rb | 2 +- spec/models/post_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index cbde19341e4..c3095054978 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -326,7 +326,7 @@ class Post < ActiveRecord::Base # Prevent new users from posting the same hosts too many times. def has_host_spam? - return false if acting_user.present? && (acting_user.staged? || acting_user.has_trust_level?(TrustLevel[1])) + return false if acting_user.present? && (acting_user.staged? || acting_user.from_staged? || acting_user.has_trust_level?(TrustLevel[1])) return false if topic&.private_message? total_hosts_usage.values.any? { |count| count >= SiteSetting.newuser_spam_host_threshold } diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index f8c58ec2e64..18c3047eabf 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -144,7 +144,7 @@ class Validators::PostValidator < ActiveModel::Validator private def acting_user_is_trusted?(post, level = 1) - post.acting_user.present? && post.acting_user.has_trust_level?(TrustLevel[level]) + post.acting_user.present? && (post.acting_user.has_trust_level?(TrustLevel[level]) || post.acting_user.from_staged?) end def private_message?(post) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index ee3ed2d57b2..68699412fbf 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -967,6 +967,14 @@ describe Post do expect(post.has_host_spam?).to eq(false) end + it "doesn't punish previously staged users" do + SiteSetting.newuser_spam_host_threshold = 1 + user = Fabricate(:user, staged: true, trust_level: 0) + user.unstage + post = Fabricate(:post, raw: raw, user: user) + expect(post.has_host_spam?).to eq(false) + end + it "ignores private messages" do SiteSetting.newuser_spam_host_threshold = 1 user = Fabricate(:user, trust_level: 0)