Skip to content

Commit

Permalink
Update check wildcard match
Browse files Browse the repository at this point in the history
takes into consideration multilevel permissions.
  • Loading branch information
bgeneto authored Nov 9, 2024
1 parent 031b637 commit 4db173c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Authorization/Traits/Authorizable.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,13 @@ public function can(string ...$permissions): bool
}

// Check wildcard match
$check = substr($permission, 0, strpos($permission, '.')) . '.*';
if (isset($matrix[$group]) && in_array($check, $matrix[$group], true)) {
$checks = [];
$parts = explode('.', $permission);
for ($i = count($parts); $i > 0; $i--) {
$check = implode('.', array_slice($parts, 0, $i)) . '.*';
$checks[] = $check;
}
if (isset($matrix[$group]) && array_intersect($checks, $matrix[$group])) {
return true;
}
}
Expand Down

0 comments on commit 4db173c

Please sign in to comment.