feat: check permissions in realtime code and frontend

Signed-off-by: Philip Molares <philip.molares@udo.edu>
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
Philip Molares 2023-03-26 14:51:18 +02:00 committed by Tilman Vatteroth
parent 24f1b2a361
commit c2f41118b6
27 changed files with 287 additions and 66 deletions

View file

@ -104,12 +104,14 @@ describe('message transporter', () => {
const yDocSyncAdapterServerTo1 = new YDocSyncServerAdapter(
transporterServerTo1,
docServer
docServer,
true
)
const yDocSyncAdapterServerTo2 = new YDocSyncServerAdapter(
transporterServerTo2,
docServer
docServer,
true
)
const waitForClient1Sync = new Promise<void>((resolve) => {

View file

@ -28,7 +28,7 @@ export abstract class YDocSyncAdapter {
this.yDocUpdateListener = doc.on(
'update',
(update, origin) => {
this.processDocUpdate(update, origin)
this.distributeDocUpdate(update, origin)
},
{
objectify: true
@ -92,7 +92,7 @@ export abstract class YDocSyncAdapter {
const noteContentUpdateListener = this.messageTransporter.on(
MessageType.NOTE_CONTENT_UPDATE,
(payload) => this.doc.applyUpdate(payload.payload, this),
(payload) => this.applyIncomingUpdatePayload(payload.payload),
{ objectify: true }
) as Listener
@ -103,7 +103,11 @@ export abstract class YDocSyncAdapter {
}
}
private processDocUpdate(update: number[], origin: unknown): void {
protected applyIncomingUpdatePayload(update: number[]): void {
this.doc.applyUpdate(update, this)
}
private distributeDocUpdate(update: number[], origin: unknown): void {
if (!this.isSynced() || origin === this) {
return
}

View file

@ -10,9 +10,17 @@ import { YDocSyncAdapter } from './y-doc-sync-adapter.js'
export class YDocSyncServerAdapter extends YDocSyncAdapter {
constructor(
readonly messageTransporter: MessageTransporter,
readonly doc: RealtimeDoc
readonly doc: RealtimeDoc,
readonly acceptEdits: boolean
) {
super(messageTransporter, doc)
this.markAsSynced()
}
protected applyIncomingUpdatePayload(update: number[]): void {
if (!this.acceptEdits) {
return
}
super.applyIncomingUpdatePayload(update)
}
}