Last active
August 29, 2015 14:01
-
-
Save paaloeye/d6efe6317d53fc85711c to your computer and use it in GitHub Desktop.
Rake task for gitlab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :'mail.ru' do | |
namespace :user do | |
# | |
# Usage: | |
# $rake mail.ru:user:disable USERNAME=p.chechetin or $rake mail.ru:user:disable [email protected] | |
# | |
# Exit code: | |
# 0 => Success | |
# 1 => Failure | |
# | |
desc "Disable user by USERNAME or EMAIL" | |
task :disable => :environment do | |
abort 'Either USERNAME or EMAIL are required' if !ENV['USERNAME'] and !ENV['EMAIL'] | |
user = if ENV['USERNAME'] | |
User.find_by_username(ENV['USERNAME']) | |
else | |
User.find_by_email(ENV['EMAIL']) | |
end | |
abort "User with given username or email hasn't been found" unless user | |
abort "User is already blocked" if user.blocked? | |
if user.block | |
puts "User has been successfully blocked." | |
else | |
abort "User hasn't been blocked due to error" | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment