Skip to content

Commit cdf9368

Browse files
committed
fix: properly expose rename permissions over dav
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent 005b2b0 commit cdf9368

File tree

3 files changed

+29
-23
lines changed

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

140122
/**
@@ -343,7 +325,7 @@ public function getNoteFromShare(?string $user): ?string {
343325
}
344326

345327
public function getDavPermissions(): string {
346-
return DavUtil::getDavPermissions($this->info);
328+
return DavUtil::getDavPermissions($this->info, $this->node->getParent());
347329
}
348330

349331
/**

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()) {
@@ -52,7 +53,10 @@ public static function getDavPermissions(FileInfo $info): string {
5253
$p .= 'D';
5354
}
5455
if ($permissions & Constants::PERMISSION_UPDATE) {
55-
$p .= 'NV'; // Renameable, Movable
56+
$p .= 'V'; // Movable
57+
}
58+
if (self::canRename($info, $parent)) {
59+
$p .= 'N'; // Renamable
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)