Files
Lauri Ojansivu 69eeb00c84 Let a rule have several triggers (any fires it) and several actions (in order).
Maintainer decision for #4294 and #2953: a rule keeps its own trigger and
action and may add up to ten more of each. It fires when any of its
triggers fires - once per activity, even when several match - and runs its
actions in order, its own first. Rule details lists the extra parts with
Add another trigger / Add another action and Remove; the new
rules.addPart/removePart methods keep the board-admin and cross-board
destination checks of rules.createRule and refuse a button as an extra
trigger.

Ordinary, scheduled and button rules, the durable Sync rule plan, rule
History (snapshot, part edits and restore), deletion, board copy, WeKan
export/import, the rules JSON export/import, the REST representation and
the admin rules report all handle every part. Two rule-engine test
harnesses now receive the new helpers they evaluate.

New strings are in en.i18n.json, pending translation.

Thanks to xet7 !

Fixes #2953,
2026-09-29 14:34:18 +03:00

25 lines
1.2 KiB
JavaScript

// #2713: shared by every trigger/action "create the rule" button across
// boardActions.js, cardActions.js, checklistActions.js and mailActions.js.
// When the wizard was opened through rulesList's "Edit" button, the data
// context carries a `ruleId` ReactiveVar holding the rule being edited; this
// updates that rule's trigger/action IN PLACE (server/rulesButton.js ->
// rules.updateRule) instead of creating a brand-new rule. Otherwise it falls
// back to the normal create path (rules.createRule), same as before.
export function saveRuleTriggerAction(boardId, ruleIdVar, ruleName, trigger, actionDoc) {
// #4294: "Add another action" on a rule's details adds this action to that
// rule instead of creating or editing a rule (see rulesMain.js).
const adding = Session.get('rulesAddingPart');
if (adding && adding.kind === 'action') {
Session.set('rulesAddingPart', null);
Meteor.call('rules.addPart', adding.ruleId, 'action', actionDoc);
return;
}
const ruleId =
ruleIdVar && typeof ruleIdVar.get === 'function' ? ruleIdVar.get() : null;
if (ruleId) {
Meteor.call('rules.updateRule', ruleId, ruleName, trigger, actionDoc);
} else {
Meteor.call('rules.createRule', boardId, ruleName, trigger, actionDoc);
}
}