From 56357a26b2682183086b6ca6dbe541b7de87810e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 21 Apr 2022 12:33:56 +0200 Subject: Open files read only if locked MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Service/ApiService.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 850c72c74..69712cfbe 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -28,6 +28,7 @@ namespace OCA\Text\Service; use Exception; use OC\Files\Node\File; +use OCA\Text\AppInfo\Application; use OCA\Text\DocumentHasUnsavedChangesException; use OCA\Text\DocumentSaveConflictException; use OCA\Text\VersionMismatchException; @@ -37,6 +38,7 @@ use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; use OCP\AppFramework\Http\NotFoundResponse; use OCP\Constants; +use OCP\Files\Lock\ILock; use OCP\Files\NotFoundException; use OCP\ILogger; use OCP\IRequest; @@ -63,7 +65,6 @@ class ApiService { public function create($fileId = null, $filePath = null, $token = null, $guestName = null, bool $forceRecreate = false): DataResponse { try { - $readOnly = true; /** @var File $file */ if ($token) { $file = $this->documentService->getFileByShareToken($token, $this->request->getParam('filePath')); @@ -77,19 +78,14 @@ class ApiService { } catch (NotFoundException $e) { return new DataResponse([], Http::STATUS_NOT_FOUND); } - - try { - $this->documentService->checkSharePermissions($token, Constants::PERMISSION_UPDATE); - $readOnly = false; - } catch (NotFoundException $e) { - } } elseif ($fileId) { $file = $this->documentService->getFileById($fileId); - $readOnly = !$file->isUpdateable(); } else { return new DataResponse('No valid file argument provided', 500); } + $readOnly = $this->documentService->isReadOnly($file, $token); + $this->sessionService->removeInactiveSessions($file->getId()); $activeSessions = $this->sessionService->getActiveSessions($file->getId()); if ($forceRecreate || count($activeSessions) === 0) { -- cgit v1.2.3