summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2016-04-13 17:31:01 +0200
committerBjörn Schießle <schiessle@owncloud.com>2016-04-18 12:02:06 +0200
commit52669d0ea3d687b79a9ee04c6351e6793803ecb4 (patch)
treeb08c1caa21df3a7c89b8c744d2993f8de5199b53 /apps
parentd1d80b4f9e3ddfc0e2dd509d8cb96a77251ce1db (diff)
downloadnextcloud-server-52669d0ea3d687b79a9ee04c6351e6793803ecb4.tar.gz
nextcloud-server-52669d0ea3d687b79a9ee04c6351e6793803ecb4.zip
return correct share permissions on propfind
Diffstat (limited to 'apps')
-rw-r--r--apps/dav/lib/connector/sabre/filesplugin.php8
-rw-r--r--apps/dav/lib/connector/sabre/node.php29
-rw-r--r--apps/dav/tests/unit/connector/sabre/node.php91
3 files changed, 88 insertions, 40 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php
index 686d0863f91..bd00a7c9930 100644
--- a/apps/dav/lib/connector/sabre/filesplugin.php
+++ b/apps/dav/lib/connector/sabre/filesplugin.php
@@ -236,6 +236,8 @@ class FilesPlugin extends ServerPlugin {
*/
public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
+ $httpRequest = $this->server->httpRequest;
+
if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
@@ -255,8 +257,10 @@ class FilesPlugin extends ServerPlugin {
return $perms;
});
- $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node) {
- return $node->getSharePermissions();
+ $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
+ return $node->getSharePermissions(
+ $httpRequest->getRawServerValue('PHP_AUTH_USER')
+ );
});
$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
diff --git a/apps/dav/lib/connector/sabre/node.php b/apps/dav/lib/connector/sabre/node.php
index eaba6713992..edb0ad82f41 100644
--- a/apps/dav/lib/connector/sabre/node.php
+++ b/apps/dav/lib/connector/sabre/node.php
@@ -32,6 +32,8 @@ namespace OCA\DAV\Connector\Sabre;
use OC\Files\Mount\MoveableMount;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
+use OCP\Share\Exceptions\ShareNotFound;
+use OCP\Share\IManager;
abstract class Node implements \Sabre\DAV\INode {
@@ -61,15 +63,26 @@ abstract class Node implements \Sabre\DAV\INode {
protected $info;
/**
+ * @var IManager
+ */
+ protected $shareManager;
+
+ /**
* Sets up the node, expects a full path name
*
* @param \OC\Files\View $view
* @param \OCP\Files\FileInfo $info
+ * @param IManager $shareManager
*/
- public function __construct($view, $info) {
+ public function __construct($view, $info, IManager $shareManager = null) {
$this->fileView = $view;
$this->path = $this->fileView->getRelativePath($info->getPath());
$this->info = $info;
+ if ($shareManager) {
+ $this->shareManager = $shareManager;
+ } else {
+ $this->shareManager = \OC::$server->getShareManager();
+ }
}
protected function refreshInfo() {
@@ -215,9 +228,21 @@ abstract class Node implements \Sabre\DAV\INode {
}
/**
+ * @param string $user
* @return int
*/
- public function getSharePermissions() {
+ public function getSharePermissions($user) {
+
+ // check of we access a federated share
+ if ($user !== null) {
+ try {
+ $share = $this->shareManager->getShareByToken($user);
+ return $share->getPermissions();
+ } catch (ShareNotFound $e) {
+ // ignore
+ }
+ }
+
$storage = $this->info->getStorage();
$path = $this->info->getInternalPath();
diff --git a/apps/dav/tests/unit/connector/sabre/node.php b/apps/dav/tests/unit/connector/sabre/node.php
index 6fdf77adc21..f70d1ee3faf 100644
--- a/apps/dav/tests/unit/connector/sabre/node.php
+++ b/apps/dav/tests/unit/connector/sabre/node.php
@@ -23,6 +23,12 @@
namespace OCA\DAV\Tests\Unit\Connector\Sabre;
+/**
+ * Class Node
+ *
+ * @group DB
+ * @package OCA\DAV\Tests\Unit\Connector\Sabre
+ */
class Node extends \Test\TestCase {
public function davPermissionsProvider() {
return array(
@@ -66,52 +72,64 @@ class Node extends \Test\TestCase {
public function sharePermissionsProvider() {
return [
- [\OCP\Files\FileInfo::TYPE_FILE, 1, 1],
- [\OCP\Files\FileInfo::TYPE_FILE, 3, 3],
- [\OCP\Files\FileInfo::TYPE_FILE, 5, 1],
- [\OCP\Files\FileInfo::TYPE_FILE, 7, 3],
- [\OCP\Files\FileInfo::TYPE_FILE, 9, 1],
- [\OCP\Files\FileInfo::TYPE_FILE, 11, 3],
- [\OCP\Files\FileInfo::TYPE_FILE, 13, 1],
- [\OCP\Files\FileInfo::TYPE_FILE, 15, 3],
- [\OCP\Files\FileInfo::TYPE_FILE, 17, 17],
- [\OCP\Files\FileInfo::TYPE_FILE, 19, 19],
- [\OCP\Files\FileInfo::TYPE_FILE, 21, 17],
- [\OCP\Files\FileInfo::TYPE_FILE, 23, 19],
- [\OCP\Files\FileInfo::TYPE_FILE, 25, 17],
- [\OCP\Files\FileInfo::TYPE_FILE, 27, 19],
- [\OCP\Files\FileInfo::TYPE_FILE, 29, 17],
- [\OCP\Files\FileInfo::TYPE_FILE, 30, 18],
- [\OCP\Files\FileInfo::TYPE_FILE, 31, 19],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 1, 1],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 3, 3],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 5, 5],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 7, 7],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 9, 9],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 11, 11],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 13, 13],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 15, 15],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 17, 17],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 19, 19],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 21, 21],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 23, 23],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 25, 25],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 27, 27],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 29, 29],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 30, 30],
- [\OCP\Files\FileInfo::TYPE_FOLDER, 31, 31],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 1, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 3, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 5, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 7, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 9, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 11, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 13, 1],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 15, 3],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 17, 17],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 19, 19],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 21, 17],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 23, 19],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 25, 17],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 27, 19],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 29, 17],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 30, 18],
+ [\OCP\Files\FileInfo::TYPE_FILE, null, 31, 19],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 1, 1],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 3, 3],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 5, 5],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 7, 7],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 9, 9],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 11, 11],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 13, 13],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 15, 15],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 17, 17],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 19, 19],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 21, 21],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 23, 23],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 25, 25],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 27, 27],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 29, 29],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 30, 30],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, null, 31, 31],
+ [\OCP\Files\FileInfo::TYPE_FOLDER, 'shareToken', 7, 7],
];
}
/**
* @dataProvider sharePermissionsProvider
*/
- public function testSharePermissions($type, $permissions, $expected) {
+ public function testSharePermissions($type, $user, $permissions, $expected) {
$storage = $this->getMock('\OCP\Files\Storage');
$storage->method('getPermissions')->willReturn($permissions);
$mountpoint = $this->getMock('\OCP\Files\Mount\IMountPoint');
$mountpoint->method('getMountPoint')->willReturn('myPath');
+ $shareManager = $this->getMockBuilder('OCP\Share\IManager')->disableOriginalConstructor()->getMock();
+ $share = $this->getMockBuilder('OCP\Share\IShare')->disableOriginalConstructor()->getMock();
+
+ if ($user === null) {
+ $shareManager->expects($this->never())->method('getShareByToken');
+ $share->expects($this->never())->method('getPermissions');
+ } else {
+ $shareManager->expects($this->once())->method('getShareByToken')->with($user)
+ ->willReturn($share);
+ $share->expects($this->once())->method('getPermissions')->willReturn($permissions);
+ }
$info = $this->getMockBuilder('\OC\Files\FileInfo')
->disableOriginalConstructor()
@@ -125,6 +143,7 @@ class Node extends \Test\TestCase {
$view = $this->getMock('\OC\Files\View');
$node = new \OCA\DAV\Connector\Sabre\File($view, $info);
- $this->assertEquals($expected, $node->getSharePermissions());
+ $this->invokePrivate($node, 'shareManager', [$shareManager]);
+ $this->assertEquals($expected, $node->getSharePermissions($user));
}
}