diff --git a/src/Security/Authorization/Voter/NodeTypeFieldVoter.php b/src/Security/Authorization/Voter/NodeTypeFieldVoter.php new file mode 100644 index 00000000..eb55732c --- /dev/null +++ b/src/Security/Authorization/Voter/NodeTypeFieldVoter.php @@ -0,0 +1,62 @@ +getUser(); + + if (!$user instanceof UserInterface) { + // the user must be logged in; if not, deny access + return false; + } + + return match ($attribute) { + self::VIEW => $this->canView($subject, $user), + default => throw new \LogicException('This code should not be reached!') + }; + } + + private function canView(NodeTypeField $field, UserInterface $user): bool + { + if ($field->isNodes() && !$this->security->isGranted(NodeVoter::SEARCH)) { + return false; + } + if ($field->isDocuments() && !$this->security->isGranted('ROLE_ACCESS_DOCUMENTS')) { + return false; + } + if ($field->isUser() && !$this->security->isGranted('ROLE_ACCESS_USERS')) { + return false; + } + if ($field->isCustomForms() && !$this->security->isGranted('ROLE_ACCESS_CUSTOMFORMS')) { + return false; + } + + return true; + } +} diff --git a/src/Security/Authorization/Voter/NodeVoter.php b/src/Security/Authorization/Voter/NodeVoter.php index ca17f851..54187b57 100644 --- a/src/Security/Authorization/Voter/NodeVoter.php +++ b/src/Security/Authorization/Voter/NodeVoter.php @@ -161,10 +161,12 @@ private function canReadAtRoot(UserInterface $user): bool return null === $chroot && $this->security->isGranted('ROLE_ACCESS_NODES'); } + /* + * All node users can search even if they are chroot-ed + */ private function canSearch(UserInterface $user): bool { - $chroot = $this->chrootResolver->getChroot($user); - return null === $chroot && $this->security->isGranted('ROLE_ACCESS_NODES'); + return $this->security->isGranted('ROLE_ACCESS_NODES'); } private function canEmptyTrash(UserInterface $user): bool