slightly better automatic flag reason messages

This commit is contained in:
Régis Hanol 2016-04-25 23:03:17 +02:00
parent 7a079f6de5
commit 2194ccec6e
6 changed files with 21 additions and 19 deletions

View File

@ -229,7 +229,6 @@ class Post < ActiveRecord::Base
end
def whitelisted_spam_hosts
hosts = SiteSetting
.white_listed_spam_host_domains
.split('|')
@ -255,7 +254,8 @@ class Post < ActiveRecord::Base
TopicLink.where(domain: hosts.keys, user_id: acting_user.id)
.group(:domain, :post_id)
.count.each_key do |tuple|
.count
.each_key do |tuple|
domain = tuple[0]
hosts[domain] = (hosts[domain] || 0) + 1
end
@ -265,13 +265,9 @@ 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.has_trust_level?(TrustLevel[1])
return false if acting_user.present? && (acting_user.staged? || acting_user.has_trust_level?(TrustLevel[1]))
total_hosts_usage.each do |_, count|
return true if count >= SiteSetting.newuser_spam_host_threshold
end
false
total_hosts_usage.values.any? { |count| count >= SiteSetting.newuser_spam_host_threshold }
end
def archetype

View File

@ -702,12 +702,16 @@ class User < ActiveRecord::Base
# Flag all posts from a user as spam
def flag_linked_posts_as_spam
admin = Discourse.system_user
disagreed_flag_post_ids = PostAction.where(post_action_type_id: PostActionType.types[:spam])
.where.not(disagreed_at: nil)
.pluck(:post_id)
disagreed_flag_post_ids = PostAction.where(post_action_type_id: PostActionType.types[:spam]).where.not(disagreed_at: nil).pluck(:post_id)
topic_links.includes(:post).where.not(post_id: disagreed_flag_post_ids).each do |tl|
topic_links.includes(:post)
.where.not(post_id: disagreed_flag_post_ids)
.each do |tl|
begin
PostAction.act(admin, tl.post, PostActionType.types[:spam], message: I18n.t('flag_reason.spam_hosts'))
message = I18n.t('flag_reason.spam_hosts', domain: tl.domain)
PostAction.act(Discourse.system_user, tl.post, PostActionType.types[:spam], message: message)
rescue PostAction::AlreadyActed
# If the user has already acted, just ignore it
end

View File

@ -30,10 +30,11 @@ class SpamRule::FlagSockpuppets
end
def flag_sockpuppet_users
system_user = Discourse.system_user
PostAction.act(system_user, @post, PostActionType.types[:spam], message: I18n.t('flag_reason.sockpuppet')) rescue PostAction::AlreadyActed
message = I18n.t('flag_reason.sockpuppet', ip_address: @post.user.ip_address)
PostAction.act(Discourse.system_user, @post, PostActionType.types[:spam], message: message) rescue PostAction::AlreadyActed
if (first_post = @post.topic.posts.by_post_number.first).try(:user).try(:new_user?)
PostAction.act(system_user, first_post, PostActionType.types[:spam], message: I18n.t('flag_reason.sockpuppet')) rescue PostAction::AlreadyActed
PostAction.act(Discourse.system_user, first_post, PostActionType.types[:spam], message: message) rescue PostAction::AlreadyActed
end
end

View File

@ -1134,7 +1134,7 @@ en:
tos_url: "If you have a Terms of Service 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_threshold` posts before being considered spam."
white_listed_spam_host_domains: "A list of domains excluded from spam host testing. New users will never be restricted from creating posts with links to these domains."
staff_like_weight: "How much extra weighting factor to give staff likes."
@ -2389,8 +2389,8 @@ en:
missing: "Sorry, we can't find any avatar associated with that email address. Can you try uploading it again?"
flag_reason:
sockpuppet: "A new user created a topic, and another new user at the same IP address replied. See the flag_sockpuppets site setting."
spam_hosts: "This new user tried to create multiple posts with links to the same domain. See the newuser_spam_host_threshold site setting."
sockpuppet: "A new user created a topic, and another new user at the same IP address (%{ip_address}) replied. See the <a href='/admin/site_settings/category/spam'>`flag_sockpuppets`</a> site setting."
spam_hosts: "This new user tried to create multiple posts with links to the same domain (%{domain}). See the <a href='/admin/site_settings/category/spam'>`newuser_spam_host_threshold`</a> site setting."
email_log:
no_user: "Can't find user with id %{user_id}"

View File

@ -283,7 +283,7 @@ module Discourse
SYSTEM_USER_ID ||= -1
def self.system_user
User.find_by(id: SYSTEM_USER_ID)
@system_user ||= User.find_by(id: SYSTEM_USER_ID)
end
def self.store

View File

@ -102,6 +102,7 @@ class PostCreator
setup_post
return true if skip_validations?
if @post.has_host_spam?
@spam = true
errors[:base] << I18n.t(:spamming_host)