Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/workers/personal_access_tokens/expired_notification_worker.rb')
-rw-r--r--app/workers/personal_access_tokens/expired_notification_worker.rb18
1 files changed, 15 insertions, 3 deletions
diff --git a/app/workers/personal_access_tokens/expired_notification_worker.rb b/app/workers/personal_access_tokens/expired_notification_worker.rb
index 2d0ea3d3aa4..b119957fa2c 100644
--- a/app/workers/personal_access_tokens/expired_notification_worker.rb
+++ b/app/workers/personal_access_tokens/expired_notification_worker.rb
@@ -10,16 +10,28 @@ module PersonalAccessTokens
feature_category :authentication_and_authorization
+ MAX_TOKENS = 100
+
def perform(*args)
notification_service = NotificationService.new
User.with_personal_access_tokens_expired_today.find_each do |user|
with_context(user: user) do
- Gitlab::AppLogger.info "#{self.class}: Notifying User #{user.id} about an expired token"
+ expiring_user_tokens = user.personal_access_tokens.without_impersonation.expired_today_and_not_notified
+
+ # rubocop: disable CodeReuse/ActiveRecord
+ # We never materialise the token instances. We need the names to mention them in the
+ # email. Later we trigger an update query on the entire relation, not on individual instances.
+ token_names = expiring_user_tokens.limit(MAX_TOKENS).pluck(:name)
+ # rubocop: enable CodeReuse/ActiveRecord
+
+ notification_service.access_token_expired(user, token_names)
- notification_service.access_token_expired(user)
+ Gitlab::AppLogger.info "#{self.class}: Notifying User #{user.id} about expired tokens"
- user.personal_access_tokens.without_impersonation.expired_today_and_not_notified.update_all(after_expiry_notification_delivered: true)
+ expiring_user_tokens.each_batch do |expiring_tokens|
+ expiring_tokens.update_all(after_expiry_notification_delivered: true)
+ end
end
end
end