2020-01-30 02:38:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class EnqueueSuspectUsers < ::Jobs::Scheduled
|
|
|
|
every 2.hours
|
|
|
|
|
|
|
|
def execute(_args)
|
|
|
|
return unless SiteSetting.approve_suspect_users
|
2020-03-12 04:05:44 +08:00
|
|
|
return if SiteSetting.must_approve_users
|
2020-01-30 02:38:27 +08:00
|
|
|
|
2020-03-10 19:56:42 +08:00
|
|
|
users = User
|
2020-03-14 19:47:53 +08:00
|
|
|
.distinct
|
2020-03-10 19:56:42 +08:00
|
|
|
.activated
|
|
|
|
.human_users
|
2020-03-12 04:05:44 +08:00
|
|
|
.where(approved: false)
|
2020-03-10 19:56:42 +08:00
|
|
|
.joins(:user_profile, :user_stat)
|
2020-03-14 19:47:53 +08:00
|
|
|
.where("users.created_at <= ? AND users.created_at >= ?", 1.day.ago, 6.months.ago)
|
2020-03-10 19:56:42 +08:00
|
|
|
.where("LENGTH(COALESCE(user_profiles.bio_raw, user_profiles.website, '')) > 0")
|
2021-02-20 19:25:32 +08:00
|
|
|
.where("user_stats.posts_read_count <= 1 OR user_stats.topics_entered <= 1 OR user_stats.time_read < ?", 1.minute.to_i)
|
2020-01-30 02:38:27 +08:00
|
|
|
.joins("LEFT OUTER JOIN reviewables r ON r.target_id = users.id AND r.target_type = 'User'")
|
|
|
|
.where('r.id IS NULL')
|
2020-12-23 01:28:07 +08:00
|
|
|
.joins(
|
|
|
|
<<~SQL
|
|
|
|
LEFT OUTER JOIN (
|
|
|
|
SELECT user_id
|
|
|
|
FROM user_custom_fields
|
|
|
|
WHERE user_custom_fields.name = 'import_id'
|
|
|
|
) AS ucf ON ucf.user_id = users.id
|
|
|
|
SQL
|
|
|
|
)
|
|
|
|
.where('ucf.user_id IS NULL')
|
2020-01-30 02:38:27 +08:00
|
|
|
.limit(10)
|
|
|
|
|
|
|
|
users.each do |user|
|
|
|
|
user_profile = user.user_profile
|
|
|
|
|
|
|
|
reviewable = ReviewableUser.needs_review!(
|
|
|
|
target: user,
|
|
|
|
created_by: Discourse.system_user,
|
|
|
|
reviewable_by_moderator: true,
|
|
|
|
payload: {
|
|
|
|
username: user.username,
|
|
|
|
name: user.name,
|
|
|
|
email: user.email,
|
|
|
|
bio: user_profile.bio_raw,
|
|
|
|
website: user_profile.website,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
if reviewable.created_new
|
|
|
|
reviewable.add_score(
|
|
|
|
Discourse.system_user,
|
|
|
|
ReviewableScore.types[:needs_approval],
|
|
|
|
reason: :suspect_user,
|
|
|
|
force_review: true
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|