2017-08-17 22:00:37 +05:30
|
|
|
require_relative '../../app/models/concerns/token_authenticatable.rb'
|
|
|
|
|
|
|
|
namespace :tokens do
|
2018-03-17 18:26:18 +05:30
|
|
|
desc "Reset all GitLab incoming email tokens"
|
2017-08-17 22:00:37 +05:30
|
|
|
task reset_all_email: :environment do
|
|
|
|
reset_all_users_token(:reset_incoming_email_token!)
|
|
|
|
end
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
desc "Reset all GitLab RSS tokens"
|
|
|
|
task reset_all_rss: :environment do
|
|
|
|
reset_all_users_token(:reset_rss_token!)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
|
|
|
|
def reset_rss_token!
|
|
|
|
write_new_token(:rss_token)
|
|
|
|
save!(validate: false)
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|