Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,19 @@ public function checkMove(string $source, string $target): void {
// First check copyable (move only needs additional delete permission)
$this->checkCopy($source, $target);

// The source needs to be deletable for moving
$sourceNodeFileInfo = $sourceNode->getFileInfo();
if (!$sourceNodeFileInfo->isDeletable()) {
throw new Forbidden($source . ' cannot be deleted');
[$sourceDir] = \Sabre\Uri\split($source);
[$destinationDir, ] = \Sabre\Uri\split($target);

if ($sourceDir === $destinationDir) {
if (!$sourceNode->canRename()) {
throw new Forbidden($source . ' cannot be renamed');
}
} else {
// The source needs to be deletable for moving
$sourceNodeFileInfo = $sourceNode->getFileInfo();
if (!$sourceNodeFileInfo->isDeletable()) {
throw new Forbidden($source . ' cannot be deleted');
}
}

// The source is not allowed to be the parent of the target
Expand Down
33 changes: 29 additions & 4 deletions apps/dav/lib/Connector/Sabre/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,33 @@
return $this->path;
}

/**
* Check if this node can be renamed
*/
public function canRename(): bool {
// the root of a movable mountpoint can be renamed regardless of the file permissions
if ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === '') {
return true;
}

// we allow renaming the file if either the file has update permissions
if ($this->info->isUpdateable()) {
return true;
}
// or the file can be deleted and the parent has create permissions
[$parentPath,] = \Sabre\Uri\split($this->path);
if ($parentPath === null) {
// can't rename the users home
return false;
}
$parent = $this->fileView->getFileInfo($parentPath);

Check failure on line 125 in apps/dav/lib/Connector/Sabre/Node.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InternalMethod

apps/dav/lib/Connector/Sabre/Node.php:125:30: InternalMethod: The method OC\Files\View::getFileInfo is internal to OC but called from OCA\DAV\Connector\Sabre\Node::canRename (see https://psalm.dev/175)
if ($this->info->isDeletable() && $parent->isCreatable()) {
return true;
}

return false;
}

/**
* Renames the node
*
Expand All @@ -111,10 +138,8 @@
* @throws \Sabre\DAV\Exception\Forbidden
*/
public function setName($name) {
// rename is only allowed if the delete privilege is granted
// (basically rename is a copy with delete of the original node)
if (!($this->info->isDeletable() || ($this->info->getMountPoint() instanceof MoveableMount && $this->info->getInternalPath() === ''))) {
throw new \Sabre\DAV\Exception\Forbidden();
if (!$this->canRename()) {
throw new \Sabre\DAV\Exception\Forbidden('');
}

[$parentPath,] = \Sabre\Uri\split($this->path);
Expand Down
13 changes: 9 additions & 4 deletions apps/files/src/actions/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ export const action = new FileAction({
: filesStore.getNode(dirname(node.source))
const parentPermissions = parentNode?.permissions || Permission.NONE

// Only enable if the node have the delete permission
// and if the parent folder allows creating files
return Boolean(node.permissions & Permission.DELETE)
&& Boolean(parentPermissions & Permission.CREATE)
// Enable if the node has update permissions or the node
// has delete permission and the parent folder allows creating files
return (
(
Boolean(node.permissions & Permission.DELETE)
&& Boolean(parentPermissions & Permission.CREATE)
)
|| Boolean(node.permissions & Permission.UPDATE)
)
},

async exec({ nodes }) {
Expand Down
Loading