2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-12 15:32:14 -05:00
|
|
|
module Jobs
|
|
|
|
|
2019-10-02 00:01:53 -04:00
|
|
|
class InvalidateInactiveAdmins < ::Jobs::Scheduled
|
2018-12-12 15:32:14 -05:00
|
|
|
every 1.day
|
|
|
|
|
|
|
|
def execute(_)
|
|
|
|
return if SiteSetting.invalidate_inactive_admin_email_after_days == 0
|
|
|
|
|
2019-11-12 11:56:01 -05:00
|
|
|
timestamp = SiteSetting.invalidate_inactive_admin_email_after_days.days.ago
|
|
|
|
|
2018-12-12 15:32:14 -05:00
|
|
|
User.human_users
|
|
|
|
.where(admin: true)
|
2018-12-12 22:59:56 -05:00
|
|
|
.where(active: true)
|
2019-11-12 11:56:01 -05:00
|
|
|
.where('last_seen_at < ?', timestamp)
|
|
|
|
.where("NOT EXISTS ( SELECT 1 from api_keys WHERE api_keys.user_id = users.id AND COALESCE(last_used_at, updated_at) > ? )", timestamp)
|
|
|
|
.where("NOT EXISTS ( SELECT 1 from posts WHERE posts.user_id = users.id AND created_at > ?)", timestamp)
|
2018-12-12 15:32:14 -05:00
|
|
|
.each do |user|
|
|
|
|
|
2018-12-12 22:59:56 -05:00
|
|
|
User.transaction do
|
2019-04-03 12:04:05 -04:00
|
|
|
user.deactivate(Discourse.system_user)
|
2018-12-12 22:59:56 -05:00
|
|
|
user.email_tokens.update_all(confirmed: false, expired: true)
|
2018-12-12 15:32:14 -05:00
|
|
|
|
2020-01-28 07:16:24 -05:00
|
|
|
reason = I18n.t("user.deactivated_by_inactivity", count: SiteSetting.invalidate_inactive_admin_email_after_days)
|
|
|
|
StaffActionLogger.new(Discourse.system_user).log_user_deactivate(user, reason)
|
|
|
|
|
2018-12-12 22:59:56 -05:00
|
|
|
Discourse.authenticators.each do |authenticator|
|
|
|
|
if authenticator.can_revoke? && authenticator.description_for_user(user).present?
|
|
|
|
authenticator.revoke(user)
|
|
|
|
end
|
2018-12-12 15:32:14 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|