aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/Connector
diff options
context:
space:
mode:
authortobiasKaminsky <tobias@kaminsky.me>2019-07-23 10:31:13 +0200
committertobiasKaminsky <tobias@kaminsky.me>2019-07-23 10:33:56 +0200
commitefa0733b040b4674cd2e9cf2ee54ee48164291d1 (patch)
tree55a4546d8a849b1afc9db53992d0d31ca28810bd /apps/dav/lib/Connector
parentb81fb182b3d793882a1942c852e8c3d2262b3de9 (diff)
downloadnextcloud-server-efa0733b040b4674cd2e9cf2ee54ee48164291d1.tar.gz
nextcloud-server-efa0733b040b4674cd2e9cf2ee54ee48164291d1.zip
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Diffstat (limited to 'apps/dav/lib/Connector')
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php90
1 files changed, 32 insertions, 58 deletions
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index e395bb7313a..be76171c33d 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -27,13 +27,9 @@
*/
namespace OCA\DAV\Connector\Sabre;
-use OCA\DAV\Connector\Sabre\Exception\FileLocked;
use \Sabre\DAV\PropFind;
use OCP\IUserSession;
use OCP\Share\IShare;
-use OCP\Files\NotFoundException;
-use OCP\Lock\LockedException;
-use \OCA\DAV\Connector\Sabre\Node;
/**
* Sabre Plugin to provide share-related properties
@@ -223,67 +219,45 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
});
$propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($sabreNode) {
- $test = $this->server->httpRequest->getRawServerValue('PHP_AUTH_USER');
- return $this->getShareeFromShare($sabreNode, $test);
- });
- }
-
- /**
- * @param \Sabre\DAV\INode $sabreNode
- * @param string $user
- * @return string
- * @throws FileLocked
- * @throws NotFoundException
- */
- public function getShareeFromShare(\Sabre\DAV\INode $sabreNode, $user) {
- $sharees = [];
+ $user = $this->server->httpRequest->getRawServerValue('PHP_AUTH_USER');
- if ($user == null) {
- return $sharees;
- }
- $types = [
- Share::SHARE_TYPE_USER,
- Share::SHARE_TYPE_REMOTE,
- Share::SHARE_TYPE_GROUP,
- ];
-
- if ($sabreNode->getPath() === "/") {
- return $sharees;
- }
+ if ($user == null) {
+ return [];
+ }
- $path = $this->getPath();
+ if ($sabreNode->getPath() === "/") {
+ return [];
+ }
- if ($path !== null) {
$userFolder = \OC::$server->getRootFolder()->getUserFolder($user);
- try {
- $path = $userFolder->get($path);
- $this->lock($path);
- } catch (\OCP\Files\NotFoundException $e) {
- throw new NotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist'));
- } catch (LockedException $e) {
- throw new FileLocked($e->getMessage(), $e->getCode(), $e);
- }
- }
+ $path = $userFolder->get($sabreNode->getPath());
- foreach ($types as $shareType) {
- $shares = $this->shareManager->getSharesBy($user, $shareType, $path, false, -1, 0);
- foreach ($shares as $share) {
- if ($share->getSharedBy() === $user) {
- $sharees[] = $share->getSharedWith();
+ if (isset($this->cachedShareTypes[$sabreNode->getId()])) {
+ $shareTypes = $this->cachedShareTypes[$sabreNode->getId()];
+ } else {
+ list($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) {
+ $node = $this->userFolder->get($sabreNode->getPath());
+ $shareTypes = $this->getShareTypes($node);
+ } else {
+ return [];
}
}
- }
- return implode(', ', $sharees);
- }
- /**
- * Lock a Node
- *
- * @param \OCP\Files\Node $node
- * @throws LockedException
- */
- private function lock(\OCP\Files\Node $node) {
- $node->lock(ILockingProvider::LOCK_SHARED);
- $this->lockedNode = $node;
+ foreach ($shareTypes as $shareType) {
+ $shares = $this->shareManager->getSharesBy($user, $shareType, $path, false, -1, 0);
+
+ foreach ($shares as $share) {
+ if ($share->getSharedBy() === $user) {
+ $sharees[] = $share->getSharedWith();
+ }
+ }
+ }
+ return implode(', ', $sharees);
+ });
}
}