highs: 1.8.0 -> 1.8.1 (#360451)
[NixPkgs.git] / pkgs / applications / version-management / gitlab / reset_token.rake
blob705b5830edfc1eb97b55fc78ac1de1b3e9250a57
1 # Taken from:
2 # https://about.gitlab.com/2017/03/20/gitlab-8-dot-17-dot-4-security-release/
4 # lib/tasks/reset_token.rake
5 require_relative '../../app/models/concerns/token_authenticatable.rb'
7 STDOUT.sync = true
9 namespace :tokens do
10   desc "Reset all GitLab user auth tokens"
11   task reset_all: :environment do
12     reset_all_users_token(:reset_authentication_token!)
13   end
15   desc "Reset all GitLab email tokens"
16   task reset_all_email: :environment do
17     reset_all_users_token(:reset_incoming_email_token!)
18   end
20   def reset_all_users_token(token)
21     TmpUser.find_in_batches do |batch|
22       puts "Processing batch starting with user ID: #{batch.first.id}"
24       batch.each(&token)
25     end
26   end
27 end
29 class TmpUser < ActiveRecord::Base
30   include TokenAuthenticatable
32   self.table_name = 'users'
34   def reset_authentication_token!
35     write_new_token(:authentication_token)
36     save!(validate: false)
37   end
39   def reset_incoming_email_token!
40     write_new_token(:incoming_email_token)
41     save!(validate: false)
42   end
43 end