From 326c31f338cd41b7b140249e7a122dfc27d5c4c7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 11 Apr 2024 18:19:04 +0200 Subject: [PATCH] fix: use the correct source share for getting the max reshare permissions Signed-off-by: Robin Appelman --- lib/private/Share20/Manager.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 53dbf65ccc755..9fb28b0428cae 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -296,7 +296,7 @@ protected function generalCreateChecks(IShare $share, bool $isUpdate = false) { $isFederatedShare = $share->getNode()->getStorage()->instanceOfStorage('\OCA\Files_Sharing\External\Storage'); $permissions = 0; - + $isReshare = $share->getNode()->getOwner() && $share->getNode()->getOwner()->getUID() !== $share->getSharedBy(); if (!$isReshare && $isUpdate) { // in case of update on owner-less filesystem, we use share owner to improve reshare detection @@ -304,23 +304,11 @@ protected function generalCreateChecks(IShare $share, bool $isUpdate = false) { } if (!$isFederatedShare && $isReshare) { - $userMounts = array_filter($userFolder->getById($share->getNode()->getId()), function ($mount) { - // We need to filter since there might be other mountpoints that contain the file - // e.g. if the user has access to the same external storage that the file is originating from - return $mount->getStorage()->instanceOfStorage(ISharedStorage::class); - }); - $userMount = array_shift($userMounts); - if ($userMount === null) { - throw new GenericShareException('Could not get proper share mount for ' . $share->getNode()->getId() . '. Failing since else the next calls are called with null'); - } - $mount = $userMount->getMountPoint(); - // When it's a reshare use the parent share permissions as maximum - $userMountPointId = $mount->getStorageRootId(); - $userMountPoint = $userFolder->getFirstNodeById($userMountPointId); - - if ($userMountPoint === null) { - throw new GenericShareException('Could not get proper user mount for ' . $userMountPointId . '. Failing since else the next calls are called with null'); + // get the root of the parent share + if ($userFolder->getRelativePath($share->getNode()->getPath()) === null) { + throw new \Exception("share node not in user folder"); } + $userMountPoint = $this->rootFolder->get($share->getNode()->getMountPoint()->getMountPoint()); /* Check if this is an incoming share */ $incomingShares = $this->getSharedWith($share->getSharedBy(), IShare::TYPE_USER, $userMountPoint, -1, 0);