Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2015-11-17 15:40:25 +0300
committerThomas Müller <thomas.mueller@tmit.eu>2015-11-17 15:40:25 +0300
commit20c251a5755f7c218df2cafe9d5ba64036096815 (patch)
tree395609ac9ccc634987e4adbfca689fcab6f20832
parent74ce6d29e1dc2638911e52c2486e55b64538d6d8 (diff)
parentd62f410f92f32008edd3d127b1005b4754a54319 (diff)
Merge pull request #20188 from owncloud/webdav-exposeshareowner
Expose share owner id and display name via files webdav
-rw-r--r--apps/dav/lib/connector/sabre/filesplugin.php14
-rw-r--r--apps/dav/lib/connector/sabre/node.php4
-rw-r--r--apps/dav/tests/unit/connector/sabre/filesplugin.php50
-rw-r--r--lib/public/files/node.php8
-rw-r--r--lib/public/files/storage.php6
5 files changed, 82 insertions, 0 deletions
diff --git a/apps/dav/lib/connector/sabre/filesplugin.php b/apps/dav/lib/connector/sabre/filesplugin.php
index 61b5360cac1..00d5d2cd725 100644
--- a/apps/dav/lib/connector/sabre/filesplugin.php
+++ b/apps/dav/lib/connector/sabre/filesplugin.php
@@ -42,6 +42,8 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
const GETETAG_PROPERTYNAME = '{DAV:}getetag';
const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
+ const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
+ const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
/**
* Reference to main server object
@@ -99,6 +101,8 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
+ $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
+ $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
$allowedProperties = ['{DAV:}getetag'];
@@ -201,6 +205,16 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin {
return $node->getSize();
});
}
+
+ $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
+ $owner = $node->getOwner();
+ return $owner->getUID();
+ });
+ $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
+ $owner = $node->getOwner();
+ $displayName = $owner->getDisplayName();
+ return $displayName;
+ });
}
/**
diff --git a/apps/dav/lib/connector/sabre/node.php b/apps/dav/lib/connector/sabre/node.php
index 814aaceb077..ae7dd51fc94 100644
--- a/apps/dav/lib/connector/sabre/node.php
+++ b/apps/dav/lib/connector/sabre/node.php
@@ -238,6 +238,10 @@ abstract class Node implements \Sabre\DAV\INode {
return $p;
}
+ public function getOwner() {
+ return $this->info->getOwner();
+ }
+
protected function verifyPath() {
try {
$fileName = basename($this->info->getPath());
diff --git a/apps/dav/tests/unit/connector/sabre/filesplugin.php b/apps/dav/tests/unit/connector/sabre/filesplugin.php
index f3c862941c0..55c8dd49e17 100644
--- a/apps/dav/tests/unit/connector/sabre/filesplugin.php
+++ b/apps/dav/tests/unit/connector/sabre/filesplugin.php
@@ -15,6 +15,8 @@ class FilesPlugin extends \Test\TestCase {
const PERMISSIONS_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::PERMISSIONS_PROPERTYNAME;
const LASTMODIFIED_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::LASTMODIFIED_PROPERTYNAME;
const DOWNLOADURL_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::DOWNLOADURL_PROPERTYNAME;
+ const OWNER_ID_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_ID_PROPERTYNAME;
+ const OWNER_DISPLAY_NAME_PROPERTYNAME = \OCA\DAV\Connector\Sabre\FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME;
/**
* @var \Sabre\DAV\Server
@@ -91,13 +93,29 @@ class FilesPlugin extends \Test\TestCase {
self::SIZE_PROPERTYNAME,
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
+ self::OWNER_ID_PROPERTYNAME,
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME
),
0
);
+ $user = $this->getMockBuilder('\OC\User\User')
+ ->disableOriginalConstructor()->getMock();
+ $user
+ ->expects($this->once())
+ ->method('getUID')
+ ->will($this->returnValue('foo'));
+ $user
+ ->expects($this->once())
+ ->method('getDisplayName')
+ ->will($this->returnValue('M. Foo'));
+
$node->expects($this->once())
->method('getDirectDownload')
->will($this->returnValue(array('url' => 'http://example.com/')));
+ $node->expects($this->exactly(2))
+ ->method('getOwner')
+ ->will($this->returnValue($user));
$node->expects($this->never())
->method('getSize');
@@ -111,6 +129,8 @@ class FilesPlugin extends \Test\TestCase {
$this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME));
$this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME));
$this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME));
+ $this->assertEquals('foo', $propFind->get(self::OWNER_ID_PROPERTYNAME));
+ $this->assertEquals('M. Foo', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
$this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
}
@@ -207,6 +227,36 @@ class FilesPlugin extends \Test\TestCase {
$this->assertEquals(200, $result[self::GETETAG_PROPERTYNAME]);
}
+ public function testUpdatePropsForbidden() {
+ $node = $this->createTestNode('\OCA\DAV\Connector\Sabre\File');
+
+ $propPatch = new \Sabre\DAV\PropPatch(array(
+ self::OWNER_ID_PROPERTYNAME => 'user2',
+ self::OWNER_DISPLAY_NAME_PROPERTYNAME => 'User Two',
+ self::FILEID_PROPERTYNAME => 12345,
+ self::PERMISSIONS_PROPERTYNAME => 'C',
+ self::SIZE_PROPERTYNAME => 123,
+ self::DOWNLOADURL_PROPERTYNAME => 'http://example.com/',
+ ));
+
+ $this->plugin->handleUpdateProperties(
+ '/dummypath',
+ $propPatch
+ );
+
+ $propPatch->commit();
+
+ $this->assertEmpty($propPatch->getRemainingMutations());
+
+ $result = $propPatch->getResult();
+ $this->assertEquals(403, $result[self::OWNER_ID_PROPERTYNAME]);
+ $this->assertEquals(403, $result[self::OWNER_DISPLAY_NAME_PROPERTYNAME]);
+ $this->assertEquals(403, $result[self::FILEID_PROPERTYNAME]);
+ $this->assertEquals(403, $result[self::PERMISSIONS_PROPERTYNAME]);
+ $this->assertEquals(403, $result[self::SIZE_PROPERTYNAME]);
+ $this->assertEquals(403, $result[self::DOWNLOADURL_PROPERTYNAME]);
+ }
+
/**
* Testcase from https://github.com/owncloud/core/issues/5251
*
diff --git a/lib/public/files/node.php b/lib/public/files/node.php
index aa1115f8c28..866b9b6f61f 100644
--- a/lib/public/files/node.php
+++ b/lib/public/files/node.php
@@ -225,4 +225,12 @@ interface Node extends FileInfo {
* @since 6.0.0
*/
public function getName();
+
+ /**
+ * Get the file owner
+ *
+ * @since 9.0.0
+ * @return string
+ */
+ public function getOwner();
}
diff --git a/lib/public/files/storage.php b/lib/public/files/storage.php
index 1c520026777..c42a2d05bc3 100644
--- a/lib/public/files/storage.php
+++ b/lib/public/files/storage.php
@@ -462,4 +462,10 @@ interface Storage {
* @param bool $isAvailable
*/
public function setAvailability($isAvailable);
+
+ /**
+ * @param $path path for which to retrieve the owner
+ * @since 9.0.0
+ */
+ public function getOwner($path);
}