From 2c0540c357552d9c5fcb34e109fe1057b3ee1629 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Tue, 22 Jul 2025 16:25:49 +0500 Subject: [PATCH] Remove extra (#9582) Signed-off-by: Denis Bykhov --- .../calendar-resources/src/index.ts | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/server-plugins/calendar-resources/src/index.ts b/server-plugins/calendar-resources/src/index.ts index 4edacbdcbb..044b8f74e6 100644 --- a/server-plugins/calendar-resources/src/index.ts +++ b/server-plugins/calendar-resources/src/index.ts @@ -23,6 +23,7 @@ import core, { DocumentQuery, FindOptions, FindResult, + getDiffUpdate, Hierarchy, PersonId, pickPrimarySocialId, @@ -205,11 +206,11 @@ async function onEventMixin (ctx: TxMixin, control: TriggerControl async function onEventUpdate (ctx: TxUpdateDoc, control: TriggerControl): Promise { const ops = ctx.operations - const { visibility, ...otherOps } = ops + const { visibility, user, ...otherOps } = ops if (Object.keys(otherOps).length === 0) return [] const event = (await control.findAll(control.ctx, calendar.class.Event, { _id: ctx.objectId }, { limit: 1 }))[0] if (event === undefined) return [] - if (ctx.modifiedBy !== core.account.System) { + if (ctx.modifiedBy !== core.account.System && event.access === 'owner') { void sendEventToService(event, 'update', control) } void putEventToQueue(control, 'update', event, ctx.modifiedBy, ops) @@ -233,15 +234,18 @@ async function onEventUpdate (ctx: TxUpdateDoc, control: TriggerControl): res.push(outerTx) } else { newParticipants.delete(person) - const innerTx = control.txFactory.createTxUpdateDoc(ev._class, ev.space, ev._id, { ...otherOps }) - const outerTx = control.txFactory.createTxCollectionCUD( - ev.attachedToClass, - ev.attachedTo, - ev.space, - ev.collection, - innerTx - ) - res.push(outerTx) + const update = getDiffUpdate(ev, otherOps) + if (Object.keys(update).length !== 0) { + const innerTx = control.txFactory.createTxUpdateDoc(ev._class, ev.space, ev._id, update) + const outerTx = control.txFactory.createTxCollectionCUD( + ev.attachedToClass, + ev.attachedTo, + ev.space, + ev.collection, + innerTx + ) + res.push(outerTx) + } } } if (newParticipants.size === 0) return res @@ -355,7 +359,7 @@ async function putEventToQueue ( async function onEventCreate (ctx: TxCreateDoc, control: TriggerControl): Promise { const event = TxProcessor.createDoc2Doc(ctx) - if (ctx.modifiedBy !== core.account.System) { + if (ctx.modifiedBy !== core.account.System && event.access === 'owner') { void sendEventToService(event, 'create', control) } void putEventToQueue(control, 'create', event, ctx.modifiedBy) @@ -395,7 +399,7 @@ async function onRemoveEvent (ctx: TxRemoveDoc, control: TriggerControl): const removed = control.removedMap.get(ctx.objectId) as Event const res: Tx[] = [] if (removed !== undefined) { - if (ctx.modifiedBy !== core.account.System) { + if (ctx.modifiedBy !== core.account.System && removed.access === 'owner') { void sendEventToService(removed, 'delete', control) } void putEventToQueue(control, 'delete', removed, ctx.modifiedBy)