2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-10-25 12:25:02 -05:00
|
|
|
class SpamRule::FlagSockpuppets
|
|
|
|
|
|
|
|
def initialize(post)
|
|
|
|
@post = post
|
|
|
|
end
|
|
|
|
|
|
|
|
def perform
|
2019-02-07 12:46:05 -06: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-25 12:25:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def reply_is_from_sockpuppet?
|
2015-02-05 12:58:49 -06:00
|
|
|
return false if @post.try(:post_number) == 1
|
2013-10-25 12:25:02 -05:00
|
|
|
|
|
|
|
first_post = @post.topic.posts.by_post_number.first
|
|
|
|
return false if first_post.user.nil?
|
|
|
|
|
2015-02-05 12:58:49 -06:00
|
|
|
!first_post.user.staff? &&
|
|
|
|
!@post.user.staff? &&
|
2016-01-18 17:57:55 -06:00
|
|
|
!first_post.user.staged? &&
|
|
|
|
!@post.user.staged? &&
|
2015-02-05 12:58:49 -06: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-25 12:25:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def flag_sockpuppet_users
|
2019-07-12 05:04:16 -05:00
|
|
|
message = I18n.t(
|
|
|
|
'flag_reason.sockpuppet',
|
|
|
|
ip_address: @post.user.ip_address,
|
|
|
|
base_path: Discourse.base_path,
|
|
|
|
locale: SiteSetting.default_locale
|
|
|
|
)
|
2019-01-03 11:03:01 -06:00
|
|
|
|
|
|
|
PostActionCreator.create(Discourse.system_user, @post, :spam, message: message)
|
2016-04-25 16:03:17 -05:00
|
|
|
|
2013-10-25 12:25:02 -05:00
|
|
|
if (first_post = @post.topic.posts.by_post_number.first).try(:user).try(:new_user?)
|
2019-01-03 11:03:01 -06:00
|
|
|
PostActionCreator.create(Discourse.system_user, first_post, :spam, message: message)
|
2013-10-25 12:25:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-05 12:58:49 -06:00
|
|
|
end
|