Skip to content

Commit

Permalink
Update check for wildcard matching
Browse files Browse the repository at this point in the history
takes into consideration multiple permissions levels
  • Loading branch information
bgeneto authored Nov 9, 2024
1 parent 4db173c commit 9eeed0c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/Entities/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,16 @@ public function can(string $permission): bool
}

// Check wildcard match
$check = substr($permission, 0, strpos($permission, '.')) . '.*';
$checks = [];
$parts = explode('.', $permission);
for ($i = count($parts); $i > 0; $i--) {
$check = implode('.', array_slice($parts, 0, $i)) . '.*';
$checks[] = $check;
}

return $this->permissions !== null && $this->permissions !== [] && in_array($check, $this->permissions, true);
return $this->permissions !== null &&
$this->permissions !== [] &&
array_intersect($checks, $this->permissions);
}

/**
Expand Down

0 comments on commit 9eeed0c

Please sign in to comment.