Allow more segments in the permission #1177
christianberkman
started this conversation in
Ideas
Replies: 1 comment 1 reply
-
I have now implemented this as below by extending the This allows permissions with unlimited more sections after public function can(string ...$permissions): bool
{
// Check scope.action style permissions
$parentCheck = parent::can(...$permissions);
if ($parentCheck === true) {
return true;
}
// Deep wildcard search (scope.action.more.more...)
$matrix = setting('AuthGroups.matrix');
foreach ($permissions as $permission) {
// Skip if permission only has scope.action
if (substr_count($permission, '.') === 1) {
continue;
}
$permission = strtolower($permission);
// Walk down permission tree
foreach ($this->groupCache as $group) {
$walker = $permission;
while (substr_count($walker, '.') >= 1) {
$check = $walker . '.*';
if (isset($matrix[$group]) && in_array($check, $matrix[$group], true)) {
return true;
}
// Walk down one more step
$walker = substr($walker, 0, strrpos($walker, '.'));
}
}
}
return false;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I would like opinions on this idea:
What if permissions could be allowed to have more sescions beyond scope and action. It would be total optional and I believe it would not break any existing installations.
Permission examples:
if it is something that is wanted by others, I can look in to how to get it done. Should not be that impactful?
I believe this could add some conveniecne and prevent needing to add many permissions to a group.
Beta Was this translation helpful? Give feedback.
All reactions