2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-26 01:25:02 +08:00
|
|
|
class SpamRule::FlagSockpuppets
|
|
|
|
def initialize(post)
|
|
|
|
@post = post
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2019-02-08 02:46:05 +08:00
|
|
|
I18n.with_locale(SiteSetting.default_locale) do
|
|
|
|
if SiteSetting.flag_sockpuppets && reply_is_from_sockpuppet?
|
|
|
|
flag_sockpuppet_users
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
2013-10-26 01:25:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_is_from_sockpuppet?
|
2015-02-06 02:58:49 +08:00
|
|
|
return false if @post.try(:post_number) == 1
|
2013-10-26 01:25:02 +08:00
|
|
|
return false if first_post.user.nil?
|
|
|
|
|
2016-01-19 07:57:55 +08:00
|
|
|
!first_post.user.staff? && !@post.user.staff? && !first_post.user.staged? &&
|
2015-02-06 02:58:49 +08:00
|
|
|
!@post.user.staged? && @post.user != first_post.user &&
|
|
|
|
@post.user.ip_address == first_post.user.ip_address && @post.user.new_user? &&
|
2020-07-27 08:23:54 +08:00
|
|
|
!ScreenedIpAddress.is_allowed?(@post.user.ip_address)
|
2013-10-26 01:25:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def flag_sockpuppet_users
|
2019-07-12 18:04:16 +08:00
|
|
|
message =
|
|
|
|
I18n.t(
|
|
|
|
"flag_reason.sockpuppet",
|
|
|
|
ip_address: @post.user.ip_address,
|
|
|
|
base_path: Discourse.base_path,
|
|
|
|
locale: SiteSetting.default_locale,
|
|
|
|
)
|
2019-01-04 01:03:01 +08:00
|
|
|
|
2020-04-01 20:20:45 +08:00
|
|
|
flag_post(@post, message)
|
2016-04-26 05:03:17 +08:00
|
|
|
|
2020-04-01 20:20:45 +08:00
|
|
|
flag_post(first_post, message) if first_post&.user&.new_user?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def flag_post(post, message)
|
2021-12-09 01:12:24 +08:00
|
|
|
return if ReviewableFlaggedPost.rejected.exists?(target_created_by: post.user)
|
2020-04-01 20:20:45 +08:00
|
|
|
|
|
|
|
PostActionCreator.create(Discourse.system_user, post, :spam, message: message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_post
|
|
|
|
@first_post ||= @post.topic.posts.by_post_number.first
|
2013-10-26 01:25:02 +08:00
|
|
|
end
|
2015-02-06 02:58:49 +08:00
|
|
|
end
|