FEATURE: white_listed_spam_host_domains for domains that are not blocked for spam

BUGFIX: bypass host spam detection for current host
This commit is contained in:
Sam 2014-02-27 15:43:45 +11:00
parent d5719deac7
commit 1992271bf9
4 changed files with 44 additions and 0 deletions
app/models
config
spec/models

View file

@ -158,8 +158,29 @@ class Post < ActiveRecord::Base
@acting_user = pu
end
def whitelisted_spam_hosts
hosts = SiteSetting
.white_listed_spam_host_domains
.split(",")
.map{|h| h.strip}
.reject{|h| !h.include?(".")}
hosts << GlobalSetting.hostname
end
def total_hosts_usage
hosts = linked_hosts.clone
whitelisted = whitelisted_spam_hosts
hosts.reject! do |h|
whitelisted.any? do |w|
h.end_with?(w)
end
end
return hosts if hosts.length == 0
TopicLink.where(domain: hosts.keys, user_id: acting_user.id)
.group(:domain, :post_id)

View file

@ -774,6 +774,8 @@ en:
privacy_policy_url: "If you have a Privacy Policy document hosted elsewhere that you want to use, provide the full URL here."
newuser_spam_host_threshold: "How many times a new user can post a link to the same host within their `newuser_spam_host_posts` posts before being considered spam."
white_listed_spam_host_domains: "A comma delimited list of domains excluded from spam host testing, new users will be able to create an unrestricted count of posts with links to this domain"
staff_like_weight: "Extra weighting factor given to likes when performed by staff."
reply_by_email_enabled: "Enable replying to topics via email"

View file

@ -333,6 +333,7 @@ spam:
notify_mods_when_user_blocked: false
flag_sockpuppets: true
newuser_spam_host_threshold: 3
white_listed_spam_host_domains: ""
rate_limits:
unique_posts_mins:

View file

@ -795,4 +795,24 @@ describe Post do
end
end
describe "has_host_spam" do
it "correctly detects host spam" do
post = Fabricate(:post, raw: "hello from my site http://www.somesite.com
http://#{GlobalSetting.hostname} ")
post.total_hosts_usage.should == {"www.somesite.com" => 1}
post.acting_user.trust_level = 0
post.has_host_spam?.should == false
SiteSetting.stubs(:newuser_spam_host_threshold).returns(1)
post.has_host_spam?.should == true
SiteSetting.stubs(:white_listed_spam_host_domains).returns("bla.com,boo.com , somesite.com ")
post.has_host_spam?.should == false
end
end
end