Skip to content
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
13 changes: 11 additions & 2 deletions lib/Middleware/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use OC\User\NoUserException;
use OCA\Text\Controller\ISessionAwareController;
use OCA\Text\Db\Document;
use OCA\Text\Exception\AccountDisabledException;
use OCA\Text\Exception\InvalidDocumentBaseVersionEtagException;
use OCA\Text\Exception\InvalidSessionException;
Expand All @@ -31,6 +32,7 @@
use ReflectionException;

class SessionMiddleware extends Middleware {
private ?Document $document = null;

public function __construct(
private readonly IRequest $request,
Expand Down Expand Up @@ -80,7 +82,7 @@ private function assertDocumentBaseVersionEtag(): void {
$documentId = (int)$this->request->getParam('documentId');
$baseVersionEtag = $this->request->getParam('baseVersionEtag');

$document = $this->documentService->getDocument($documentId);
$document = $this->getDocument($documentId);
if ($baseVersionEtag && $document?->getBaseVersionEtag() !== $baseVersionEtag) {
throw new InvalidDocumentBaseVersionEtagException();
}
Expand Down Expand Up @@ -108,7 +110,7 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
}
}

$document = $this->documentService->getDocument($documentId);
$document = $this->getDocument($documentId);
if (!$document) {
throw new InvalidSessionException();
}
Expand Down Expand Up @@ -147,6 +149,13 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
throw new InvalidSessionException();
}

private function getDocument(int $documentId): ?Document {
if ($this->document?->getId() !== $documentId) {
$this->document = $this->documentService->getDocument($documentId);
}
return $this->document;
}

public function afterException($controller, $methodName, \Exception $exception): JSONResponse|Response {
if ($exception instanceof InvalidDocumentBaseVersionEtagException) {
return new JSONResponse(['error' => $this->l10n->t('Editing session has expired. Please reload the page.')], Http::STATUS_PRECONDITION_FAILED);
Expand Down
Loading