Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow current user lock #3206

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading