Skip to content

Commit

Permalink
Merge pull request #44297 from nextcloud/fix/forbid-tagging-readonly-…
Browse files Browse the repository at this point in the history
…files

Forbid tagging readonly files

Signed-off-by: Louis Chemineau <louis@chmn.me>
  • Loading branch information
artonge committed Mar 21, 2024
1 parent 67b9b34 commit a15c0d6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions apps/files_versions/lib/Versions/LegacyVersionsBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,23 @@ private function currentUserHasPermissions(FileInfo $sourceFile, int $permission
throw new NotFoundException("No user logged in");
}

if ($sourceFile->getOwner()?->getUID() !== $currentUserId) {
$nodes = $this->rootFolder->getUserFolder($currentUserId)->getById($sourceFile->getId());
$sourceFile = array_pop($nodes);
if (!$sourceFile) {
throw new NotFoundException("Version file not accessible by current user");
if ($sourceFile->getOwner()?->getUID() === $currentUserId) {
return ($sourceFile->getPermissions() & $permissions) === $permissions;
}

$nodes = $this->rootFolder->getUserFolder($currentUserId)->getById($sourceFile->getId());

Check notice

Code scanning / Psalm

PossiblyNullArgument Note

Argument 1 of OCP\Files\Folder::getById cannot be null, possibly null value provided

if (count($nodes) === 0) {
throw new NotFoundException("Version file not accessible by current user");
}

foreach ($nodes as $node) {
if (($node->getPermissions() & $permissions) === $permissions) {
return true;
}
}

return ($sourceFile->getPermissions() & $permissions) === $permissions;
return false;
}

public function setMetadataValue(Node $node, int $revision, string $key, string $value): void {
Expand Down

0 comments on commit a15c0d6

Please sign in to comment.