mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-04 09:54:00 -04:00
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:
parent
d5719deac7
commit
1992271bf9
4 changed files with 44 additions and 0 deletions
|
@ -158,8 +158,29 @@ class Post < ActiveRecord::Base
|
||||||
@acting_user = pu
|
@acting_user = pu
|
||||||
end
|
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
|
def total_hosts_usage
|
||||||
hosts = linked_hosts.clone
|
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)
|
TopicLink.where(domain: hosts.keys, user_id: acting_user.id)
|
||||||
.group(:domain, :post_id)
|
.group(:domain, :post_id)
|
||||||
|
|
|
@ -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."
|
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."
|
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."
|
staff_like_weight: "Extra weighting factor given to likes when performed by staff."
|
||||||
|
|
||||||
reply_by_email_enabled: "Enable replying to topics via email"
|
reply_by_email_enabled: "Enable replying to topics via email"
|
||||||
|
|
|
@ -333,6 +333,7 @@ spam:
|
||||||
notify_mods_when_user_blocked: false
|
notify_mods_when_user_blocked: false
|
||||||
flag_sockpuppets: true
|
flag_sockpuppets: true
|
||||||
newuser_spam_host_threshold: 3
|
newuser_spam_host_threshold: 3
|
||||||
|
white_listed_spam_host_domains: ""
|
||||||
|
|
||||||
rate_limits:
|
rate_limits:
|
||||||
unique_posts_mins:
|
unique_posts_mins:
|
||||||
|
|
|
@ -795,4 +795,24 @@ describe Post do
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue