0
0
Fork 0
mirror of https://github.com/verdigado/organization_folders.git synced 2024-12-06 11:22:41 +01:00

added subresources api endpoint

This commit is contained in:
Jonathan Treffler 2024-11-25 15:28:40 +01:00
parent ab378ea223
commit 789a05c4c1
6 changed files with 95 additions and 5 deletions

View file

@ -40,7 +40,9 @@ class ResourceVoter extends Voter {
/** @var Resource */
$resource = $subject;
return match ($attribute) {
'READ' => $this->isGranted($user, $resource),
'READ' => $this->isGranted( $user, $resource),
// can read limited information about the resource (true: limited read is allowed, full read may be allowed, false: limited read is not allowed, full read may be allowed (!))
'READ_LIMITED' => $this->isGrantedLimitedRead($user, $resource),
'UPDATE' => $this->isGranted($user, $resource),
'DELETE' => $this->isGranted($user, $resource),
'UPDATE_MEMBERS' => $this->isGranted($user, $resource),
@ -108,6 +110,34 @@ class ResourceVoter extends Voter {
|| $this->isResourceManager($user, $resource, $resourceOrganizationFolder);
}
protected function isGrantedLimitedRead(IUser $user, Resource $resource): bool {
$subResources = $this->resourceService->getAllSubResources($resource);
foreach($subResources as $subResource) {
if($this->isManagerOfAnySubresource($user, $subResource)) {
return true;
}
}
return false;
}
protected function isManagerOfAnySubresource(IUser $user, Resource $resource) {
if($this->isGranted($user, $resource)) {
return true;
}
$subResources = $this->resourceService->getAllSubResources($resource);
foreach($subResources as $subResource) {
if($this->isManagerOfAnySubresource($user, $subResource)) {
return true;
}
}
return false;
}
private function userIsInGroup(IUser $user, string $groupId): bool {
return $this->groupManager->isInGroup($user->getUID(), $groupId);
}