Skip to content

Commit

Permalink
passing test when have inverted rule with whole action
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexzPurewoko committed Dec 28, 2023
1 parent be56c7b commit 4485bc0
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/Abilities/Core/Comparator/AbilityCheckerImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ public function __construct(
*/
public function can(string $action, string $resource, string $scope, mixed $field = null): bool
{
$specificActionRules = $this->compiledRules->queryRule($scope, $resource, $action);
$specificNormalRules = [];
$unspecifiedActionRules = $this->compiledRules->queryRule($scope, $resource, '');

foreach ($specificActionRules as $specificActionRule) {
if ($specificActionRule->isInverted()) {
/** 1. Checking on specific inverted rules */
if ($specificActionRule->getResource()->matchField($field)) {
return false; // as the correspondent user is prohibited access resource
}
} else {
$specificNormalRules[] = $specificActionRule;
$specificNormalRules = [];
$starActionRules = [];
foreach ($unspecifiedActionRules as $unspecifiedActionRule) {
/** 1. Checking on specific inverted rules */
if ($unspecifiedActionRule->isInverted() && $unspecifiedActionRule->getResource()->matchField($field)) {
return false; // as the correspondent user is prohibited access resource
} elseif ($unspecifiedActionRule->getAction()->wholeAction()) {
$starActionRules[] = $unspecifiedActionRule;
} elseif ($unspecifiedActionRule->getAction()->get() === $action) {
$specificNormalRules[] = $unspecifiedActionRule;
}
}

/** 2. Star-<action> rules */
$starActionRules = $this->compiledRules->queryRule($scope, $resource, '*');
foreach ($starActionRules as $starActionRule) {
if ($starActionRule->getResource()->matchField($field)) {
return !$starActionRule->isInverted();
Expand Down

0 comments on commit 4485bc0

Please sign in to comment.