2021-02-05 07:09:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-04-20 17:09:07 -04:00
|
|
|
require_relative '../../app/models/concerns/token_authenticatable'
|
|
|
|
require_relative '../../app/models/concerns/token_authenticatable_strategies/base'
|
|
|
|
require_relative '../../app/models/concerns/token_authenticatable_strategies/insecure'
|
|
|
|
require_relative '../../app/models/concerns/token_authenticatable_strategies/digest'
|
2017-03-21 09:36:46 -04:00
|
|
|
|
|
|
|
namespace :tokens do
|
2017-10-12 04:58:55 -04:00
|
|
|
desc "Reset all GitLab incoming email tokens"
|
2017-03-21 09:36:46 -04:00
|
|
|
task reset_all_email: :environment do
|
|
|
|
reset_all_users_token(:reset_incoming_email_token!)
|
|
|
|
end
|
|
|
|
|
2018-05-31 10:01:04 -04:00
|
|
|
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
|
|
|
|
|
2017-03-21 09:36:46 -04:00
|
|
|
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
|
|
|
|
|
2019-03-29 07:23:05 -04:00
|
|
|
class TmpUser < ActiveRecord::Base # rubocop:disable Rails/ApplicationRecord
|
2017-03-21 09:36:46 -04:00
|
|
|
include TokenAuthenticatable
|
|
|
|
|
|
|
|
self.table_name = 'users'
|
|
|
|
|
2018-10-29 12:06:45 -04:00
|
|
|
add_authentication_token_field :incoming_email_token, token_generator: -> { SecureRandom.hex.to_i(16).to_s(36) }
|
|
|
|
add_authentication_token_field :feed_token
|
2017-03-21 09:36:46 -04:00
|
|
|
end
|