diff options
author | James Lopez <james@gitlab.com> | 2017-03-21 13:36:46 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-03-21 13:36:46 +0000 |
commit | b356ce7e12e8ffbf19754908ffad2660aec9a07c (patch) | |
tree | 08583cf41c66c52be9ac42cf3adcb66a09f6a888 /lib/tasks/tokens.rake | |
parent | 4ebc62391dea489935af80291363d76e67a64336 (diff) | |
download | gitlab-ce-b356ce7e12e8ffbf19754908ffad2660aec9a07c.tar.gz |
Add a rake task to reset all email and private tokens
Diffstat (limited to 'lib/tasks/tokens.rake')
-rw-r--r-- | lib/tasks/tokens.rake | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/tasks/tokens.rake b/lib/tasks/tokens.rake new file mode 100644 index 00000000000..95735f43802 --- /dev/null +++ b/lib/tasks/tokens.rake @@ -0,0 +1,38 @@ +require_relative '../../app/models/concerns/token_authenticatable.rb' + +namespace :tokens do + desc "Reset all GitLab user auth tokens" + task reset_all_auth: :environment do + reset_all_users_token(:reset_authentication_token!) + end + + desc "Reset all GitLab email tokens" + task reset_all_email: :environment do + reset_all_users_token(:reset_incoming_email_token!) + end + + def reset_all_users_token(reset_token_method) + TmpUser.find_in_batches do |batch| + puts "Processing batch starting with user ID: #{batch.first.id}" + STDOUT.flush + + batch.each(&reset_token_method) + end + end +end + +class TmpUser < ActiveRecord::Base + include TokenAuthenticatable + + self.table_name = 'users' + + def reset_authentication_token! + write_new_token(:authentication_token) + save!(validate: false) + end + + def reset_incoming_email_token! + write_new_token(:incoming_email_token) + save!(validate: false) + end +end |