Skip to content

Commit

Permalink
Expose share owner is and display name via files webdav
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Oct 30, 2015
1 parent 73d9699 commit 72d318a
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
4 changes: 4 additions & 0 deletions apps/dav/lib/connector/sabre/node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions apps/dav/lib/connector/sabre/serverfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
97 changes: 97 additions & 0 deletions apps/dav/lib/connector/sabre/sharesplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
/**
* @author Vincent Petry <pvince81@owncloud.com>
*
* @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 <http://www.gnu.org/licenses/>
*
*/
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;
});
}
}

0 comments on commit 72d318a

Please sign in to comment.