FIX: don't enforce newuser_spam_host_threshold on private messages

This commit is contained in:
Neil Lalonde 2017-08-10 17:18:57 -04:00
parent c1228dab25
commit 15a74d6d3e
2 changed files with 18 additions and 1 deletions

View File

@ -303,6 +303,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 topic&.private_message?
total_hosts_usage.values.any? { |count| count >= SiteSetting.newuser_spam_host_threshold }
end

View File

@ -835,8 +835,10 @@ describe Post do
end
describe "has_host_spam" do
let(:raw) { "hello from my site http://www.somesite.com http://#{GlobalSetting.hostname} http://#{RailsMultisite::ConnectionManagement.current_hostname}" }
it "correctly detects host spam" do
post = Fabricate(:post, raw: "hello from my site http://www.somesite.com http://#{GlobalSetting.hostname} http://#{RailsMultisite::ConnectionManagement.current_hostname}")
post = Fabricate(:post, raw: raw)
expect(post.total_hosts_usage).to eq("www.somesite.com" => 1)
post.acting_user.trust_level = 0
@ -850,6 +852,20 @@ describe Post do
SiteSetting.white_listed_spam_host_domains = "bla.com|boo.com | somesite.com "
expect(post.has_host_spam?).to eq(false)
end
it "doesn't punish staged users" do
SiteSetting.newuser_spam_host_threshold = 1
user = Fabricate(:user, staged: true, trust_level: 0)
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)
post = Fabricate(:post, raw: raw, user: user, topic: Fabricate(:private_message_topic, user: user))
expect(post.has_host_spam?).to eq(false)
end
end
it "has custom fields" do