2019-10-08 16:54:23 +02:00
|
|
|
require Rails.root.join("lib", "tasks", "task_helper")
|
|
|
|
|
2018-12-21 15:19:24 +01:00
|
|
|
namespace :superadmin do
|
2018-12-21 15:20:34 +01:00
|
|
|
desc <<~EOD
|
|
|
|
List all super-admins
|
|
|
|
EOD
|
|
|
|
task list: :environment do
|
2020-11-05 18:56:03 +01:00
|
|
|
rake_puts "All SuperAdmins:"
|
2024-02-05 11:35:01 +01:00
|
|
|
SuperAdmin.pluck(:email).each do |a|
|
2018-12-21 15:20:34 +01:00
|
|
|
puts a
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc <<~EOD
|
|
|
|
Create a new super-admin account with the #EMAIL email address.
|
|
|
|
EOD
|
2018-12-21 15:19:24 +01:00
|
|
|
task :create, [:email] => :environment do |_t, args|
|
2017-12-20 17:00:17 +01:00
|
|
|
email = args[:email]
|
2018-12-21 15:20:34 +01:00
|
|
|
|
2020-11-05 18:56:03 +01:00
|
|
|
rake_puts "Creating SuperAdmin for #{email}"
|
2022-11-24 12:22:01 +01:00
|
|
|
password = Devise.friendly_token
|
|
|
|
a = SuperAdmin.new(email:, password:)
|
2018-12-21 15:20:34 +01:00
|
|
|
|
2017-12-20 17:00:17 +01:00
|
|
|
if a.save
|
2019-10-08 16:54:23 +02:00
|
|
|
rake_puts "#{a.email} created"
|
2020-11-03 23:04:01 +01:00
|
|
|
a.send_reset_password_instructions
|
|
|
|
rake_puts "Password reset instructions sent to #{a.email}"
|
2022-11-24 12:22:01 +01:00
|
|
|
|
|
|
|
user = User.create_or_promote_to_administrateur(email, password)
|
|
|
|
|
|
|
|
user.update!(team_account: true)
|
2017-12-20 17:00:17 +01:00
|
|
|
else
|
2019-10-08 16:54:23 +02:00
|
|
|
rake_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-21 15:19:24 +01:00
|
|
|
task :delete, [:email] => :environment do |_t, args|
|
2018-01-03 11:45:19 +01:00
|
|
|
email = args[:email]
|
2020-11-05 18:56:03 +01:00
|
|
|
rake_puts "Deleting SuperAdmin for #{email}"
|
|
|
|
a = SuperAdmin.find_by(email: email)
|
2018-01-03 11:45:19 +01:00
|
|
|
a.destroy
|
2019-10-08 16:54:23 +02:00
|
|
|
rake_puts "#{a.email} deleted"
|
2018-01-03 11:45:19 +01:00
|
|
|
end
|
2017-12-20 17:00:17 +01:00
|
|
|
end
|