2015-10-07 15:46:18 -04:00
|
|
|
namespace :gitlab do
|
|
|
|
namespace :two_factor do
|
|
|
|
desc "GitLab | Disable Two-factor authentication (2FA) for all users"
|
|
|
|
task disable_for_all_users: :environment do
|
2015-10-08 23:19:56 -04:00
|
|
|
scope = User.with_two_factor
|
|
|
|
count = scope.count
|
|
|
|
|
|
|
|
if count > 0
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "This will disable 2FA for #{count.to_s.color(:red)} users..."
|
2015-10-08 23:19:56 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
ask_to_continue
|
|
|
|
scope.find_each(&:disable_two_factor!)
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Successfully disabled 2FA for #{count} users.".color(:green)
|
2015-10-08 23:19:56 -04:00
|
|
|
rescue Gitlab::TaskAbortedByUserError
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "Quitting...".color(:red)
|
2015-10-08 23:19:56 -04:00
|
|
|
end
|
|
|
|
else
|
2016-06-01 18:37:15 -04:00
|
|
|
puts "There are currently no users with 2FA enabled.".color(:yellow)
|
2015-10-07 15:46:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|