Skip to content

Commit 1071a55

Browse files
icewind1991nextcloud-command
authored andcommitted
fix: allow renaming files with just update permissions
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f138461 commit 1071a55

2 files changed

Lines changed: 41 additions & 8 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,19 @@ public function checkMove(string $source, string $target): void {
207207
// First check copyable (move only needs additional delete permission)
208208
$this->checkCopy($source, $target);
209209

210-
// The source needs to be deletable for moving
211-
$sourceNodeFileInfo = $sourceNode->getFileInfo();
212-
if (!$sourceNodeFileInfo->isDeletable()) {
213-
throw new Forbidden($source . ' cannot be deleted');
210+
[$sourceDir] = \Sabre\Uri\split($source);
211+
[$destinationDir, ] = \Sabre\Uri\split($target);
212+
213+
if ($sourceDir === $destinationDir) {
214+
if (!$sourceNode->canRename()) {
215+
throw new Forbidden($source . ' cannot be renamed');
216+
}
217+
} else {
218+
// The source needs to be deletable for moving
219+
$sourceNodeFileInfo = $sourceNode->getFileInfo();
220+
if (!$sourceNodeFileInfo->isDeletable()) {
221+
throw new Forbidden($source . ' cannot be deleted');
222+
}
214223
}
215224

216225
// The source is not allowed to be the parent of the target

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

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use OCP\Server;
2424
use OCP\Share\Exceptions\ShareNotFound;
2525
use OCP\Share\IManager;
26+
use Sabre\DAV\Exception\Forbidden;
2627

2728
abstract class Node implements \Sabre\DAV\INode {
2829
/**
@@ -103,6 +104,31 @@ public function getPath() {
103104
return $this->path;
104105
}
105106

107+
/**
108+
* Check if this node can be renamed
109+
*/
110+
public function canRename(): bool {
111+
// the root of a movable mountpoint can be renamed regardless of the file permissions
112+
if ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === '') {
113+
return true;
114+
}
115+
116+
// we allow renaming the file if either the file has update permissions
117+
if ($this->info->isUpdateable()) {
118+
return true;
119+
}
120+
121+
// or the file can be deleted and the parent has create permissions
122+
[$parentPath,] = \Sabre\Uri\split($this->path);
123+
if ($parentPath === null) {
124+
// can't rename the users home
125+
return false;
126+
}
127+
128+
$parent = $this->node->getParent();
129+
return $this->info->isDeletable() && $parent->isCreatable();
130+
}
131+
106132
/**
107133
* Renames the node
108134
*
@@ -111,10 +137,8 @@ public function getPath() {
111137
* @throws \Sabre\DAV\Exception\Forbidden
112138
*/
113139
public function setName($name) {
114-
// rename is only allowed if the delete privilege is granted
115-
// (basically rename is a copy with delete of the original node)
116-
if (!($this->info->isDeletable() || ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === ''))) {
117-
throw new \Sabre\DAV\Exception\Forbidden();
140+
if (!$this->canRename()) {
141+
throw new Forbidden('');
118142
}
119143

120144
[$parentPath,] = \Sabre\Uri\split($this->path);

0 commit comments

Comments
 (0)