Files
wekan/server/lib/syncActivityDelivery.js
T
Lauri Ojansivu 24536f6cbd Keep Sync's rule, notification and webhook effects off unless enabled.
Maintainer decision of 2026-09-30: running rules, notifications and
webhooks for changes that Sync makes is off by default. A board opts in
with syncEffectsEnabled, and scheduled runs additionally need the new
instance flag enableSyncCronEffects, so an upgrade changes nothing on
its own. Every stored-effect stage (rules, rule email and archive,
notifications, webhooks) now requires its caller to name the trigger,
manual or scheduled, and checks both switches inside its guard with the
board it re-read, so whatever later wires Sync to these stages cannot
skip them. The switches have no interface yet: the stages are not
called by Sync until the History coordination they wait on is done, and
a toggle that does nothing would mislead.

tests/syncActivation.test.cjs pins the decision, the defaults and that
each stage checks it; the full-app suite refuses a missing trigger, a
board that has not opted in and a scheduled run without the instance
switch, writing nothing, then succeeds once both are on. 560 server
tests pass.

Thanks to xet7 !
2026-09-30 02:00:42 +03:00

45 lines
2.2 KiB
JavaScript

'use strict';
const { EJSON } = require('bson');
const { validateSyncEffectPolicy, assertSyncEffectPolicy } = require('./syncEffectPolicy');
const { notificationActivityIdentity, planId: notificationId } = require('./syncNotificationPlan');
const { planId: webhookId } = require('./syncWebhookPlan');
const copy = value => EJSON.parse(EJSON.stringify(value), { relaxed: true });
// These adapters must reconcile their own durable receipts on replay. This
// coordinator never treats activity insertion or a resolved Promise alone as
// acknowledgement. Rules are mandatory even when notifications are disabled.
// `trigger` (manual or scheduled) reaches every stage, which checks the Sync
// activation switches itself (server/lib/syncActivation.js).
async function deliverSyncActivity({ effectId, activity, policy, assertCurrent, readPolicy,
rules, notifications, webhooks, trigger }) {
if (typeof effectId !== 'string' || !/^[a-f0-9]{64}$/.test(effectId) ||
typeof assertCurrent !== 'function' || typeof readPolicy !== 'function') throw new Error('sync-activity-delivery-invalid');
const saved = copy(activity), captured = validateSyncEffectPolicy(policy);
notificationActivityIdentity(saved);
if (typeof saved.listId !== 'string' || !saved.listId || saved.listId.length > 1024) {
throw new Error('sync-activity-delivery-invalid');
}
if (!captured.activities || typeof rules !== 'function' ||
(captured.notifications && (typeof notifications !== 'function' || typeof webhooks !== 'function'))) {
throw new Error('sync-activity-delivery-adapter-required');
}
const guard = async () => {
await assertCurrent();
await assertSyncEffectPolicy(captured, readPolicy);
await assertCurrent();
};
const run = async (adapter, expected) => {
await guard();
const receipt = await adapter({ effectId, activity: copy(saved), policy: { ...captured }, assertCurrent: guard, trigger });
if (receipt !== expected) throw new Error('sync-activity-delivery-unconfirmed');
await guard();
};
await run(rules, effectId);
if (captured.notifications) {
await run(notifications, notificationId(saved._id));
await run(webhooks, webhookId(saved._id));
}
await guard();
return effectId;
}
module.exports = { deliverSyncActivity };