roles
roles copied to clipboard
Role Heredity
May there be a feature to make inheritance on roles like:
user |- admin |-superadmin
and giving a role will automaticly assign missing permissions? And even a way to RESTRICT permissions in that kind of model?
My application in the first instance uses a Microsoft Windows © like permission model. I am porting my app to Laravel 5.2 and I am using bican/roles for a strong and nice permission concept.
I want to keep my old kind of permission concept where my views appropriate a keyword
(the permission entry) and check if the group
(or role) has this keyword
(aka permission). And since it is the administrator, who sets up the groups and assignes the permissions, I need a way to decline the assignment of a permission somehow.
If needed I can make a more indeepth post containing more of the project and what I am doing. Maybe ther eis another approach I don't know.
+1
Would be very helpful to be able to do something like this:
$user->isAtLeast('admin'); // Allows 'superadmin' role as well
Edit
I just made this little functionality by adding the following method in the HasRoleAndPermission
trait:
/**
* Check if the User has the given role or one with a higher level.
*
* @param Role|string $role
* @return bool
*/
public function isAtLeast($role)
{
if ($this->isPretendEnabled())
{
return $this->pretend('is');
}
if ( ! is_object($role))
{
if ( ! $this->hasRole($role))
{
$role = Role::where('slug', $role)->firstOrFail();
}
else
{
$role = $this->getRoles()->where('slug', $role)->first();
}
}
return $this->level() >= $role->level;
}
If I understood, you are working with the level
field.
I don't like level
s much. Maybe i will fork it and open a pull request. But I don't have the time now. Maybe this night.