From 68e4e6a5755db4dd974eaeed73d5cfc517449b75 Mon Sep 17 00:00:00 2001 From: Jeff Wong Date: Mon, 18 Jun 2018 17:05:04 -0700 Subject: [PATCH] FIX: staged users are still tl0 but do not trigger spam if 1 week old. --- app/models/post.rb | 2 +- app/models/user.rb | 4 ++++ lib/validators/post_validator.rb | 2 +- spec/models/post_spec.rb | 14 +++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index c309505497..c797c471a8 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.from_staged? || acting_user.has_trust_level?(TrustLevel[1])) + return false if acting_user.present? && (acting_user.staged? || acting_user.mature_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/app/models/user.rb b/app/models/user.rb index c28809f26b..a20687a5d1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1073,6 +1073,10 @@ class User < ActiveRecord::Base custom_fields[User::FROM_STAGED] end + def mature_staged? + from_staged? && self.created_at && self.created_at < 1.week.ago + end + protected def badge_grant diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index 18c3047eab..f8c58ec2e6 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.from_staged?) + post.acting_user.present? && post.acting_user.has_trust_level?(TrustLevel[level]) end def private_message?(post) diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 68699412fb..f2bd06587d 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -967,9 +967,21 @@ describe Post do expect(post.has_host_spam?).to eq(false) end - it "doesn't punish previously staged users" do + it "punishes previously staged users that were created within 1 week" do SiteSetting.newuser_spam_host_threshold = 1 + SiteSetting.newuser_max_links = 3 user = Fabricate(:user, staged: true, trust_level: 0) + user.created_at = 1.hour.ago + user.unstage + post = Fabricate(:post, raw: raw, user: user) + expect(post.has_host_spam?).to eq(true) + end + + it "doesn't punish previously staged users over 1 week old" do + SiteSetting.newuser_spam_host_threshold = 1 + SiteSetting.newuser_max_links = 3 + user = Fabricate(:user, staged: true, trust_level: 0) + user.created_at = 1.week.ago user.unstage post = Fabricate(:post, raw: raw, user: user) expect(post.has_host_spam?).to eq(false)