2013-08-27 04:15:59 +08:00
|
|
|
require_dependency 'admin_user_index_query'
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class PendingUsersReminder < Jobs::Scheduled
|
2015-11-21 05:05:57 +08:00
|
|
|
every 1.hour
|
2013-08-27 04:15:59 +08:00
|
|
|
|
|
|
|
def execute(args)
|
2015-11-21 05:05:57 +08:00
|
|
|
if SiteSetting.must_approve_users && SiteSetting.pending_users_reminder_delay >= 0
|
2017-07-28 09:20:09 +08:00
|
|
|
query = AdminUserIndexQuery.new(query: 'pending', stats: false).find_users_query # default order is: users.created_at DESC
|
2015-11-21 05:05:57 +08:00
|
|
|
if SiteSetting.pending_users_reminder_delay > 0
|
|
|
|
query = query.where('users.created_at < ?', SiteSetting.pending_users_reminder_delay.hours.ago)
|
|
|
|
end
|
|
|
|
|
2017-08-01 06:27:29 +08:00
|
|
|
newest_username = query.limit(1).select(:username).first&.username
|
2015-11-21 04:32:08 +08:00
|
|
|
|
|
|
|
return true if newest_username == previous_newest_username # already notified
|
|
|
|
|
|
|
|
count = query.count
|
|
|
|
|
2013-08-27 04:15:59 +08:00
|
|
|
if count > 0
|
2017-10-23 12:30:28 +08:00
|
|
|
target_usernames = Group[:moderators].users.map do |user|
|
|
|
|
next if user.id < 0
|
|
|
|
|
|
|
|
count = user.notifications.joins(:topic)
|
|
|
|
.where("notifications.id > ?", user.seen_notification_id)
|
2017-07-28 09:20:09 +08:00
|
|
|
.where("notifications.read = false")
|
2017-10-23 12:30:28 +08:00
|
|
|
.where("topics.subtype = ?", TopicSubtype.pending_users_reminder)
|
|
|
|
.count
|
|
|
|
|
|
|
|
count == 0 ? user.username : nil
|
2014-07-17 05:53:44 +08:00
|
|
|
end.compact
|
|
|
|
|
|
|
|
unless target_usernames.empty?
|
|
|
|
PostCreator.create(
|
|
|
|
Discourse.system_user,
|
|
|
|
target_usernames: target_usernames,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.pending_users_reminder,
|
2017-07-28 09:20:09 +08:00
|
|
|
title: I18n.t("system_messages.pending_users_reminder.subject_template", count: count),
|
|
|
|
raw: I18n.t("system_messages.pending_users_reminder.text_body_template", count: count, base_url: Discourse.base_url)
|
2014-07-17 05:53:44 +08:00
|
|
|
)
|
2015-11-21 04:32:08 +08:00
|
|
|
|
|
|
|
self.previous_newest_username = newest_username
|
2014-07-17 05:53:44 +08:00
|
|
|
end
|
2013-08-27 04:15:59 +08:00
|
|
|
end
|
|
|
|
end
|
2015-11-21 04:32:08 +08:00
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_newest_username
|
|
|
|
$redis.get previous_newest_username_cache_key
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_newest_username=(username)
|
|
|
|
$redis.setex previous_newest_username_cache_key, 7.days, username
|
|
|
|
end
|
|
|
|
|
|
|
|
def previous_newest_username_cache_key
|
|
|
|
"pending-users-reminder:newest-username".freeze
|
2013-08-27 04:15:59 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|