From 54b8ef8612ad0d018feccfbc3ab01349c028cac6 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Fri, 19 Apr 2024 18:43:39 +0200 Subject: [PATCH] fix(Permissions): expect "context" in checkPermission Signed-off-by: Arthur Schiwon --- lib/Service/PermissionsService.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index 562129c1f..93ed1bb8a 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -523,13 +523,13 @@ private function hasPermission(int $existingPermissions, string $permissionName) } /** - * @param mixed $element - * @param 'table'|'view' $nodeType + * @param Table|View|Context $element + * @param 'table'|'view'|'context' $nodeType * @param string $permission * @param string|null $userId * @return bool */ - private function checkPermission($element, string $nodeType, string $permission, ?string $userId = null): bool { + private function checkPermission(Table|View|Context $element, string $nodeType, string $permission, ?string $userId = null): bool { if($this->basisCheck($element, $nodeType, $userId)) { return true; } @@ -542,7 +542,9 @@ private function checkPermission($element, string $nodeType, string $permission, return $this->getSharedPermissionsIfSharedWithMe($element->getId(), $nodeType, $userId)[$permission]; } catch (NotFoundError $e) { try { - if ($this->hasPermission($this->getPermissionIfAvailableThroughContext($element->getId(), $nodeType, $userId), $permission)) { + if ($nodeType !== 'context' + && $this->hasPermission($this->getPermissionIfAvailableThroughContext($element->getId(), $nodeType, $userId), $permission) + ) { return true; } } catch (NotFoundError $e) { @@ -580,13 +582,7 @@ private function checkPermissionById(int $elementId, string $nodeType, string $p return false; } - /** - * @param Table|View|Context $element - * @param string $nodeType - * @param string|null $userId - * @return bool - */ - private function basisCheck($element, string $nodeType, ?string &$userId): bool { + private function basisCheck(Table|View|Context $element, string $nodeType, ?string &$userId): bool { try { $userId = $this->preCheckUserId($userId); } catch (InternalError $e) {