From ebd3f14f4c6b9246a90e6600dd6346c3fd4a30c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 11 May 2023 12:22:04 +0200 Subject: [PATCH] fix: Return X-WOPI-Lock when a manual lock from outside exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/Controller/WopiController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index 22de7335..b0cd3def 100755 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -518,7 +518,7 @@ private function getLock(Wopi $wopi): JSONResponse { try { $response = new JSONResponse(); $locks = $this->lockManager->getLocks($wopi->getFileid()); - $existingLock = array_pop($locks); + $existingLock = array_shift($locks); $response->addHeader('X-WOPI-Lock', $existingLock->getToken()); return $response; } catch (NoLockProviderException|PreConditionNotMetException $e) { @@ -671,6 +671,16 @@ public function postFile($fileId, $access_token) { $wopiOverride = $this->request->getHeader('X-WOPI-Override'); if ($this->lockManager->isLockProviderAvailable()) { + $locks = $this->lockManager->getLocks($wopi->getFileid()); + $existingLock = array_shift($locks); + $outsideLocked = $existingLock && $existingLock->getOwner() !== 'officeonline'; + if ($outsideLocked) { + $result = new JSONResponse(); + $result->setStatus(Http::STATUS_CONFLICT); + $result->addHeader('X-WOPI-Lock', $existingLock->getToken()); + $result->addHeader('X-WOPI-LockFailureReason', 'File already locked by ' . $existingLock->getOwner()); + return $result; + } // Currently we do not use the return value of those methods, // as we perform actual WOPI lock token handling through the apps own lock table switch ($wopiOverride) {