mirror of
https://github.com/nextcloud/server.git
synced 2026-06-15 11:41:20 -04:00
fix(dav): also return shared-with-me shares data
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
This commit is contained in:
parent
4ad83e9fa3
commit
697f9032cf
3 changed files with 70 additions and 37 deletions
|
|
@ -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 [];
|
||||
}
|
||||
return $this->cachedShares[$sabreNode->getId()];
|
||||
}
|
||||
|
||||
return $shares;
|
||||
[$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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -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
|
||||
&& (
|
||||
|
|
|
|||
|
|
@ -295,13 +295,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(),
|
||||
|
|
@ -324,7 +326,7 @@ class Server {
|
|||
$this->server->tree,
|
||||
$user,
|
||||
\OC::$server->getRootFolder(),
|
||||
\OC::$server->getShareManager(),
|
||||
$shareManager,
|
||||
$view,
|
||||
\OCP\Server::get(IFilesMetadataManager::class)
|
||||
));
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class SharesPluginTest extends \Test\TestCase {
|
|||
->with(
|
||||
$this->equalTo('user1'),
|
||||
$this->anything(),
|
||||
$this->anything(),
|
||||
$this->equalTo($node),
|
||||
$this->equalTo(false),
|
||||
$this->equalTo(-1)
|
||||
)
|
||||
|
|
@ -133,6 +133,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],
|
||||
|
|
@ -221,6 +231,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([]);
|
||||
|
||||
$this->shareManager->expects($this->any())
|
||||
->method('getSharesInFolder')
|
||||
->with(
|
||||
|
|
|
|||
Loading…
Reference in a new issue