mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
slightly better automatic flag reason messages
This commit is contained in:
@ -229,7 +229,6 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def whitelisted_spam_hosts
|
def whitelisted_spam_hosts
|
||||||
|
|
||||||
hosts = SiteSetting
|
hosts = SiteSetting
|
||||||
.white_listed_spam_host_domains
|
.white_listed_spam_host_domains
|
||||||
.split('|')
|
.split('|')
|
||||||
@ -255,7 +254,8 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
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)
|
||||||
.count.each_key do |tuple|
|
.count
|
||||||
|
.each_key do |tuple|
|
||||||
domain = tuple[0]
|
domain = tuple[0]
|
||||||
hosts[domain] = (hosts[domain] || 0) + 1
|
hosts[domain] = (hosts[domain] || 0) + 1
|
||||||
end
|
end
|
||||||
@ -265,13 +265,9 @@ class Post < ActiveRecord::Base
|
|||||||
|
|
||||||
# Prevent new users from posting the same hosts too many times.
|
# Prevent new users from posting the same hosts too many times.
|
||||||
def has_host_spam?
|
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|
|
total_hosts_usage.values.any? { |count| count >= SiteSetting.newuser_spam_host_threshold }
|
||||||
return true if count >= SiteSetting.newuser_spam_host_threshold
|
|
||||||
end
|
|
||||||
|
|
||||||
false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def archetype
|
def archetype
|
||||||
|
@ -702,12 +702,16 @@ class User < ActiveRecord::Base
|
|||||||
|
|
||||||
# Flag all posts from a user as spam
|
# Flag all posts from a user as spam
|
||||||
def flag_linked_posts_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)
|
||||||
topic_links.includes(:post).where.not(post_id: disagreed_flag_post_ids).each do |tl|
|
.where.not(post_id: disagreed_flag_post_ids)
|
||||||
|
.each do |tl|
|
||||||
begin
|
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
|
rescue PostAction::AlreadyActed
|
||||||
# If the user has already acted, just ignore it
|
# If the user has already acted, just ignore it
|
||||||
end
|
end
|
||||||
|
@ -30,10 +30,11 @@ class SpamRule::FlagSockpuppets
|
|||||||
end
|
end
|
||||||
|
|
||||||
def flag_sockpuppet_users
|
def flag_sockpuppet_users
|
||||||
system_user = Discourse.system_user
|
message = I18n.t('flag_reason.sockpuppet', ip_address: @post.user.ip_address)
|
||||||
PostAction.act(system_user, @post, PostActionType.types[:spam], message: I18n.t('flag_reason.sockpuppet')) rescue PostAction::AlreadyActed
|
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?)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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."
|
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."
|
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."
|
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."
|
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?"
|
missing: "Sorry, we can't find any avatar associated with that email address. Can you try uploading it again?"
|
||||||
|
|
||||||
flag_reason:
|
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."
|
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. See the newuser_spam_host_threshold 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:
|
email_log:
|
||||||
no_user: "Can't find user with id %{user_id}"
|
no_user: "Can't find user with id %{user_id}"
|
||||||
|
@ -283,7 +283,7 @@ module Discourse
|
|||||||
SYSTEM_USER_ID ||= -1
|
SYSTEM_USER_ID ||= -1
|
||||||
|
|
||||||
def self.system_user
|
def self.system_user
|
||||||
User.find_by(id: SYSTEM_USER_ID)
|
@system_user ||= User.find_by(id: SYSTEM_USER_ID)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.store
|
def self.store
|
||||||
|
@ -102,6 +102,7 @@ class PostCreator
|
|||||||
setup_post
|
setup_post
|
||||||
|
|
||||||
return true if skip_validations?
|
return true if skip_validations?
|
||||||
|
|
||||||
if @post.has_host_spam?
|
if @post.has_host_spam?
|
||||||
@spam = true
|
@spam = true
|
||||||
errors[:base] << I18n.t(:spamming_host)
|
errors[:base] << I18n.t(:spamming_host)
|
||||||
|
Reference in New Issue
Block a user