diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-06-06 18:55:33 +0200 |
---|---|---|
committer | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2024-06-12 13:23:39 +0200 |
commit | 14c1b53b56c2fa3650edcd1888de6b5d2e05fe00 (patch) | |
tree | 118521cae9e142272ba7dd771e1918a919f84287 /apps/dav/lib/Connector/Sabre | |
parent | 339fdfb6b59a33e2f789be9f15069ffd09442b70 (diff) | |
download | nextcloud-server-14c1b53b56c2fa3650edcd1888de6b5d2e05fe00.tar.gz nextcloud-server-14c1b53b56c2fa3650edcd1888de6b5d2e05fe00.zip |
fix(dav): also return shared-with-me shares data
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/dav/lib/Connector/Sabre')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/SharesPlugin.php | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php index 4cda346af01..d1cadee5f8b 100644 --- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php @@ -28,6 +28,7 @@ */ namespace OCA\DAV\Connector\Sabre; +use OC\Share20\Exception\BackendError; use OCA\DAV\Connector\Sabre\Node as DavNode; use OCP\Files\Folder; use OCP\Files\Node; @@ -54,24 +55,19 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { * @var \Sabre\DAV\Server */ private $server; - private IManager $shareManager; - private Tree $tree; private string $userId; - private Folder $userFolder; + /** @var IShare[][] */ private array $cachedShares = []; /** @var string[] */ private array $cachedFolders = []; public function __construct( - Tree $tree, - IUserSession $userSession, - Folder $userFolder, - IManager $shareManager + private Tree $tree, + private IUserSession $userSession, + private Folder $userFolder, + private IManager $shareManager, ) { - $this->tree = $tree; - $this->shareManager = $shareManager; - $this->userFolder = $userFolder; $this->userId = $userSession->getUser()->getUID(); } @@ -112,18 +108,29 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { IShare::TYPE_DECK, IShare::TYPE_SCIENCEMESH, ]; + foreach ($requestedShareTypes as $requestedShareType) { - $shares = $this->shareManager->getSharesBy( + $result = array_merge($result, $this->shareManager->getSharesBy( $this->userId, $requestedShareType, $node, false, -1 - ); - foreach ($shares as $share) { - $result[] = $share; + )); + + // Also check for shares where the user is the recipient + try { + $result = array_merge($result, $this->shareManager->getSharedWith( + $this->userId, + $requestedShareType, + $node, + -1 + )); + } catch (BackendError $e) { + // ignore } } + return $result; } @@ -145,27 +152,29 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { */ private function getShares(DavNode $sabreNode): array { if (isset($this->cachedShares[$sabreNode->getId()])) { - $shares = $this->cachedShares[$sabreNode->getId()]; - } else { - [$parentPath,] = \Sabre\Uri\split($sabreNode->getPath()); - if ($parentPath === '') { - $parentPath = '/'; - } - // if we already cached the folder this file is in we know there are no shares for this file - if (array_search($parentPath, $this->cachedFolders) === false) { - try { - $node = $sabreNode->getNode(); - } catch (NotFoundException $e) { - return []; - } - $shares = $this->getShare($node); - $this->cachedShares[$sabreNode->getId()] = $shares; - } else { + return $this->cachedShares[$sabreNode->getId()]; + } + + [$parentPath,] = \Sabre\Uri\split($sabreNode->getPath()); + if ($parentPath === '') { + $parentPath = '/'; + } + + // if we already cached the folder containing this file + // then we already know there are no shares here. + if (array_search($parentPath, $this->cachedFolders) === false) { + try { + $node = $sabreNode->getNode(); + } catch (NotFoundException $e) { return []; } + + $shares = $this->getShare($node); + $this->cachedShares[$sabreNode->getId()] = $shares; + return $shares; } - return $shares; + return []; } /** @@ -182,7 +191,9 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin { return; } - // need prefetch ? + // If the node is a directory and we are requesting share types or sharees + // then we get all the shares in the folder and cache them. + // This is more performant than iterating each files afterwards. if ($sabreNode instanceof Directory && $propFind->getDepth() !== 0 && ( |