Skip to content

Commit cfbeca6

Browse files
committed
fix: properly expose rename permissions over dav
Signed-off-by: Robin Appelman <[email protected]>
1 parent fcf21be commit cfbeca6

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

apps/dav/lib/BulkUpload/BulkUploadPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
7676
'error' => false,
7777
'etag' => $node->getETag(),
7878
'fileid' => DavUtil::getDavFileId($node->getId()),
79-
'permissions' => DavUtil::getDavPermissions($node),
79+
'permissions' => DavUtil::getDavPermissions($node, $node->getParent()),
8080
];
8181
} catch (\Exception $e) {
8282
$this->logger->error($e->getMessage(), ['path' => $headers['x-file-path']]);

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,25 +115,7 @@ public function getPath() {
115115
* Check if this node can be renamed
116116
*/
117117
public function canRename(): bool {
118-
// the root of a movable mountpoint can be renamed regardless of the file permissions
119-
if ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === '') {
120-
return true;
121-
}
122-
123-
// we allow renaming the file if either the file has update permissions
124-
if ($this->info->isUpdateable()) {
125-
return true;
126-
}
127-
128-
// or the file can be deleted and the parent has create permissions
129-
[$parentPath,] = \Sabre\Uri\split($this->path);
130-
if ($parentPath === null) {
131-
// can't rename the users home
132-
return false;
133-
}
134-
135-
$parent = $this->node->getParent();
136-
return $this->info->isDeletable() && $parent->isCreatable();
118+
return DavUtil::canRename($this->node, $this->node->getParent());
137119
}
138120

139121
/**
@@ -365,11 +347,8 @@ public function getNoteFromShare(?string $user): ?string {
365347
return null;
366348
}
367349

368-
/**
369-
* @return string
370-
*/
371-
public function getDavPermissions() {
372-
return DavUtil::getDavPermissions($this->info);
350+
public function getDavPermissions(): string {
351+
return DavUtil::getDavPermissions($this->info, $this->node->getParent());
373352
}
374353

375354
public function getOwner() {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function davPermissionsProvider(): array {
4242
[Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL, true, '' , 'SRMGDNVW'],
4343
[Constants::PERMISSION_ALL, 'file', true, Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, true, '' , 'SRMGDNV'],
4444
[Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, 'file', true, Constants::PERMISSION_ALL, false, 'test', 'SGDNVW'],
45-
[Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGD'],
45+
[Constants::PERMISSION_ALL - Constants::PERMISSION_UPDATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDN'],
4646
[Constants::PERMISSION_ALL - Constants::PERMISSION_DELETE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGNVW'],
4747
[Constants::PERMISSION_ALL - Constants::PERMISSION_CREATE, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RGDNVW'],
4848
[Constants::PERMISSION_ALL - Constants::PERMISSION_READ, 'file', false, Constants::PERMISSION_ALL, false, 'test', 'RDNVW'],

lib/public/Files/DavUtil.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace OCP\Files;
99

10+
use OC\Files\Mount\MoveableMount;
1011
use OCP\Constants;
1112
use OCP\Files\Mount\IMovableMount;
1213

@@ -33,7 +34,7 @@ public static function getDavFileId(int $id): string {
3334
*
3435
* @since 25.0.0
3536
*/
36-
public static function getDavPermissions(FileInfo $info): string {
37+
public static function getDavPermissions(FileInfo $info, ?FileInfo $parent = null): string {
3738
$permissions = $info->getPermissions();
3839
$p = '';
3940
if ($info->isShared()) {
@@ -51,8 +52,17 @@ public static function getDavPermissions(FileInfo $info): string {
5152
if ($permissions & Constants::PERMISSION_DELETE) {
5253
$p .= 'D';
5354
}
54-
if ($permissions & Constants::PERMISSION_UPDATE) {
55-
$p .= 'NV'; // Renameable, Movable
55+
if ($parent) {
56+
if (self::canRename($info, $parent)) {
57+
$p .= 'N'; // Renamable
58+
}
59+
if ($permissions & Constants::PERMISSION_UPDATE) {
60+
$p .= 'V'; // Movable
61+
}
62+
} else {
63+
if ($permissions & Constants::PERMISSION_UPDATE) {
64+
$p .= 'NV'; // Renamable, Movable
65+
}
5666
}
5767

5868
// since we always add update permissions for the root of movable mounts
@@ -76,4 +86,24 @@ public static function getDavPermissions(FileInfo $info): string {
7686
}
7787
return $p;
7888
}
89+
90+
public static function canRename(FileInfo $info, FileInfo $parent): bool {
91+
// the root of a movable mountpoint can be renamed regardless of the file permissions
92+
if ($info->getMountPoint() instanceof MoveableMount && $info->getInternalPath() === '') {
93+
return true;
94+
}
95+
96+
// we allow renaming the file if either the file has update permissions
97+
if ($info->isUpdateable()) {
98+
return true;
99+
}
100+
101+
// or the file can be deleted and the parent has create permissions
102+
if ($info->getStorage() instanceof IHomeStorage && $info->getInternalPath() === 'files') {
103+
// can't rename the users home
104+
return false;
105+
}
106+
107+
return $info->isDeletable() && $parent->isCreatable();
108+
}
79109
}

0 commit comments

Comments
 (0)