BigW Consortium Gitlab

tokens.rake 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
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

14
  desc "Reset all GitLab RSS tokens"
15 16 17 18
  task reset_all_rss: :environment do
    reset_all_users_token(:reset_rss_token!)
  end

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
  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
43 44 45 46 47

  def reset_rss_token!
    write_new_token(:rss_token)
    save!(validate: false)
  end
48
end