aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-06-06 18:55:33 +0200
committerskjnldsv <skjnldsv@protonmail.com>2024-06-12 10:27:29 +0200
commit4a77fe3530d3213a2700b8ecdc1ccf3b4195b41a (patch)
tree768e11fc630481073127dd10ee61c6f18cd2a646 /apps
parentfb11672df6f05a502549c596b5f5443988bb5edb (diff)
downloadnextcloud-server-4a77fe3530d3213a2700b8ecdc1ccf3b4195b41a.tar.gz
nextcloud-server-4a77fe3530d3213a2700b8ecdc1ccf3b4195b41a.zip
fix(dav): also return shared-with-me shares data
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php75
-rw-r--r--apps/dav/lib/Server.php6
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php22
3 files changed, 68 insertions, 35 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index c734700f37f..20e94e9aede 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -7,6 +7,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;
@@ -33,24 +34,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();
}
@@ -91,18 +87,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;
}
@@ -124,27 +131,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 [];
}
/**
@@ -161,7 +170,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
&& (
diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php
index 133ac55f303..bec76a03236 100644
--- a/apps/dav/lib/Server.php
+++ b/apps/dav/lib/Server.php
@@ -263,13 +263,15 @@ class Server {
$this->server->tree, \OC::$server->getTagManager()
)
);
+
// TODO: switch to LazyUserFolder
$userFolder = \OC::$server->getUserFolder();
+ $shareManager = \OCP\Server::get(\OCP\Share\IManager::class);
$this->server->addPlugin(new SharesPlugin(
$this->server->tree,
$userSession,
$userFolder,
- \OC::$server->getShareManager()
+ $shareManager,
));
$this->server->addPlugin(new CommentPropertiesPlugin(
\OC::$server->getCommentsManager(),
@@ -304,7 +306,7 @@ class Server {
$this->server->tree,
$user,
\OC::$server->getRootFolder(),
- \OC::$server->getShareManager(),
+ $shareManager,
$view,
\OCP\Server::get(IFilesMetadataManager::class)
));
diff --git a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
index 79f773e42f8..546be840cd8 100644
--- a/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/SharesPluginTest.php
@@ -97,7 +97,7 @@ class SharesPluginTest extends \Test\TestCase {
->with(
$this->equalTo('user1'),
$this->anything(),
- $this->anything(),
+ $this->equalTo($node),
$this->equalTo(false),
$this->equalTo(-1)
)
@@ -111,6 +111,16 @@ class SharesPluginTest extends \Test\TestCase {
return [];
});
+ $this->shareManager->expects($this->any())
+ ->method('getSharedWith')
+ ->with(
+ $this->equalTo('user1'),
+ $this->anything(),
+ $this->equalTo($node),
+ $this->equalTo(-1)
+ )
+ ->willReturn([]);
+
$propFind = new \Sabre\DAV\PropFind(
'/dummyPath',
[self::SHARETYPES_PROPERTYNAME],
@@ -200,6 +210,16 @@ class SharesPluginTest extends \Test\TestCase {
});
$this->shareManager->expects($this->any())
+ ->method('getSharedWith')
+ ->with(
+ $this->equalTo('user1'),
+ $this->anything(),
+ $this->equalTo($node),
+ $this->equalTo(-1)
+ )
+ ->willReturn([]);
+
+ $this->shareManager->expects($this->any())
->method('getSharesInFolder')
->with(
$this->equalTo('user1'),