Merge pull request #495 from differentreality/is_admin
Task to create admins and fix in migration
This commit is contained in:
commit
e230105f2e
2 changed files with 19 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ class MigrateRolesForCancancan < ActiveRecord::Migration
|
||||||
Conference.all.each do |conference|
|
Conference.all.each do |conference|
|
||||||
if role.name == 'Admin' || role.name == 'Organizer'
|
if role.name == 'Admin' || role.name == 'Organizer'
|
||||||
user.add_role :organizer, conference
|
user.add_role :organizer, conference
|
||||||
|
user.update_columns(is_admin: true)
|
||||||
else
|
else
|
||||||
user.add_role role.name.parameterize.underscore.to_sym, conference
|
user.add_role role.name.parameterize.underscore.to_sym, conference
|
||||||
end
|
end
|
||||||
|
|
@ -22,6 +23,6 @@ class MigrateRolesForCancancan < ActiveRecord::Migration
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
raise ActiveRecord::IrreversibleMigration.new('Cannot reverse migration. Deleted events cannot be re-created')
|
raise ActiveRecord::IrreversibleMigration.new('Cannot reverse migration.')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
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