diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 9bff1cdcf94..8a69feeaa0c 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -409,7 +409,13 @@ public function getFileById($fileId, $userId = null): Node { throw new NotFoundException(); } - return $files[0]; + // Workaround to always open files with edit permissions if multiple occurences of + // the same file id are in the user home, ideally we should also track the path of the file when opening + usort($files, function (Node $a, Node $b) { + return ($a->getPermissions() & Constants::PERMISSION_UPDATE) < ($b->getPermissions() & Constants::PERMISSION_UPDATE); + }); + + return array_shift($files); } /**