2013-10-26 01:25:02 +08:00
|
|
|
class SpamRule::FlagSockpuppets
|
|
|
|
|
|
|
|
def initialize(post)
|
|
|
|
@post = post
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2015-02-06 02:58:49 +08:00
|
|
|
if SiteSetting.flag_sockpuppets && reply_is_from_sockpuppet?
|
2013-10-26 01:25:02 +08:00
|
|
|
flag_sockpuppet_users
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
|
|
|
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
|
|
|
|
|
|
|
first_post = @post.topic.posts.by_post_number.first
|
|
|
|
return false if first_post.user.nil?
|
|
|
|
|
2015-02-06 02:58:49 +08:00
|
|
|
!first_post.user.staff? &&
|
|
|
|
!@post.user.staff? &&
|
2016-01-19 07:57:55 +08:00
|
|
|
!first_post.user.staged? &&
|
|
|
|
!@post.user.staged? &&
|
2015-02-06 02:58:49 +08:00
|
|
|
@post.user != first_post.user &&
|
|
|
|
@post.user.ip_address == first_post.user.ip_address &&
|
|
|
|
@post.user.new_user? &&
|
|
|
|
!ScreenedIpAddress.is_whitelisted?(@post.user.ip_address)
|
2013-10-26 01:25:02 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def flag_sockpuppet_users
|
2016-04-26 05:03:17 +08:00
|
|
|
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
|
|
|
|
|
2013-10-26 01:25:02 +08:00
|
|
|
if (first_post = @post.topic.posts.by_post_number.first).try(:user).try(:new_user?)
|
2016-04-26 05:03:17 +08:00
|
|
|
PostAction.act(Discourse.system_user, first_post, PostActionType.types[:spam], message: message) rescue PostAction::AlreadyActed
|
2013-10-26 01:25:02 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-06 02:58:49 +08:00
|
|
|
end
|