From e3991fbde0e97ad31af44c9f2506a8a1208d8f53 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Tue, 26 Feb 2019 08:15:32 +0100 Subject: [PATCH] Show sharees via propfind Signed-off-by: tobiasKaminsky --- apps/dav/lib/Connector/Sabre/FilesPlugin.php | 6 ++- apps/dav/lib/Connector/Sabre/Node.php | 57 ++++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/Connector/Sabre/FilesPlugin.php b/apps/dav/lib/Connector/Sabre/FilesPlugin.php index 99317f2bc1c..4a15edfdf46 100644 --- a/apps/dav/lib/Connector/Sabre/FilesPlugin.php +++ b/apps/dav/lib/Connector/Sabre/FilesPlugin.php @@ -71,6 +71,7 @@ class FilesPlugin extends ServerPlugin { const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type'; const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted'; const SHARE_NOTE = '{http://nextcloud.org/ns}note'; + const SHAREES_PROPERTYNAME = '{http://nextcloud.org/ns}sharees'; /** * Reference to main server object @@ -163,6 +164,7 @@ class FilesPlugin extends ServerPlugin { $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME; $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME; $server->protectedProperties[] = self::SHARE_NOTE; + $server->protectedProperties[] = self::SHAREES_PROPERTYNAME; // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH $allowedProperties = ['{DAV:}getetag']; @@ -361,12 +363,14 @@ class FilesPlugin extends ServerPlugin { $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) { return $node->getFileInfo()->getMountPoint()->getMountType(); }); - $propFind->handle(self::SHARE_NOTE, function() use ($node, $httpRequest) { return $node->getNoteFromShare( $httpRequest->getRawServerValue('PHP_AUTH_USER') ); }); + $propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($node, $httpRequest) { + return $node->getShareeFromShare($httpRequest->getRawServerValue('PHP_AUTH_USER')); + }); } if ($node instanceof \OCA\DAV\Connector\Sabre\Node) { diff --git a/apps/dav/lib/Connector/Sabre/Node.php b/apps/dav/lib/Connector/Sabre/Node.php index f0917fe11b2..4cf6835b89d 100644 --- a/apps/dav/lib/Connector/Sabre/Node.php +++ b/apps/dav/lib/Connector/Sabre/Node.php @@ -43,6 +43,7 @@ use OCP\Share\Exceptions\ShareNotFound; use OCP\Share\IManager; use OCP\Share; use OCP\Share\IShare; +use OCP\Lock\ILockingProvider; abstract class Node implements \Sabre\DAV\INode { @@ -323,6 +324,62 @@ abstract class Node implements \Sabre\DAV\INode { return ''; } + /** + * @param string $user + * @return string + */ + public function getShareeFromShare($user) { + $sharees = []; + + if ($user == null) { + return $sharees; + } + $types = [ + Share::SHARE_TYPE_USER, + Share::SHARE_TYPE_REMOTE, + Share::SHARE_TYPE_GROUP, + ]; + + if ($this->getPath() === "/") { + return $sharees; + } + + $path = $this->getPath(); + + if ($path !== null) { + $userFolder = \OC::$server->getRootFolder()->getUserFolder($user); + try { + $path = $userFolder->get($path); + $this->lock($path); + } catch (\OCP\Files\NotFoundException $e) { + throw new OCSNotFoundException($this->l->t('Wrong path, file/folder doesn\'t exist')); + } catch (LockedException $e) { + throw new OCSNotFoundException($this->l->t('Could not lock path')); + } + } + + 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(); + } + } + } + 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; + } + /** * @return string */ -- 2.39.5