diff options
Diffstat (limited to 'apps/dav/lib')
-rw-r--r-- | apps/dav/lib/Connector/Sabre/FilesPlugin.php | 7 | ||||
-rw-r--r-- | apps/dav/lib/Connector/Sabre/Node.php | 34 | ||||
-rw-r--r-- | apps/dav/lib/Storage/PublicShareWrapper.php | 38 |
3 files changed, 55 insertions, 24 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 3b96f67a82b..13244004993 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -345,13 +345,10 @@ class FilesPlugin extends ServerPlugin { return $node->getNode()->getInternalPath() === '' ? 'true' : 'false'; }); - $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): ?string { + $propFind->handle(self::SHARE_NOTE, function () use ($node, $httpRequest): string { $user = $this->userSession->getUser(); - if ($user === null) { - return null; - } return $node->getNoteFromShare( - $user->getUID() + $user?->getUID() ); }); diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index 379574b30d6..075ea2dd65b 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -15,6 +15,7 @@ use OCA\DAV\Connector\Sabre\Exception\InvalidPath; use OCP\Files\DavUtil; use OCP\Files\FileInfo; use OCP\Files\IRootFolder; +use OCP\Files\NotFoundException; use OCP\Files\StorageNotAvailableException; use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; @@ -298,15 +299,14 @@ abstract class Node implements \Sabre\DAV\INode { * @return array */ public function getShareAttributes(): array { - $attributes = []; - try { - $storage = $this->info->getStorage(); - } catch (StorageNotAvailableException $e) { - $storage = null; + $storage = $this->node->getStorage(); + } catch (NotFoundException $e) { + return []; } - if ($storage && $storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { + $attributes = []; + if (method_exists($storage, 'getShare')) { /** @var \OCA\Files_Sharing\SharedStorage $storage */ $attributes = $storage->getShare()->getAttributes(); if ($attributes === null) { @@ -319,29 +319,25 @@ abstract class Node implements \Sabre\DAV\INode { return $attributes; } - /** - * @param string $user - * @return string - */ - public function getNoteFromShare($user) { - if ($user === null) { + public function getNoteFromShare(?string $user): string { + try { + $storage = $this->node->getStorage(); + } catch (NotFoundException) { return ''; } - // Retrieve note from the share object already loaded into - // memory, to avoid additional database queries. - $storage = $this->getNode()->getStorage(); - if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { + if (!method_exists($storage, 'getShare')) { return ''; } /** @var \OCA\Files_Sharing\SharedStorage $storage */ $share = $storage->getShare(); $note = $share->getNote(); - if ($share->getShareOwner() !== $user) { - return $note; + if ($user === $share->getShareOwner()) { + // Note is only for recipient not the owner + return ''; } - return ''; + return $note; } /** diff --git a/apps/dav/lib/Storage/PublicShareWrapper.php b/apps/dav/lib/Storage/PublicShareWrapper.php new file mode 100644 index 00000000000..fb24abda9d0 --- /dev/null +++ b/apps/dav/lib/Storage/PublicShareWrapper.php @@ -0,0 +1,38 @@ +<?php + +declare(strict_types=1); + +/** + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +namespace OCA\DAV\Storage; + +use OC\Files\Storage\Wrapper\Wrapper; +use OCP\Share\IShare; + +class PublicShareWrapper extends Wrapper { + + private IShare $share; + + /** + * @param array $arguments ['storage' => $storage, 'share' => $share] + * + * $storage: The storage the permissions mask should be applied on + * $share: The share to use in case no share is found + */ + public function __construct($arguments) { + parent::__construct($arguments); + $this->share = $arguments['share']; + } + + public function getShare(): IShare { + $storage = parent::getWrapperStorage(); + if (method_exists($storage, 'getShare')) { + /** @var \OCA\Files_Sharing\SharedStorage $storage */ + return $storage->getShare(); + } + + return $this->share; + } +} |