Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion cypress/support/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ Cypress.Commands.add('pushAndClose', ({ connection, steps, version, awareness =
cy.log('Race between push and close')
.then(() => {
const push = connection.push({ steps, version, awareness })
.catch(e => e) // handle 403 gracefully
.catch(error => {
// handle 403 gracefully
if (error.response?.status !== 403) {
throw error
}
})
const close = connection.close()
return Promise.all([push, close])
})
Expand Down
29 changes: 20 additions & 9 deletions lib/Service/ApiService.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,20 +194,31 @@ public function push($documentId, $sessionId, $sessionToken, $version, $steps, $
return new DataResponse([], 403);
}
$session = $this->sessionService->getSession($documentId, $sessionId, $sessionToken);
$this->sessionService->updateSessionAwareness($documentId, $sessionId, $sessionToken, $awareness);
if (!$session) {
return new DataResponse([], 403);
}
try {
$this->sessionService->updateSessionAwareness($documentId, $sessionId, $sessionToken, $awareness);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the long term maybe we should only fetch the session once and pass it along on further calls, but for now this change seems good 👍

} catch (DoesNotExistException $e) {
// Session was removed in the meantime. #3875
return new DataResponse([], 403);
}
if (empty($steps)) {
return new DataResponse([]);
}
$file = $this->documentService->getFileForSession($session, $token);
if (!$this->documentService->isReadOnly($file, $token)) {
try {
$result = $this->documentService->addStep($documentId, $sessionId, $steps, $version);
} catch (InvalidArgumentException $e) {
return new DataResponse($e->getMessage(), 422);
}
return new DataResponse($result);
if ($this->documentService->isReadOnly($file, $token)) {
return new DataResponse([], 403);
}
try {
$result = $this->documentService->addStep($documentId, $sessionId, $steps, $version);
} catch (InvalidArgumentException $e) {
return new DataResponse($e->getMessage(), 422);
} catch (DoesNotExistException $e) {
// Session was removed in the meantime. #3875
return new DataResponse([], 403);
}
return new DataResponse([], 403);
return new DataResponse($result);
}

public function sync($documentId, $sessionId, $sessionToken, $version = 0, $autosaveContent = null, $documentState = null, bool $force = false, bool $manualSave = false, $token = null): DataResponse {
Expand Down