Replies: 2 comments 2 replies
-
You can get it. config('AuthGroups')->matrix['groupName'] See also #734. |
Beta Was this translation helpful? Give feedback.
2 replies
-
this function generates the group-permission map more or less efficiently private function groupPermissions(){
$permissions = array_keys(setting('AuthGroups.permissions'));
$groups = array_keys(setting('AuthGroups.groups'));
$matrix = setting('AuthGroups.matrix');
$res = []; //response matrix
$row = []; //default row
//build a default row with all permissions set to false
foreach ($permissions as $permission){
$row[$permission] = false;
}
foreach ($groups as $group){
$res[$group] = $row; //add default row to group response
foreach ($matrix[$group] as $mtrx){
if(str_contains($mtrx, '*')){
// this is a group of permissions in the matrix
$grpPermission = strstr($mtrx, '*', true);
foreach ($permissions as $permission){
if(str_contains($permission, $grpPermission)){
$res[$group][$permission] = true;
}
}
}else{
//this is a single permission in the matrix
$res[$group][$mtrx] = true;
}
}
}
return $res;
} but i am leaving to the group the decisions of how to implement this on the provider if at all |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
right now you can use auth()->user->getPermissions() to see an array for the permissions of a user, but can we do the same for groups?
the current workflow now is lacking somehow, let me give an example:
you have a user without permissions, and assign it to a group "x" that has a permit "permit.*" on the matrix, then you remove a single permit from that group but for that user. and that's a mess
so in practice, you can only have users tied to groups or permits, but not both. still the matrix makes easy to build permissions for groups, and use those groups as templates. but there is a missing link. witch is to get the permits array for a given group, to then apply that array to a user as individual permit
my recommendation its put it in a function on the provider, something like auth()->getProvider()->getPermissions('groupName') that returns an array of permissions
Beta Was this translation helpful? Give feedback.
All reactions