From 81d58ce46cc47b9d3a7d93882b5291ddac85bea1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Mon, 27 Mar 2023 13:14:03 +0200 Subject: [PATCH] fix: Avoid unlocking too early and fix collaboration in Word 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 | 41 ++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/lib/Controller/WopiController.php b/lib/Controller/WopiController.php index aed1bbf2..22de7335 100755 --- a/lib/Controller/WopiController.php +++ b/lib/Controller/WopiController.php @@ -465,6 +465,14 @@ private function lock(Wopi $wopi): JSONResponse { private function unlock(Wopi $wopi): JSONResponse { try { $wopiLock = $this->request->getHeader('X-WOPI-Lock'); + + // OOS sends UNLOCK with GetCurrentLock-00000000-0000-0000-0000-000000000000 + // instead of GET_LOCK it seems, so we cannot always unlock + $fLock = $this->lockMapper->find($wopi->getFileid()); + if ($fLock->getValue() !== $wopiLock) { + return new JSONResponse(); + } + $this->lockManager->unlock(new LockContext( $this->getFileForWopiToken($wopi), ILock::TYPE_APP, @@ -661,27 +669,36 @@ public function postFile($fileId, $access_token) { } $wopiOverride = $this->request->getHeader('X-WOPI-Override'); + if ($this->lockManager->isLockProviderAvailable()) { + // 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) { case 'LOCK': - return $this->lock($wopi); - case 'UNLOCK': - return $this->unlock($wopi); - case 'REFRESH_LOCK': - return $this->refreshLock($wopi); - case 'GET_LOCK': - return $this->getLock($wopi); - } - } else { - switch ($wopiOverride) { - case 'LOCK': + $this->lock($wopi); + break; case 'UNLOCK': + $this->unlock($wopi); + break; case 'REFRESH_LOCK': + $this->refreshLock($wopi); + break; case 'GET_LOCK': - return $this->fallbackLock($fileId, $access_token); + $this->getLock($wopi); + break; } } + // FIXME: We should merge the fallbackLock method into the above individual methods + // The specific table is still relevant to cover different lock tokens used by OOS + switch ($wopiOverride) { + case 'LOCK': + case 'UNLOCK': + case 'REFRESH_LOCK': + case 'GET_LOCK': + return $this->fallbackLock($fileId, $access_token); + } + $isRenameFile = ($wopiOverride === 'RENAME_FILE'); // Unless the editor is empty (public link) we modify the files as the current editor