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
34 changes: 30 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,34 @@
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But does this not just mean write permissions to the file?
Do we not need to check the containing folder for update permission?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would be the delete+create case I think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if I share a folder with a file and only allow read+write then recipient still can rename the file inside the folder?
Would this not be unexpected as renaming is destructive if you expect the file to have a specific name?

If that is expected behavior then all good!

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;
}
/** @@psalm-suppress InternalMethod */
$parent = $this->fileView->getFileInfo($parentPath);

Check failure on line 126 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:126: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 +139,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
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.

Loading