Files
wekan/models/lib/featureFlags.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

56 lines
2.4 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import Settings from '/models/settings';
// Synchronously-readable cache of the Admin Panel / Features / Notifications
// toggles (issue #5820). A collection `before.insert` hook (models/activities.js)
// runs in a synchronous context and cannot await a Settings lookup, so the server
// keeps this small cache up to date with a Settings observer and exposes it via a
// plain getter. On the client the flags stay at their defaults (false); the server
// is authoritative for the actual enforcement.
const flags = {
disableActivities: false,
disableNotifications: false,
disableWatch: false,
// Admin Panel / Features / Delete: when true, a Global Admin may PHYSICALLY
// (permanently) delete soft-deleted content. Off by default — ordinary deletes
// are always soft. GDPR/account erasure is a separate path and ignores this.
enablePermanentDelete: false,
// Admin Panel: run rules, notifications and webhooks for changes that
// SCHEDULED Sync makes (server/lib/syncActivation.js). Off by default.
enableSyncCronEffects: false,
};
export function getFeatureFlags() {
return flags;
}
function applyFields(fields) {
if (!fields) return;
if ('disableActivities' in fields) flags.disableActivities = !!fields.disableActivities;
if ('disableNotifications' in fields) flags.disableNotifications = !!fields.disableNotifications;
if ('disableWatch' in fields) flags.disableWatch = !!fields.disableWatch;
if ('enablePermanentDelete' in fields) flags.enablePermanentDelete = !!fields.enablePermanentDelete;
if ('enableSyncCronEffects' in fields) flags.enableSyncCronEffects = !!fields.enableSyncCronEffects;
}
if (Meteor.isServer) {
Meteor.startup(async () => {
// observeChanges' `changed` reports only the changed fields, so applyFields
// merges rather than replaces — correct for the single Settings document.
await Settings.find(
{},
{ fields: { disableActivities: 1, disableNotifications: 1, disableWatch: 1, enablePermanentDelete: 1, enableSyncCronEffects: 1 } },
).observeChangesAsync({
added(id, fields) { applyFields(fields); },
changed(id, fields) { applyFields(fields); },
removed() {
flags.disableActivities = false;
flags.disableNotifications = false;
flags.disableWatch = false;
flags.enablePermanentDelete = false;
flags.enableSyncCronEffects = false;
},
});
});
}