Skip to content

Commit

Permalink
Add "owner-id" and "owner-display-name" Webdav properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry committed Nov 13, 2015
1 parent 84e5b76 commit 607e7fe
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
14 changes: 14 additions & 0 deletions apps/dav/lib/connector/sabre/filesplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -99,6 +101,8 @@ public function initialize(\Sabre\DAV\Server $server) {
$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'];
Expand Down Expand Up @@ -201,6 +205,16 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
return $node->getSize();
});
}

$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
$owner = $node->getOwner();
return $owner;
});
$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
$owner = $node->getOwner();
$displayName = \OC_User::getDisplayName($owner);
return $displayName;
});
}

/**
Expand Down
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->info->getOwner();
}

protected function verifyPath() {
try {
$fileName = basename($this->info->getPath());
Expand Down
39 changes: 39 additions & 0 deletions apps/dav/tests/unit/connector/sabre/filesplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,13 +93,18 @@ public function testGetPropertiesForFile() {
self::SIZE_PROPERTYNAME,
self::PERMISSIONS_PROPERTYNAME,
self::DOWNLOADURL_PROPERTYNAME,
self::OWNER_ID_PROPERTYNAME,
self::OWNER_DISPLAY_NAME_PROPERTYNAME
),
0
);

$node->expects($this->once())
->method('getDirectDownload')
->will($this->returnValue(array('url' => 'http://example.com/')));
$node->expects($this->exactly(2))
->method('getOwner')
->will($this->returnValue('user1'));
$node->expects($this->never())
->method('getSize');

Expand All @@ -111,6 +118,8 @@ public function testGetPropertiesForFile() {
$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('user1', $propFind->get(self::OWNER_ID_PROPERTYNAME));
$this->assertEquals('user1', $propFind->get(self::OWNER_DISPLAY_NAME_PROPERTYNAME));
$this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties());
}

Expand Down Expand Up @@ -207,6 +216,36 @@ public function testUpdateProps() {
$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
*
Expand Down

0 comments on commit 607e7fe

Please sign in to comment.