aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2019-08-13 20:22:47 +0200
committerGitHub <noreply@github.com>2019-08-13 20:22:47 +0200
commit34868f09644b4b63559d1d9ce072dbed7802c620 (patch)
tree6a01ae374a8847ce10a01d9d1a505d067a25da6d /apps/dav/lib
parent3a99ef30dfa6a49ef0c5f4c0515a98e55c43dbe4 (diff)
parenta85392615d74f08a8ec62eca5d9ccc94294d89ec (diff)
downloadnextcloud-server-34868f09644b4b63559d1d9ce072dbed7802c620.tar.gz
nextcloud-server-34868f09644b4b63559d1d9ce072dbed7802c620.zip
Merge pull request #14429 from tobiasKaminsky/shareesOnDav
Show sharees via propfind
Diffstat (limited to 'apps/dav/lib')
-rw-r--r--apps/dav/lib/Connector/Sabre/ShareeList.php61
-rw-r--r--apps/dav/lib/Connector/Sabre/SharesPlugin.php98
2 files changed, 109 insertions, 50 deletions
diff --git a/apps/dav/lib/Connector/Sabre/ShareeList.php b/apps/dav/lib/Connector/Sabre/ShareeList.php
new file mode 100644
index 00000000000..a9e9dfc2803
--- /dev/null
+++ b/apps/dav/lib/Connector/Sabre/ShareeList.php
@@ -0,0 +1,61 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019, Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @author Roeland Jago Douma <roeland@famdouma.nl>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\DAV\Connector\Sabre;
+
+use OCP\Share\IShare;
+use Sabre\Xml\Element;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
+
+/**
+ * This property contains multiple "sharee" elements, each containing a share sharee
+ */
+class ShareeList implements XmlSerializable {
+ const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
+
+ /** @var IShare[] */
+ private $shares;
+
+ public function __construct(array $shares) {
+ $this->shares = $shares;
+ }
+
+ /**
+ * The xmlSerialize metod is called during xml writing.
+ *
+ * @param Writer $writer
+ * @return void
+ */
+ function xmlSerialize(Writer $writer) {
+ foreach ($this->shares as $share) {
+ $writer->startElement('{' . self::NS_NEXTCLOUD . '}sharee');
+ $writer->writeElement('{' . self::NS_NEXTCLOUD . '}id', $share->getSharedWith());
+ $writer->writeElement('{' . self::NS_NEXTCLOUD . '}display-name', $share->getSharedWithDisplayName());
+ $writer->writeElement('{' . self::NS_NEXTCLOUD . '}type', $share->getShareType());
+ $writer->endElement();
+ }
+ }
+}
diff --git a/apps/dav/lib/Connector/Sabre/SharesPlugin.php b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
index 46174c8118e..5edf28e6e50 100644
--- a/apps/dav/lib/Connector/Sabre/SharesPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/SharesPlugin.php
@@ -37,7 +37,9 @@ use OCP\Share\IShare;
class SharesPlugin extends \Sabre\DAV\ServerPlugin {
const NS_OWNCLOUD = 'http://owncloud.org/ns';
+ const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
const SHARETYPES_PROPERTYNAME = '{http://owncloud.org/ns}share-types';
+ const SHAREES_PROPERTYNAME = '{http://nextcloud.org/ns}sharees';
/**
* Reference to main server object
@@ -66,10 +68,8 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
*/
private $userFolder;
- /**
- * @var IShare[]
- */
- private $cachedShareTypes;
+ /** @var IShare[] */
+ private $cachedShares = [];
private $cachedFolders = [];
@@ -89,7 +89,6 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
$this->shareManager = $shareManager;
$this->userFolder = $userFolder;
$this->userId = $userSession->getUser()->getUID();
- $this->cachedShareTypes = [];
}
/**
@@ -106,20 +105,14 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
$server->xml->namespacesMap[self::NS_OWNCLOUD] = 'oc';
$server->xml->elementMap[self::SHARETYPES_PROPERTYNAME] = ShareTypeList::class;
$server->protectedProperties[] = self::SHARETYPES_PROPERTYNAME;
+ $server->protectedProperties[] = self::SHAREES_PROPERTYNAME;
$this->server = $server;
$this->server->on('propFind', array($this, 'handleGetProperties'));
}
- /**
- * Return a list of share types for outgoing shares
- *
- * @param \OCP\Files\Node $node file node
- *
- * @return int[] array of share types
- */
- private function getShareTypes(\OCP\Files\Node $node) {
- $shareTypes = [];
+ private function getShare(\OCP\Files\Node $node): array {
+ $result = [];
$requestedShareTypes = [
\OCP\Share::SHARE_TYPE_USER,
\OCP\Share::SHARE_TYPE_GROUP,
@@ -130,40 +123,47 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
\OCP\Share::SHARE_TYPE_CIRCLE,
];
foreach ($requestedShareTypes as $requestedShareType) {
- // one of each type is enough to find out about the types
$shares = $this->shareManager->getSharesBy(
$this->userId,
$requestedShareType,
$node,
false,
- 1
+ -1
);
- if (!empty($shares)) {
- $shareTypes[] = $requestedShareType;
+ foreach ($shares as $share) {
+ $result[] = $share;
}
}
- return $shareTypes;
+ return $result;
}
- private function getSharesTypesInFolder(\OCP\Files\Folder $node) {
- $shares = $this->shareManager->getSharesInFolder(
+ private function getSharesFolder(\OCP\Files\Folder $node): array {
+ return $this->shareManager->getSharesInFolder(
$this->userId,
$node,
true
);
+ }
- $shareTypesByFileId = [];
-
- foreach($shares as $fileId => $sharesForFile) {
- $types = array_map(function(IShare $share) {
- return $share->getShareType();
- }, $sharesForFile);
- $types = array_unique($types);
- sort($types);
- $shareTypesByFileId[$fileId] = $types;
+ private function getShares(\Sabre\DAV\INode $sabreNode): array {
+ if (isset($this->cachedShares[$sabreNode->getId()])) {
+ $shares = $this->cachedShares[$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());
+ $shares = $this->getShare($node);
+ $this->cachedShares[$sabreNode->getId()] = $shares;
+ } else {
+ return [];
+ }
}
- return $shareTypesByFileId;
+ return $shares;
}
/**
@@ -183,36 +183,34 @@ class SharesPlugin extends \Sabre\DAV\ServerPlugin {
// need prefetch ?
if ($sabreNode instanceof \OCA\DAV\Connector\Sabre\Directory
&& $propFind->getDepth() !== 0
- && !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME))
+ && (
+ !is_null($propFind->getStatus(self::SHARETYPES_PROPERTYNAME)) ||
+ !is_null($propFind->getStatus(self::SHAREES_PROPERTYNAME))
+ )
) {
$folderNode = $this->userFolder->get($sabreNode->getPath());
- $childShares = $this->getSharesTypesInFolder($folderNode);
$this->cachedFolders[] = $sabreNode->getPath();
- $this->cachedShareTypes[$folderNode->getId()] = $this->getShareTypes($folderNode);
+ $childShares = $this->getSharesFolder($folderNode);
foreach ($childShares as $id => $shares) {
- $this->cachedShareTypes[$id] = $shares;
+ $this->cachedShares[$id] = $shares;
}
}
$propFind->handle(self::SHARETYPES_PROPERTYNAME, function () use ($sabreNode) {
- 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 [];
- }
- }
+ $shares = $this->getShares($sabreNode);
+
+ $shareTypes = array_unique(array_map(function(IShare $share) {
+ return $share->getShareType();
+ }, $shares));
return new ShareTypeList($shareTypes);
});
+
+ $propFind->handle(self::SHAREES_PROPERTYNAME, function() use ($sabreNode) {
+ $shares = $this->getShares($sabreNode);
+
+ return new ShareeList($shares);
+ });
}
}