Hello,
Nice library and is good that CL Auth has a successor.
I prefer that the tables follows the DataMapper model cos will help me to code faster the control panel.
As for the “check_role_uri” the only problem of mine is that it checks the table each time is accessed. Maybe caching the results is consuming too much memory.
Like other users here I’ve tried to develop a similar library but you were so good and fast that I abandoned the idea. The only thing I propose is to develop add-ins for this library.
The library can contain in a way or another groups and roles. The add-ins can offer functions to treat those groups and/or roles.
As ex. I’m trying to implement an approach to RBAC library in manner closer to CI, but with flexibility for other ideas. Using DX Auth as a authentication library we can develop different styles of authorization: unique group, multiple groups, unique role, multiple roles, combination of previous, etc (have any other ideas?).
What I want to make is a more flexible way to set the “role_uri” keeping all the structure in the database (I need to keep there another record of the level of the user: owner, manager, supervisor - can see or change data accordingly). That renders a very easy to use control panel but a lot of pain in getting the rules for the roles in the case I’ll try to describe below.
I wrote here to have some “consultancy” on making multiple roles for one users and role inheritance.
As ex a user could have 2 roles (or more) and at least one of the roles inherits from another (or maybe from the one the user has already). Some restrictions could be set when we are allocating the roles (the user can have only one role from the main and inherited list). Also, for some roles (with no relation between them) we can have different levels of access.
Yes, I know, complicated.
Paul
PS: i don’t like “is_admin” cos what I want to try is that when rule is not set will inherit the right from the superior one (like in “role_uri”) and for the role “Admin” I can set only a simple rule “/”. The access to the page could be managed by the authentication.
EDIT: Maybe we can consider no inheritance between roles and add a feature to clone a certain role in CP?
Thanks you for reply,
Unfortunately, i cannot change the database table design to follow datamapper since it’s
very different (need exclusive table for foreign key, but of course you can port it). As for ORM, you may want to see Ignited record, it’s also very good, and the author is very great at support. You can use Ignited record right away with DX Auth library.
In next release (which i already finished it, only the documentation haven’t)
I’m sorry to telling you this right now,
role_uri will be not supported by next version.
Instead, it changed into permissions table, so it’s more powerful, you can add your custom permission there, and of course ‘uri permission’ checking function is built in. So basically it’s the same with role_uri table, but it’s just not restricted to URI anymore.
And also, role will have inheritance feature.
User can only have one role, but you can also check parent role permissions.
Then, to check permission you can use (next version)
/*
Get permission value from specified key.
Call this function only when user is logged in already.
$key is permission array key (Note: permissions is saved as array in table).
if $check_parent is TRUE then it will check role_id parent if permission is not found in current logged in role_id
Returning value if permission found, otherwise returning NULL
*/
function get_permission($key, $check_parent = TRUE)
// Get permission
$allow_edit = $this->dx_auth->get_permission('edit');
// This will check if current logged in user have permission edit or not
if ($allow_edit ! = NULL)
// Is allowed ?
if ($allow_edit)
{
// do edit
}
}
Alternative function, if you want to get all permissions.
/*
Get permission value from specified key.
Call this function only when user is logged in already.
This will get current logged in user role_id, and it's parents permissions.
Function returning an array.
$array_key = 'default'. Array ordered using 0, 1, 2, etc as array key.
$array_key = 'role_id'. Array ordered using role_id as array key.
$array_key = 'role_name'. Array ordered using role_name as array key.
*/
function get_permissions($key, $array_key = 'default')
is_admin() function will be preserved as now you see we are using completely different permissions table.
New function to check URI permissions is
using $this->dx_auth->check_uri_permissions()
This will have same effect with check_role_uri() function, but it’s used for new permissions table.
And this time, the result is cached.