2018-04-04 10:18:51 -07:00
|
|
|
# frozen_string_literal: true
|
2014-09-04 15:53:47 +03:00
|
|
|
|
2018-04-04 10:18:51 -07:00
|
|
|
namespace :user do
|
|
|
|
|
desc 'Makes is_admin attribute true for user based on the supplied email address.'
|
|
|
|
|
task :admin, [:email] => :environment do |_t, args|
|
2014-09-04 15:53:47 +03:00
|
|
|
# Check if an email address was supplied
|
2018-04-04 10:18:51 -07:00
|
|
|
raise 'You need to define the email address of the user you want to make an admin.' unless args.email
|
2014-09-04 15:53:47 +03:00
|
|
|
|
|
|
|
|
user = User.find_by(email: args.email)
|
|
|
|
|
# Check if a user is found based on the supplied email address
|
2018-04-04 10:18:51 -07:00
|
|
|
raise "There is no user with email #{args.email}!" unless user
|
2014-09-04 15:53:47 +03:00
|
|
|
|
2018-04-04 10:18:51 -07:00
|
|
|
puts "User with email #{args.email} is now an admin!" if user.update_columns(is_admin: true)
|
2014-09-04 15:53:47 +03:00
|
|
|
end
|
|
|
|
|
|
2018-04-04 10:18:51 -07:00
|
|
|
desc 'Set email_public attrubute true for all users'
|
|
|
|
|
task set_email_public: :environment do
|
2017-02-15 18:07:44 +03:00
|
|
|
User.update_all email_public: true
|
|
|
|
|
end
|
2014-09-04 15:53:47 +03:00
|
|
|
end
|