2017-12-20 17:00:17 +01:00
|
|
|
namespace :admin do
|
2018-12-21 15:20:34 +01:00
|
|
|
desc <<~EOD
|
|
|
|
List all super-admins
|
|
|
|
EOD
|
|
|
|
task list: :environment do
|
|
|
|
puts "All Administrations:"
|
|
|
|
Administration.all.pluck(:email).each do |a|
|
|
|
|
puts a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc <<~EOD
|
|
|
|
Create a new super-admin account with the #EMAIL email address.
|
|
|
|
EOD
|
2018-12-24 17:53:16 +01:00
|
|
|
task :create_admin, [:email] => :environment do |_t, args|
|
2017-12-20 17:00:17 +01:00
|
|
|
email = args[:email]
|
2018-12-21 15:20:34 +01:00
|
|
|
|
2017-12-20 17:00:17 +01:00
|
|
|
puts "Creating Administration for #{email}"
|
2018-12-24 17:37:57 +01:00
|
|
|
a = Administration.new(email: email, password: Devise.friendly_token[0, 20])
|
2018-12-21 15:20:34 +01:00
|
|
|
|
2017-12-20 17:00:17 +01:00
|
|
|
if a.save
|
|
|
|
puts "#{a.email} created"
|
|
|
|
else
|
2018-12-21 15:20:34 +01:00
|
|
|
puts "An error occured: #{a.errors.full_messages}"
|
2018-01-03 11:45:19 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-21 15:20:34 +01:00
|
|
|
desc <<~EOD
|
|
|
|
Delete the #EMAIL super-admin account
|
|
|
|
EOD
|
2018-12-24 17:53:16 +01:00
|
|
|
task :delete_admin, [:email] => :environment do |_t, args|
|
2018-01-03 11:45:19 +01:00
|
|
|
email = args[:email]
|
|
|
|
puts "Deleting Administration for #{email}"
|
|
|
|
a = Administration.find_by(email: email)
|
|
|
|
a.destroy
|
|
|
|
puts "#{a.email} deleted"
|
|
|
|
end
|
2017-12-20 17:00:17 +01:00
|
|
|
end
|