-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose share owner is and display name via files webdav
- Loading branch information
Vincent Petry
committed
Oct 30, 2015
1 parent
73d9699
commit 72d318a
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
} |