Skip to content

Commit 663bb78

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: properly expose rename permissions over dav
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent a4d5fdd commit 663bb78

File tree

4 files changed

+29
-23
lines changed

4 files changed

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

138120
/**

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: 26 additions & 2 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): string {
3738
$permissions = $info->getPermissions();
3839
$p = '';
3940
if ($info->isShared()) {
@@ -51,8 +52,11 @@ public static function getDavPermissions(FileInfo $info): string {
5152
if ($permissions & Constants::PERMISSION_DELETE) {
5253
$p .= 'D';
5354
}
55+
if (self::canRename($info, $parent)) {
56+
$p .= 'N'; // Renamable
57+
}
5458
if ($permissions & Constants::PERMISSION_UPDATE) {
55-
$p .= 'NV'; // Renameable, Movable
59+
$p .= 'V'; // Movable
5660
}
5761

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

0 commit comments

Comments
 (0)