Multiple roles per user

henning-koch edited this page Sep 13, 2010 · 4 revisions

Aegis allows multiple roles per user. Permission is granted to a user when at least one role is allowed access, even if other roles are not.

You can give a user multiple roles by separating the role names with a comma:

user.role_name = 'author,editor'

Alternatively you can use the setter and getter for role_names (plural), which take and return an array instead of a string:

user.role_names = ['author', 'editor']
puts user.role_name # prints 'author,editor'

Parametrized roles

Aegis does not currently support parametrized roles like “leader for project #2” and “author of post #7”. We might add this in the future.

You can sort of emulate parametrized roles by testing vanilla Rails associations in your allow directives:

resources :projects do
  allow :user do
    user.projects.include?(object) if object