discourse/app/jobs/scheduled/invalidate_inactive_admins.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

32 lines
828 B
Ruby

# frozen_string_literal: true
module Jobs
class InvalidateInactiveAdmins < Jobs::Scheduled
every 1.day
def execute(_)
return if SiteSetting.invalidate_inactive_admin_email_after_days == 0
User.human_users
.where(admin: true)
.where(active: true)
.where('last_seen_at < ?', SiteSetting.invalidate_inactive_admin_email_after_days.days.ago)
.each do |user|
User.transaction do
user.deactivate(Discourse.system_user)
user.email_tokens.update_all(confirmed: false, expired: true)
Discourse.authenticators.each do |authenticator|
if authenticator.can_revoke? && authenticator.description_for_user(user).present?
authenticator.revoke(user)
end
end
end
end
end
end
end