Added grant to all function to RightChecker and LawPermissionChecker

This commit is contained in:
Kevin Frantz
2019-02-16 16:16:48 +01:00
parent 6f6b720470
commit 256e37ccd5
12 changed files with 130 additions and 11 deletions

View File

@@ -54,17 +54,27 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
return $this->getFilteredRights($rights, $type, 'Crud');
}
/**
* @param RightInterface $right
*
* @return bool True if right applies to all
*/
private function doesRightApplyToAll(RightInterface $right): bool
{
return !$right->hasReciever();
}
/**
* @param Collection|RightInterface[] $rights
* @param SourceInterface $reciever
* @param RightInterface $requestedRight
*
* @return Collection|RightInterface[]
*/
private function getRightsByReciever(Collection $rights, SourceInterface $reciever): Collection
private function getRightsByReciever(Collection $rights, RightInterface $requestedRight): Collection
{
$result = new ArrayCollection();
foreach ($rights as $right) {
if ($right->getReciever() === $reciever || $this->memberExist($right, $reciever)) {
if ($this->doesRightApplyToAll($right) || $right->getReciever() === $requestedRight->getReciever() || $this->memberExist($right, $requestedRight->getReciever())) {
$result->add($right);
}
}
@@ -160,7 +170,7 @@ final class LawPermissionChecker implements LawPermissionCheckerInterface
$rights = clone $this->law->getRights();
$rights = $this->getRightsByCrud($rights, $clientRight->getCrud());
$rights = $this->getRightsByLayer($rights, $clientRight->getLayer());
$rights = $this->getRightsByReciever($rights, $clientRight->getReciever());
$rights = $this->getRightsByReciever($rights, $clientRight);
$rights = $this->sortByPriority($rights);
return $this->isGranted($rights, $clientRight);