Allows to manage access rights based on roles hierarchy.
- create your roles and permissions
- group roles into parent - children relations
- manage access to a CMS page
- use Twig helpers to allow or restrict access in views
- RainLab.User plugin is no longer required because now it's possible to use Lovata.Buddies as front-end auth system
- This may cause issue if you install User or Buddies plugin after Roles is installed. In that case just reinstall the Roles.
First, create some roles and/or permissions in Users > Roles Hierarchy.
Optionaly to use the power of roles hierarchy create roles system by assigning parent - child relations between them. Then you can create some permissions and assign them to roles depending on hierarchy
After at least one role is created you can choose it in CMS Page settings to allow access only for users of that role or it's parents. Another option is to manage Page access by choosing permission. Or check "Only anonymous" checkbox to restrict access for any logged user.
If you got both RainLab.User and Lovata.Buddies installed you can choose in settings which to use with this plugin.
You can use twig helpers or PHP static functions to allow or restrict access.
Twig: isRole(role_code, user = null)
PHP: Helper::isRole(role_code, user = null)
Checks if current user has specific role or a role with higher privileges (roles ancestors). Example: if user is got admin role: isRole('admin') and isRole('superadmin') will return true.
Twig: able(permission_code, user = null)
PHP: Helper::able(permission_code, user = null)
Checks if current user's role has right to execute a permission. Permission should be assigned to the user's role or to a role with lower privileges (roles successors).
Pass user object as second parameter to check it rather then authenticated user.