Roles Configuration

kristianmandrup edited this page May 29, 2012 · 3 revisions

Roles and RoleGroups can be configured via the cantango-config DSL.

  • system defines what role system to use.
  • system_apis - map API for use with cantango
  • register - roles to be used by can tango permits
  • exclude - filtered out certain roles

System API

Note that only the :list is required, the :has is optional.

  • :list - method that lists the roles of the subject, fx current_user.all_roles
  • :has - method that returns if the subject has a given role, fx has_role?(:editor)


Support (rolify)[] which supports a scope argument to the has_role? method.

Roles configuration:

CanTango.config do |config|
  config.roles do |roles|
    roles.register :admin, :guest, :basic
    roles.system = :simple_roles
    roles.system_apis = {:list => :role_list, :has => :has_role?}
    roles.exclude :admin # filter

Role groups configuration:

CanTango.config do |config|
  config.roles_groups do |role_groups|
    role_groups.register :editors, :publishers
    role_groups.system = :troles
    role_groups.only :editors # filter

Example: Configuring alternative Role groups system:

CanTango.config do |config|
  config.roles_groups do |role_groups|
    role_groups.system = :simple_role_groups
    role_groups.system_apis = {:list => :role_groups, :has => :role_group?}