BigW Consortium Gitlab

two_factor.rake 709 Bytes
Newer Older
1 2 3 4
namespace :gitlab do
  namespace :two_factor do
    desc "GitLab | Disable Two-factor authentication (2FA) for all users"
    task disable_for_all_users: :environment do
5 6 7 8
      scope = User.with_two_factor
      count = scope.count

      if count > 0
9
        puts "This will disable 2FA for #{count.to_s.color(:red)} users..."
10 11 12 13

        begin
          ask_to_continue
          scope.find_each(&:disable_two_factor!)
14
          puts "Successfully disabled 2FA for #{count} users.".color(:green)
15
        rescue Gitlab::TaskAbortedByUserError
16
          puts "Quitting...".color(:red)
17 18
        end
      else
19
        puts "There are currently no users with 2FA enabled.".color(:yellow)
20 21 22 23
      end
    end
  end
end