Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
arogachev committed Apr 21, 2024
1 parent 11ed38e commit 2791ab2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function userHasPermission(
$itemNames = array_map(static fn (array $treeItem): string => $treeItem['item']->getName(), $hierarchy);
$userItemNames = $guestRole !== null
? [$guestRole->getName()]
: $this->assignmentsStorage->filterUserItemNames((string) $userId, $itemNames);
: $this->filterUserItemNames((string) $userId, $itemNames);
$userItemNamesMap = [];
foreach ($userItemNames as $userItemName) {
$userItemNamesMap[$userItemName] = null;
Expand Down Expand Up @@ -110,6 +110,18 @@ public function userHasPermission(
return false;
}

public function filterUserItemNames(string $userId, array $itemNames): array
{

$userItemNames = $this->assignmentsStorage->filterUserItemNames($userId, $itemNames);
foreach ($this->defaultRoleNames as $roleName) {
if(in_array($roleName, $itemNames)) {

Check warning on line 118 in src/Manager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "IfNegation": --- Original +++ New @@ @@ { $userItemNames = $this->assignmentsStorage->filterUserItemNames($userId, $itemNames); foreach ($this->defaultRoleNames as $roleName) { - if (in_array($roleName, $itemNames)) { + if (!in_array($roleName, $itemNames)) { $userItemNames[] = $roleName; } }
$userItemNames[] = $roleName;
}
}
return $userItemNames;

Check warning on line 122 in src/Manager.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "ArrayOneItem": --- Original +++ New @@ @@ $userItemNames[] = $roleName; } } - return $userItemNames; + return count($userItemNames) > 1 ? array_slice($userItemNames, 0, 1, true) : $userItemNames; } public function canAddChild(string $parentName, string $childName) : bool {
}

public function canAddChild(string $parentName, string $childName): bool
{
try {
Expand Down
10 changes: 10 additions & 0 deletions src/ManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@
*/
interface ManagerInterface extends AccessCheckerInterface
{
/**
* Filters item names leaving only the ones that are assigned to specific user or assigned by default.
*
* @param string $userId User id.
* @param string[] $itemNames List of item names.
*
* @return string[] Filtered item names.
*/
public function filterUserItemNames(string $userId, array $itemNames): array;

/**
* Checks the possibility of adding a child to a parent.
*
Expand Down

0 comments on commit 2791ab2

Please sign in to comment.