This plugin allows to manage access rights for front-end users based on roles hierarchy.
RainLab.User and Lovata.Buddies are supported as auth system
- 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
You may like my other plugins
- Vdomah.Octoshop Product Plus - Enreaches Octoshop products with your custom properties, adds filters and sorters to product list and adds product views tracking.
- Vdomah.BlogViews - track blog posts views
- Vdomah.Excel - excel import-export tools
- Vdomah.JWT Auth API - Token Authentication for API integrated with RainLab.User
- RainLab.User plugin
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 (check screenshot).
CMS Pages access
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.
You can use twig helpers or PHP static functions to allow or restrict access.
Check if user got specific role
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.
Check if user got specific permission
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.
Found the plugin useful on 10 Aug, 2016
There is a hardcoded URL to the " /admin" area if the user has a different Backend URL the links will not work. Found in the following files:
~/roles/controllers/roles/index.htm Upon the lines 16, 18, 31 ~/roles/controllers/Roles.php Upon the line 38
Works perfect btw.
Replied on 10 Aug, 2016
Thanks! Added new version with this fix
Check role_id exists in users table and add if no
Sep 20, 2018
role_id field nullable
Sep 19, 2018
Add fillable to Role model
Sep 19, 2018
Check if users table exists in migrations before altering it
Sep 15, 2018
Lovata.Buddies plugin integration
Feb 23, 2018
Logged only CMS page parameter added
Mar 14, 2017
Fixed bug wich prevented returning the whole ancestor tree in a role (thanks Daniel Tamas). En translations updated
Jan 25, 2017
CMS Pages access managment moved to separate tab
Jan 24, 2017
CMS Pages access managment by assigning roles and permissions
Dec 14, 2016
Replaced hardcoded backend urls with dynamic links in controller (thanks to Damian Verhaar)
Aug 21, 2016
Replaced hardcoded backend urls with dynamic links in view (thanks to Damian Verhaar)
Aug 10, 2016
SimpleTree trait implemented, fixed roles dropdown in user form
Aug 08, 2016
Soft implementation of RainLab.Translate
Aug 04, 2016
Permission name transaltable. Readme update. Move static methods to Helper
Aug 04, 2016
Jul 29, 2016