Skip to content

Commit 343e823

Browse files
committed
refactor: extract logic to hide mounts and share information
The permission string for directories and files can contain M or S depending if they are respectively coming from a mount or a share. This information is not to be disclosed when the share is a public one. Signed-off-by: Salvatore Martire <[email protected]>
1 parent f892437 commit 343e823

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

apps/dav/lib/Connector/Sabre/FilesPlugin.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use Sabre\HTTP\ResponseInterface;
4141

4242
class FilesPlugin extends ServerPlugin {
43+
4344
// namespace
4445
public const NS_OWNCLOUD = 'http://owncloud.org/ns';
4546
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
@@ -316,12 +317,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
316317
});
317318

318319
$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function () use ($node) {
319-
$perms = $node->getDavPermissions();
320-
if ($this->isPublic) {
321-
// remove mount information
322-
$perms = str_replace(['S', 'M'], '', $perms);
323-
}
324-
return $perms;
320+
return $this->isPublic ? $node->getPublicDavPermissions() : $node->getDavPermissions();
325321
});
326322

327323
$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function () use ($node, $httpRequest) {

apps/dav/lib/Connector/Sabre/Node.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,13 @@ public function getDavPermissions() {
337337
return DavUtil::getDavPermissions($this->info);
338338
}
339339

340+
/**
341+
* Returns the DAV Permissions with share and mount infromation stripped.
342+
*/
343+
public function getPublicDavPermissions(): string {
344+
return str_replace(['S', 'M'], '', $this->getDavPermissions());
345+
}
346+
340347
public function getOwner() {
341348
return $this->info->getOwner();
342349
}

apps/dav/tests/unit/Connector/Sabre/FilesPluginTest.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,12 @@ public function testGetPublicPermissions(): void {
327327

328328
/** @var File&MockObject $node */
329329
$node = $this->createTestNode(File::class);
330-
$node->expects($this->any())
331-
->method('getDavPermissions')
332-
->willReturn('DWCKMSR');
330+
$node->expects($this->once())
331+
->method('getPublicDavPermissions')
332+
->willReturn('DWCKR');
333+
334+
$node->expects($this->never())
335+
->method('getDavPermissions');
333336

334337
$this->plugin->handleGetProperties(
335338
$propFind,

0 commit comments

Comments
 (0)