gitlab-org--gitlab-foss/lib/tasks/tokens.rake

39 lines
909 B
Ruby
Raw Normal View History

require_relative '../../app/models/concerns/token_authenticatable.rb'
namespace :tokens do
2017-10-12 04:58:55 -04:00
desc "Reset all GitLab incoming email tokens"
task reset_all_email: :environment do
reset_all_users_token(:reset_incoming_email_token!)
end
desc "Reset all GitLab feed tokens"
task reset_all_feed: :environment do
reset_all_users_token(:reset_feed_token!)
2017-05-23 08:09:45 -04:00
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_incoming_email_token!
write_new_token(:incoming_email_token)
save!(validate: false)
end
2017-05-23 08:09:45 -04:00
def reset_feed_token!
write_new_token(:feed_token)
2017-05-23 08:09:45 -04:00
save!(validate: false)
end
end