From 72d318a85c083ba1855d7601bd9d81db76e92aa5 Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Fri, 30 Oct 2015 17:37:17 +0100 Subject: [PATCH] Expose share owner is and display name via files webdav --- apps/dav/lib/connector/sabre/node.php | 4 + .../dav/lib/connector/sabre/serverfactory.php | 1 + apps/dav/lib/connector/sabre/sharesplugin.php | 97 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 apps/dav/lib/connector/sabre/sharesplugin.php diff --git a/apps/dav/lib/connector/sabre/node.php b/apps/dav/lib/connector/sabre/node.php index 814aaceb0770..b5e5879a3ebf 100644 --- a/apps/dav/lib/connector/sabre/node.php +++ b/apps/dav/lib/connector/sabre/node.php @@ -238,6 +238,10 @@ public function getDavPermissions() { return $p; } + public function getOwner() { + return $this->fileView->getOwner($this->path); + } + protected function verifyPath() { try { $fileName = basename($this->info->getPath()); diff --git a/apps/dav/lib/connector/sabre/serverfactory.php b/apps/dav/lib/connector/sabre/serverfactory.php index b62f90ab8026..9b9bb7ff6a44 100644 --- a/apps/dav/lib/connector/sabre/serverfactory.php +++ b/apps/dav/lib/connector/sabre/serverfactory.php @@ -95,6 +95,7 @@ public function createServer($baseUri, $requestUri, BackendInterface $authBacken if($this->userSession->isLoggedIn()) { $server->addPlugin(new \OCA\DAV\Connector\Sabre\TagsPlugin($objectTree, $this->tagManager)); + $server->addPlugin(new \OCA\DAV\Connector\Sabre\SharesPlugin($objectTree)); // custom properties plugin must be the last one $server->addPlugin( new \Sabre\DAV\PropertyStorage\Plugin( diff --git a/apps/dav/lib/connector/sabre/sharesplugin.php b/apps/dav/lib/connector/sabre/sharesplugin.php new file mode 100644 index 000000000000..b58e74e8557d --- /dev/null +++ b/apps/dav/lib/connector/sabre/sharesplugin.php @@ -0,0 +1,97 @@ + + * + * @copyright Copyright (c) 2015, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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, version 3, + * along with this program. If not, see + * + */ +namespace OCA\DAV\Connector\Sabre; + +use \Sabre\DAV\PropFind; +use \Sabre\DAV\PropPatch; + +class SharesPlugin extends \Sabre\DAV\ServerPlugin +{ + + // namespace + const NS_OWNCLOUD = 'http://owncloud.org/ns'; + const SHARE_OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}share-owner-id'; + const SHARE_OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}share-owner-display-name'; + + /** + * Reference to main server object + * + * @var \Sabre\DAV\Server + */ + private $server; + + /** + * @var \Sabre\DAV\Tree + */ + private $tree; + + /** + * @param \Sabre\DAV\Tree $tree tree + */ + public function __construct(\Sabre\DAV\Tree $tree) { + $this->tree = $tree; + } + + /** + * This initializes the plugin. + * + * This function is called by \Sabre\DAV\Server, after + * addPlugin is called. + * + * This method should set up the required event subscriptions. + * + * @param \Sabre\DAV\Server $server + * @return void + */ + public function initialize(\Sabre\DAV\Server $server) { + + $server->xmlNamespaces[self::NS_OWNCLOUD] = 'oc'; + + $this->server = $server; + $this->server->on('propFind', array($this, 'handleGetProperties')); + } + + /** + * Adds share owner to the response, if requested + * + * @param PropFind $propFind + * @param \Sabre\DAV\INode $node + * @return void + */ + public function handleGetProperties( + PropFind $propFind, + \Sabre\DAV\INode $node + ) { + if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) { + return; + } + + $propFind->handle(self::SHARE_OWNER_ID_PROPERTYNAME, function() use ($node) { + $owner = $node->getOwner(); + return $owner; + }); + $propFind->handle(self::SHARE_OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) { + $owner = $node->getOwner(); + $displayName = \OC_User::getDisplayName($owner); + return $displayName; + }); + } +}