diff options
author | Julius Härtl <jus@bitgrid.net> | 2022-04-21 13:43:09 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2022-04-21 14:27:44 +0300 |
commit | 5c9225e8864e7b466c50499045d45cfc9573927d (patch) | |
tree | aaffa49bdb3dff9381ba01f882143b7933e3f045 /lib | |
parent | 53d1012f7fb2373e4067b5efc44526175f3ac7f8 (diff) |
Expose lock in the text UI
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Service/ApiService.php | 8 | ||||
-rw-r--r-- | lib/Service/DocumentService.php | 31 |
2 files changed, 33 insertions, 6 deletions
diff --git a/lib/Service/ApiService.php b/lib/Service/ApiService.php index 69712cfbe..289443cc6 100644 --- a/lib/Service/ApiService.php +++ b/lib/Service/ApiService.php @@ -110,6 +110,11 @@ class ApiService { $content = null; } + $lockInfo = $this->documentService->getLockInfo($file); + if ($lockInfo && $lockInfo->getType() === ILock::TYPE_APP && $lockInfo->getOwner() === Application::APP_NAME) { + $lockInfo = null; + } + $isLocked = $this->documentService->lock($fileId); if (!$isLocked) { $readOnly = true; @@ -119,7 +124,8 @@ class ApiService { 'document' => $document, 'session' => $session, 'readOnly' => $readOnly, - 'content' => $content + 'content' => $content, + 'lock' => $lockInfo, ]); } diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 319412f1d..ee82baf82 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -30,6 +30,8 @@ use \InvalidArgumentException; use OCA\Text\AppInfo\Application; use OCA\Text\Db\Session; use OCA\Text\Db\SessionMapper; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; use OCP\DirectEditing\IManager; use OCP\Files\Lock\ILock; use OCP\Files\Lock\ILockManager; @@ -256,20 +258,19 @@ class DocumentService { } /** + * @param $file * @param $documentId * @param $version * @param $autoaveDocument * @param bool $force * @param bool $manualSave * @param null $shareToken + * @param null $filePath * @return Document * @throws DocumentSaveConflictException * @throws DoesNotExistException - * @throws GenericFileException - * @throws InvalidPathException * @throws NotFoundException - * @throws NotPermittedException - * @throws ShareNotFound + * @throws \OCP\DB\Exception */ public function autosave($file, $documentId, $version, $autoaveDocument, $force = false, $manualSave = false, $shareToken = null, $filePath = null): Document { /** @var Document $document */ @@ -442,7 +443,27 @@ class DocumentService { } else { $readOnly = !$file->isUpdateable(); } - return $readOnly; + + $lockInfo = $this->getLockInfo($file); + $isTextLock = ( + $lockInfo && $lockInfo->getType() === ILock::TYPE_APP && $lockInfo->getOwner() === Application::APP_NAME + ); + + if ($isTextLock) { + return $readOnly; + } + + return $readOnly || $lockInfo !== null; + } + + public function getLockInfo($file): ?ILock { + try { + $locks = $this->lockManager->getLocks($file->getId()); + } catch (NoLockProviderException|PreConditionNotMetException $e) { + return null; + } + return array_shift($locks); + } /** |