Skip to content

Commit

Permalink
fix: accept current user filelock
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
ArtificialOwl authored and juliusknorr committed Oct 19, 2023
1 parent 3ae186e commit 0a5afd4
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion lib/Controller/WopiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ public function checkFileInfo($fileId, $access_token) {
$user = $this->userManager->get($wopi->getEditorUid());
$userDisplayName = $user !== null && !$isPublic ? $user->getDisplayName() : $wopi->getGuestDisplayname();
$isVersion = $version !== '0';

// If the file is locked manually by a user we want to open it read only for all others
$canWriteThroughLock = true;
try {
$locks = $this->lockManager->getLocks($wopi->getFileid());
$canWriteThroughLock = count($locks) > 0 && $locks[0]->getType() === ILock::TYPE_USER && $locks[0]->getOwner() !== $wopi->getEditorUid() ? false : true;
} catch (NoLockProviderException|PreConditionNotMetException) {
}

$response = [
'BaseFileName' => $file->getName(),
'Size' => $file->getSize(),
Expand All @@ -206,7 +215,7 @@ public function checkFileInfo($fileId, $access_token) {
'UserFriendlyName' => $userDisplayName,
'UserExtraInfo' => [],
'UserPrivateInfo' => [],
'UserCanWrite' => (bool)$wopi->getCanwrite(),
'UserCanWrite' => $canWriteThroughLock && (bool)$wopi->getCanwrite(),
'UserCanNotWriteRelative' => $isPublic || $this->encryptionManager->isEnabled() || $wopi->getHideDownload(),
'PostMessageOrigin' => $wopi->getServerHost(),
'LastModifiedTime' => Helper::toISO8601($file->getMTime()),
Expand Down Expand Up @@ -710,6 +719,11 @@ private function lock(Wopi $wopi, string $lock): JSONResponse {
} catch (NoLockProviderException|PreConditionNotMetException $e) {
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
} catch (OwnerLockedException $e) {
// If a file is manually locked by a user we want to all this user to still perform a WOPI lock and write
if ($e->getLock()->getType() === ILock::TYPE_USER && $e->getLock()->getOwner() === $wopi->getEditorUid()) {
return new JSONResponse();
}

return new JSONResponse([], Http::STATUS_LOCKED);
} catch (\Exception $e) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
Expand All @@ -724,6 +738,11 @@ private function unlock(Wopi $wopi, string $lock): JSONResponse {
));
return new JSONResponse();
} catch (NoLockProviderException|PreConditionNotMetException $e) {
$locks = $this->lockManager->getLocks($wopi->getFileid());
$canWriteThroughLock = count($locks) > 0 && $locks[0]->getType() === ILock::TYPE_USER && $locks[0]->getOwner() !== $wopi->getEditorUid() ? false : true;
if ($canWriteThroughLock) {
return new JSONResponse();
}
return new JSONResponse([], Http::STATUS_BAD_REQUEST);
} catch (\Exception $e) {
return new JSONResponse([], Http::STATUS_INTERNAL_SERVER_ERROR);
Expand Down

0 comments on commit 0a5afd4

Please sign in to comment.