Skip to content

Instantly share code, notes, and snippets.

@paaloeye
Last active August 29, 2015 14:01
Show Gist options
  • Save paaloeye/d6efe6317d53fc85711c to your computer and use it in GitHub Desktop.
Save paaloeye/d6efe6317d53fc85711c to your computer and use it in GitHub Desktop.
Rake task for gitlab
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