debian-mirror-gitlab/app/workers/personal_access_tokens/expiring_worker.rb

26 lines
880 B
Ruby
Raw Normal View History

2020-01-01 13:55:28 +05:30
# frozen_string_literal: true
module PersonalAccessTokens
2020-04-08 14:13:33 +05:30
class ExpiringWorker # rubocop:disable Scalability/IdempotentWorker
2020-01-01 13:55:28 +05:30
include ApplicationWorker
include CronjobQueue
feature_category :authentication_and_authorization
def perform(*args)
notification_service = NotificationService.new
limit_date = PersonalAccessToken::DAYS_TO_EXPIRE.days.from_now.to_date
User.with_expiring_and_not_notified_personal_access_tokens(limit_date).find_each do |user|
2020-03-13 15:44:24 +05:30
with_context(user: user) do
notification_service.access_token_about_to_expire(user)
2020-01-01 13:55:28 +05:30
2020-06-23 00:09:42 +05:30
Gitlab::AppLogger.info "#{self.class}: Notifying User #{user.id} about expiring tokens"
2020-01-01 13:55:28 +05:30
2020-06-23 00:09:42 +05:30
user.personal_access_tokens.without_impersonation.expiring_and_not_notified(limit_date).update_all(expire_notification_delivered: true)
2020-03-13 15:44:24 +05:30
end
2020-01-01 13:55:28 +05:30
end
end
end
end