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
fix: Ignore pushes of update steps for read only sessions
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and backportbot[bot] committed Jun 13, 2024
commit 7df27e41d9d3b399e58a57d768842b8529cc8cf5
6 changes: 5 additions & 1 deletion lib/Service/DocumentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,15 @@ public function writeDocumentState(int $documentId, string $content): void {
*/
public function addStep(Document $document, Session $session, array $steps, int $version, ?string $shareToken): array {
$documentId = $session->getDocumentId();
$readOnly = $this->isReadOnly($this->getFileForSession($session, $shareToken), $shareToken);
$stepsToInsert = [];
$querySteps = [];
$newVersion = $version;
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) {
$querySteps[] = $step;
Expand All @@ -233,7 +237,7 @@ public function addStep(Document $document, Session $session, array $steps, int
}
}
if (count($stepsToInsert) > 0) {
if ($this->isReadOnly($this->getFileForSession($session, $shareToken), $shareToken)) {
if ($readOnly) {
throw new NotPermittedException('Read-only client tries to push steps with changes');
}
$newVersion = $this->insertSteps($document, $session, $stepsToInsert);
Expand Down
13 changes: 13 additions & 0 deletions lib/YjsMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,17 @@ public function getYjsSyncType(): int {
return $syncType;
}

/**
* Based on https://github.com/yjs/y-protocols/blob/master/PROTOCOL.md#handling-read-only-users
*/
public function isUpdate(): bool {
if ($this->getYjsMessageType() === self::YJS_MESSAGE_SYNC) {
if (in_array($this->getYjsSyncType(), [self::YJS_MESSAGE_SYNC_STEP2, self::YJS_MESSAGE_SYNC_UPDATE])) {
return true;
}
}

return false;
}

}