From bf66d44f7133daa3af3594212ff0eefc149b495a Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Sun, 30 Mar 2025 22:08:37 +0500 Subject: [PATCH] Fix mixins for calendar event (#8393) Signed-off-by: Denis Bykhov --- .../calendar-resources/src/index.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server-plugins/calendar-resources/src/index.ts b/server-plugins/calendar-resources/src/index.ts index b1bebf0a4e..1a121051cb 100644 --- a/server-plugins/calendar-resources/src/index.ts +++ b/server-plugins/calendar-resources/src/index.ts @@ -197,12 +197,36 @@ async function OnEvent (txes: Tx[], control: TriggerControl): Promise { result.push(...(await onEventUpdate(ctx as TxUpdateDoc, control))) } else if (ctx._class === core.class.TxRemoveDoc) { result.push(...(await onRemoveEvent(ctx as TxRemoveDoc, control))) + } else if (ctx._class === core.class.TxMixin) { + result.push(...(await onEventMixin(ctx as TxMixin, control))) } } return result } +async function onEventMixin (ctx: TxMixin, control: TriggerControl): Promise { + const ops = ctx.attributes + const event = (await control.findAll(control.ctx, calendar.class.Event, { _id: ctx.objectId }, { limit: 1 }))[0] + if (event === undefined) return [] + if (event.access !== 'owner') return [] + const events = await control.findAll(control.ctx, calendar.class.Event, { eventId: event.eventId }) + const res: Tx[] = [] + for (const ev of events) { + if (ev._id === event._id) continue + const innerTx = control.txFactory.createTxMixin(ev._id, ev._class, ev.space, ctx.mixin, { ...ops }) + const outerTx = control.txFactory.createTxCollectionCUD( + ev.attachedToClass, + ev.attachedTo, + ev.space, + ev.collection, + innerTx + ) + res.push(outerTx) + } + return res +} + async function onEventUpdate (ctx: TxUpdateDoc, control: TriggerControl): Promise { const ops = ctx.operations const { visibility, ...otherOps } = ops