mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
task to make a user an admin. Alter migration to make admins users with old role of Admin or Organizer
This commit is contained in:
parent
9ff8becaf6
commit
760bca6ff0
2 changed files with 19 additions and 1 deletions
17
lib/tasks/user.rake
Normal file
17
lib/tasks/user.rake
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace :user do
|
||||
desc "Makes is_admin attribute true for user based on the supplied email address."
|
||||
task :admin, [:email] => :environment do |t, args|
|
||||
|
||||
# Check if an email address was supplied
|
||||
fail 'You need to define the email address of the user you want to make an admin.' unless args.email
|
||||
|
||||
user = User.find_by(email: args.email)
|
||||
# Check if a user is found based on the supplied email address
|
||||
fail "There is no user with email #{args.email}!" unless user
|
||||
|
||||
if user.update_columns(is_admin: true)
|
||||
puts "User with email #{args.email} is now an admin!"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue