From d5e9bd8b0bcd72368ad7fa15fbbea9e4216f1f74 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 17 Jun 2026 09:30:35 +0200 Subject: [PATCH] chore(performance): only check permissions when changing content chore(performance): only check permissions when changing content Avoid setting up the file system for read only shares. Also clarify the behavior: Updates are silently dropped as they were before. Previously `stepsToInsert` would always be empty for readonly requests, due to the continue in the loop collecting the steps. So there was no way to trigger the ``` NotPermittedException('Read-only client tries to push steps with changes') ``` Keep this behavior for now so we can backport this commit. Clients on readonly shares regularly push updates to the server to update their awareness state - i.e. let others know they are still around. These requests trigger the addStep function even if they do not actually change the content of the file. Signed-off-by: Max --- lib/Service/DocumentService.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/Service/DocumentService.php b/lib/Service/DocumentService.php index 9f7bbd7f487..2c4dcbd85c1 100644 --- a/lib/Service/DocumentService.php +++ b/lib/Service/DocumentService.php @@ -207,16 +207,11 @@ public function writeDocumentState(int $documentId, string $content): void { */ public function addStep(Document $document, Session $session, array $steps, int $version, ?int $recoveryAttempt, ?string $shareToken): array { $documentId = $session->getDocumentId(); - $file = $this->getFileForSession($session, $shareToken); - $readOnly = $this->isReadOnly($file, $shareToken); $stepsToInsert = []; $stepsIncludeQuery = false; $documentState = null; foreach ($steps as $step) { $message = YjsMessage::fromBase64($step); - if ($readOnly && $message->isUpdate()) { - continue; - } // Filter out query steps as they would just trigger clients to send their steps again if ($message->getYjsMessageType() === YjsMessage::YJS_MESSAGE_SYNC && $message->getYjsSyncType() === YjsMessage::YJS_MESSAGE_SYNC_STEP1) { $stepsIncludeQuery = true; @@ -225,10 +220,10 @@ public function addStep(Document $document, Session $session, array $steps, int } } if (count($stepsToInsert) > 0) { - if ($readOnly) { - throw new NotPermittedException('Read-only client tries to push steps with changes'); + $file = $this->getFileForSession($session, $shareToken); + if (!$this->isReadOnly($file, $shareToken)) { + $this->insertSteps($document, $session, $stepsToInsert); } - $this->insertSteps($document, $session, $stepsToInsert); } // By default, send all steps the user has not received yet.