Skip to content

Commit

Permalink
perf: don't perform trashbin access check if acls are not enabled for…
Browse files Browse the repository at this point in the history
… a folder

Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 committed Jul 24, 2024
1 parent 2f26b80 commit 6d3e607
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions lib/Trash/TrashBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCA\GroupFolders\Mount\MountProvider;
use OCA\GroupFolders\Versions\VersionsBackend;
use OCP\Constants;
use OCP\Files\Cache\ICacheEntry;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\Node;
Expand Down Expand Up @@ -309,6 +310,8 @@ private function getTrashFolder(int $folderId): Folder {
}

/**
* @param IUser $user
* @param array{folder_id: int, mount_point: string, permissions: int, quota: int, acl: bool, rootCacheEntry: ?ICacheEntry}[] $folders
* @return list<ITrashItem>
*/
private function getTrashForFolders(IUser $user, array $folders): array {
Expand All @@ -326,6 +329,7 @@ private function getTrashForFolders(IUser $user, array $folders): array {
$items = [];
foreach ($folders as $folder) {
$folderId = $folder['folder_id'];
$folderHasAcl = $folder['acl'];
$mountPoint = $folder['mount_point'];
$trashFolder = $this->getTrashFolder($folderId);
$content = $trashFolder->getDirectoryListing();
Expand All @@ -340,20 +344,22 @@ private function getTrashForFolders(IUser $user, array $folders): array {

$originalLocation = isset($indexedRows[$key]) ? $indexedRows[$key]['original_location'] : '';

// if we for any reason lost track of the original location, hide the item for non-managers as a fail-safe
if ($originalLocation === '' && !$userCanManageAcl) {
continue;
}
if (!$this->userHasAccessToPath($user, $item->getPath())) {
continue;
}
// if a parent of the original location has also been deleted, we also need to check it based on the now-deleted parent path
foreach ($this->getParentOriginalPaths($originalLocation, $trashItemsByOriginalLocation) as $parentOriginalPath) {
$parentTrashItem = $trashItemsByOriginalLocation[$parentOriginalPath];
$relativePath = substr($originalLocation, strlen($parentOriginalPath));
$parentTrashItemPath = "__groupfolders/trash/{$parentTrashItem['folder_id']}/{$parentTrashItem['name']}.d{$parentTrashItem['deleted_time']}";
if (!$this->userHasAccessToPath($user, $parentTrashItemPath . $relativePath)) {
continue 2;
if ($folderHasAcl) {
// if we for any reason lost track of the original location, hide the item for non-managers as a fail-safe
if ($originalLocation === '' && !$userCanManageAcl) {
continue;
}
if (!$this->userHasAccessToPath($user, $item->getPath())) {
continue;
}
// if a parent of the original location has also been deleted, we also need to check it based on the now-deleted parent path
foreach ($this->getParentOriginalPaths($originalLocation, $trashItemsByOriginalLocation) as $parentOriginalPath) {
$parentTrashItem = $trashItemsByOriginalLocation[$parentOriginalPath];
$relativePath = substr($originalLocation, strlen($parentOriginalPath));
$parentTrashItemPath = "__groupfolders/trash/{$parentTrashItem['folder_id']}/{$parentTrashItem['name']}.d{$parentTrashItem['deleted_time']}";
if (!$this->userHasAccessToPath($user, $parentTrashItemPath . $relativePath)) {
continue 2;
}
}
}

Expand Down

0 comments on commit 6d3e607

Please sign in to comment.