Files
wekan/server/notifications/prepareDelivery.js
T
Lauri Ojansivu 2df3e9a8b7 Deliver board-level activities durably: a rule's new swimlane and cross-board moves.
Durable delivery identified every activity by a card and a list, so a
rule's createSwimlane activity, which names neither, and a cross-board
move's moveCardBoard activity, which names no list, were written once
but delivered the ordinary way: their notifications and webhooks were
not replayed after a crash. Durable delivery now takes activities
without a list, and without a card. Recipients and webhook senders are
checked against the board, plus the card when one is named. A card or
list the activity does not name is refused. An assigned-only member
never receives a board-level event, since its scope cannot be checked
against their assignments. The rule stage has nothing to run for these
types, because no trigger exists for them, and it refuses a list-less
activity whose type has one.

Thanks to xet7 !
2026-10-03 00:08:13 +03:00

35 lines
2.1 KiB
JavaScript

import { prepareActivityNotification } from '/server/models/activities';
import { prepareActivityEmail } from '/server/notifications/email';
import { prepareTrayNotification } from '/server/notifications/profile';
const { EJSON } = require('bson');
const { prepareNotificationPlan, notificationActivityIdentity } = require('/server/lib/syncNotificationPlan');
// Internal Sync preparation: share ordinary watcher/mention/mute selection and
// service preference/rendering logic after the card mutation is confirmed.
// Ordinary helpers read the resulting card. No activity, tray or outbox write occurs.
// The caller persists this plan and supplies fresh permission checks on replay.
export async function prepareActivityDeliveryPlan({ activity, assertCurrent }) {
if (typeof assertCurrent !== 'function') throw new Error('sync-notification-guard-required');
const saved = EJSON.parse(EJSON.stringify(activity), { relaxed: true });
notificationActivityIdentity(saved);
await assertCurrent();
const context = await prepareActivityNotification(saved.userId, saved);
await assertCurrent();
// The card is in the activity's list, or where the activity's own rules
// moved it - they ran before this stage (storedRulePlans.js activityCardNow).
const moved = async () => (context.card.boardId !== saved.boardId || context.card.listId !== saved.listId) &&
!(await require('/server/notifications/storedRulePlans').activityCardNow(saved));
if (context && (context.board?._id !== saved.boardId || context.card?._id !== saved.cardId ||
(saved.listId ? await moved() : !!context.card && context.card.boardId !== saved.boardId))) {
throw new Error('sync-notification-context-unavailable');
}
const users = new Map((context?.users || []).map(user => [user._id, user]));
const plan = await prepareNotificationPlan({ activity: saved, recipientIds: [...users.keys()],
getUser: async id => users.get(id),
prepareEmail: user => prepareActivityEmail(user, context.title, context.description, context.params),
prepareTray: user => prepareTrayNotification(user, context.params),
});
await assertCurrent();
return plan;
}