From 324b65b7ad5897af5a8fce3d65d8c4d82c48eae7 Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Fri, 21 Dec 2018 15:20:34 +0100 Subject: [PATCH] Improve the admin tasks --- lib/tasks/admin.rake | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/tasks/admin.rake b/lib/tasks/admin.rake index 01dd504e6..e74c1054f 100644 --- a/lib/tasks/admin.rake +++ b/lib/tasks/admin.rake @@ -1,22 +1,33 @@ namespace :admin do - task :create_admin, [:email] => :environment do |_t, args| - email = args[:email] - puts "Creating Administration for #{email}" - a = Administration.new(email: email, password: Devise.friendly_token[0, 20]) - if a.save - puts "#{a.email} created" - else - puts "An error occured : #{a.errors.full_messages}" - end - end - + desc <<~EOD + List all super-admins + EOD task list: :environment do - puts "All Administrations :" + 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 + task :create_admin, [:email] => :environment do |_t, args| + email = args[:email] + + puts "Creating Administration for #{email}" + a = Administration.new(email: email, password: Devise.friendly_token[0, 20]) + + if a.save + puts "#{a.email} created" + else + puts "An error occured: #{a.errors.full_messages}" + end + end + + desc <<~EOD + Delete the #EMAIL super-admin account + EOD task :delete_admin, [:email] => :environment do |_t, args| email = args[:email] puts "Deleting Administration for #{email}"