I have found it is an issue with needing to save the role before the
permissions are added. I created a new rake file for the bootstrap to
fix
this, but have not yet submitted it.
Below you will find new code for only the :create_roles task
plugins/user_engine/tasks/user_engine.rake
desc ‘Create the default roles’
task :create_roles => :environment do
Create the Guest Role
if Role.find_by_name(UserEngine.config(:guest_role_name)) == nil
puts “Creating guest role ‘#{UserEngine.config(:guest_role_name)}’”
guest = Role.new
guest.name = UserEngine.config(:guest_role_name)
guest.description = “Implicit role for all accessors of the site”
guest.system_role = true
guest.omnipotent = false
guest.save
guest.permissions <<
Permission.find_by_controller_and_action(‘user’,
‘login’)
guest.permissions <<
Permission.find_by_controller_and_action(‘user’,
‘forgot_password’)
guest.permissions <<
Permission.find_by_controller_and_action(‘user’,
‘signup’)
end
@all_action_permissions = Permission.find_all
Create the Admin role
if Role.find_by_name(UserEngine.config(:admin_role_name)) == nil
puts “Creating admin role ‘#{UserEngine.config(:admin_role_name)}’”
admin = Role.new
admin.name = UserEngine.config(:admin_role_name)
admin.description = “The system administrator, with REAL ULTIMATE
POWER.”
admin.omnipotent = true
admin.system_role = true
admin.save
@all_action_permissions.each { |permission|
if !admin.permissions.include?(permission)
admin.permissions << permission
end
}
end
Create the User role, if needed
if Role.find_by_name(UserEngine.config(:user_role_name)) == nil
puts “Creating user role ‘#{UserEngine.config(:user_role_name)}’”
user = Role.new
user.name = UserEngine.config(:user_role_name)
user.description = “The default role for all logged-in users”
user.system_role = true
user.omnipotent = false
user.save
# all users automatically get the Guest permissions implicitly
user.permissions << Permission.find_by_controller_and_action('user',
‘logout’)
user.permissions << Permission.find_by_controller_and_action(‘user’,
‘home’)
user.permissions << Permission.find_by_controller_and_action(‘user’,
‘change_password’)
user.permissions << Permission.find_by_controller_and_action(‘user’,
‘edit’)
end
End
-Nb
Nathaniel S. H. Brown http://nshb.net