From 622e4cb90341d5ec19eb882cedca39e75a2679b0 Mon Sep 17 00:00:00 2001 From: yemkareems Date: Tue, 18 Mar 2025 11:48:18 +0530 Subject: [PATCH] fix: created a patch from 3258 and 3592 PRs to fix acl issues while listing group folders Signed-off-by: yemkareems --- lib/ACL/ACLManager.php | 5 +++++ lib/Trash/TrashBackend.php | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/ACL/ACLManager.php b/lib/ACL/ACLManager.php index 0d0c5aa89..523b51375 100644 --- a/lib/ACL/ACLManager.php +++ b/lib/ACL/ACLManager.php @@ -14,6 +14,7 @@ use OCP\Files\IRootFolder; use OCP\IUser; use Psr\Log\LoggerInterface; +use RuntimeException; class ACLManager { private CappedMemoryCache $ruleCache; @@ -95,6 +96,9 @@ private function getRelevantPaths(string $path): array { $groupFolderId = (int)$groupFolderId; /* Remove the date part */ $separatorPos = strrpos($rootTrashedItemName, '.d'); + if ($separatorPos === false) { + throw new RuntimeException('Invalid trash item name ' . $rootTrashedItemName); + } $rootTrashedItemDate = (int)substr($rootTrashedItemName, $separatorPos + 2); $rootTrashedItemName = substr($rootTrashedItemName, 0, $separatorPos); } @@ -103,6 +107,7 @@ private function getRelevantPaths(string $path): array { $path = dirname($path); if ($fromTrashbin && ($path === '__groupfolders/trash')) { /* We are in trash and hit the root folder, continue looking for ACLs on parent folders in original location */ + /** @psalm-suppress PossiblyUndefinedVariable Variables are defined above */ $trashItemRow = $this->trashManager->getTrashItemByFileName($groupFolderId, $rootTrashedItemName, $rootTrashedItemDate); $fromTrashbin = false; if ($trashItemRow) { diff --git a/lib/Trash/TrashBackend.php b/lib/Trash/TrashBackend.php index 2eb5cf2e0..1129ffa65 100644 --- a/lib/Trash/TrashBackend.php +++ b/lib/Trash/TrashBackend.php @@ -250,8 +250,13 @@ private function userHasAccessToPath( string $path, int $permission = Constants::PERMISSION_READ ): bool { - $activePermissions = $this->aclManagerFactory->getACLManager($user) - ->getACLPermissionsForPath($path); + try { + $activePermissions = $this->aclManagerFactory->getACLManager($user) + ->getACLPermissionsForPath($path); + } catch (\Exception $e) { + $this->logger->warning("Failed to get permissions for {$path}", ['exception' => $e]); + return false; + } return (bool)($activePermissions & $permission); }