diff --git a/apps/files_sharing/publicwebdav.php b/apps/files_sharing/publicwebdav.php index c0a9dc328d1c83bc9c007c6aceaea511bcd2f431..5bde908109d403099ddd95e26a4a524602cb2416 100644 --- a/apps/files_sharing/publicwebdav.php +++ b/apps/files_sharing/publicwebdav.php @@ -45,7 +45,7 @@ $defaults = new OC_Defaults(); $server->addPlugin(new \Sabre\DAV\Auth\Plugin($authBackend, $defaults->getName())); // FIXME: The following line is a workaround for legacy components relying on being able to send a GET to / $server->addPlugin(new \OC\Connector\Sabre\DummyGetResponsePlugin()); -$server->addPlugin(new \OC\Connector\Sabre\FilesPlugin($objectTree)); +$server->addPlugin(new \OC\Connector\Sabre\FilesPlugin($objectTree, true)); $server->addPlugin(new \OC\Connector\Sabre\MaintenancePlugin(\OC::$server->getConfig())); $server->addPlugin(new \OC\Connector\Sabre\ExceptionLoggerPlugin('webdav', \OC::$server->getLogger())); diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index 608e8cd9017ea6becc9990f6ae41b661ffe279b4..84620f454aa7605172a12e566a134dadc5d2fe8a 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -55,11 +55,20 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { */ private $tree; + /** + * Whether this is public webdav. + * If true, some returned information will be stripped off. + * + * @var bool + */ + private $isPublic; + /** * @param \Sabre\DAV\Tree $tree */ - public function __construct(\Sabre\DAV\Tree $tree) { + public function __construct(\Sabre\DAV\Tree $tree, $isPublic = false) { $this->tree = $tree; + $this->isPublic = $isPublic; } /** @@ -129,7 +138,12 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { }); $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) { - return $node->getDavPermissions(); + $perms = $node->getDavPermissions(); + if ($this->isPublic) { + // remove mount information + $perms = str_replace(['S', 'M'], '', $perms); + } + return $perms; }); $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) { diff --git a/tests/lib/connector/sabre/filesplugin.php b/tests/lib/connector/sabre/filesplugin.php index 54d43d66dda4a6055c961c1ee3bbe3571f01f1a6..a4cf9f7bfb98d38f56909375c4493feaab37f398 100644 --- a/tests/lib/connector/sabre/filesplugin.php +++ b/tests/lib/connector/sabre/filesplugin.php @@ -62,7 +62,7 @@ class FilesPlugin extends \Test\TestCase { ->will($this->returnValue('"abc"')); $node->expects($this->any()) ->method('getDavPermissions') - ->will($this->returnValue('R')); + ->will($this->returnValue('DWCKMSR')); return $node; } @@ -98,11 +98,36 @@ class FilesPlugin extends \Test\TestCase { $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME)); $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME)); $this->assertEquals(null, $propFind->get(self::SIZE_PROPERTYNAME)); - $this->assertEquals('R', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); $this->assertEquals('http://example.com/', $propFind->get(self::DOWNLOADURL_PROPERTYNAME)); $this->assertEquals(array(self::SIZE_PROPERTYNAME), $propFind->get404Properties()); } + public function testGetPublicPermissions() { + $this->plugin = new \OC\Connector\Sabre\FilesPlugin($this->tree, true); + $this->plugin->initialize($this->server); + + $propFind = new \Sabre\DAV\PropFind( + '/dummyPath', + [ + self::PERMISSIONS_PROPERTYNAME, + ], + 0 + ); + + $node = $this->createTestNode('\OC\Connector\Sabre\File'); + $node->expects($this->any()) + ->method('getDavPermissions') + ->will($this->returnValue('DWCKMSR')); + + $this->plugin->handleGetProperties( + $propFind, + $node + ); + + $this->assertEquals('DWCKR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + } + public function testGetPropertiesForDirectory() { $node = $this->createTestNode('\OC\Connector\Sabre\Directory'); @@ -132,7 +157,7 @@ class FilesPlugin extends \Test\TestCase { $this->assertEquals('"abc"', $propFind->get(self::GETETAG_PROPERTYNAME)); $this->assertEquals(123, $propFind->get(self::FILEID_PROPERTYNAME)); $this->assertEquals(1025, $propFind->get(self::SIZE_PROPERTYNAME)); - $this->assertEquals('R', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); + $this->assertEquals('DWCKMSR', $propFind->get(self::PERMISSIONS_PROPERTYNAME)); $this->assertEquals(null, $propFind->get(self::DOWNLOADURL_PROPERTYNAME)); $this->assertEquals(array(self::DOWNLOADURL_PROPERTYNAME), $propFind->get404Properties()); }