Skip to content

Commit 0fa6628

Browse files
icewind1991backportbot[bot]
authored andcommitted
fix: allow renaming files with just update permissions
Signed-off-by: Robin Appelman <robin@icewind.nl>
1 parent f705486 commit 0fa6628

2 files changed

Lines changed: 38 additions & 4 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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,31 @@ public function getPath() {
103103
return $this->path;
104104
}
105105

106+
/**
107+
* Check if this node can be renamed
108+
*/
109+
public function canRename(): bool {
110+
// the root of a movable mountpoint can be renamed regardless of the file permissions
111+
if ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === '') {
112+
return true;
113+
}
114+
115+
// we allow renaming the file if either the file has update permissions
116+
if ($this->info->isUpdateable()) {
117+
return true;
118+
}
119+
120+
// or the file can be deleted and the parent has create permissions
121+
[$parentPath,] = \Sabre\Uri\split($this->path);
122+
if ($parentPath === null) {
123+
// can't rename the users home
124+
return false;
125+
}
126+
127+
$parent = $this->node->getParent();
128+
return $this->info->isDeletable() && $parent->isCreatable();
129+
}
130+
106131
/**
107132
* Renames the node
108133
*

0 commit comments

Comments
 (0)