From 5206ec19b076c99ac9d48a647918395ee8515a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 2 Mar 2021 11:54:57 +0100 Subject: [PATCH] Use write permission when possible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/DocumentService.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 918fe31df2d..edc54e0b613 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -405,7 +405,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); } /**