mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
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,
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import { ruleForTriggerSelector } from '/models/lib/ruleParts';
|
|
|
|
const Triggers = new Mongo.Collection('triggers');
|
|
|
|
Triggers.before.insert((userId, doc) => {
|
|
doc.createdAt = new Date();
|
|
doc.updatedAt = doc.createdAt;
|
|
});
|
|
|
|
Triggers.before.update((userId, doc, fieldNames, modifier) => {
|
|
// Rule editing replaces documents; never mix replacement fields with $set.
|
|
if (Object.keys(modifier).some(key => key.startsWith('$'))) {
|
|
modifier.$set = modifier.$set || {};
|
|
modifier.$set.updatedAt = new Date();
|
|
} else {
|
|
modifier.createdAt = doc.createdAt || new Date();
|
|
modifier.updatedAt = new Date();
|
|
}
|
|
});
|
|
|
|
Triggers.helpers({
|
|
async rename(description) {
|
|
return await Triggers.updateAsync(this._id, {
|
|
$set: { description },
|
|
});
|
|
},
|
|
|
|
description() {
|
|
return this.desc;
|
|
},
|
|
|
|
getRule() {
|
|
// A trigger may be one of several a rule has (models/lib/ruleParts.js).
|
|
return ReactiveCache.getRule(ruleForTriggerSelector(this._id));
|
|
},
|
|
|
|
fromList() {
|
|
return ReactiveCache.getList(this.fromId);
|
|
},
|
|
|
|
toList() {
|
|
return ReactiveCache.getList(this.toId);
|
|
},
|
|
|
|
findList(title) {
|
|
return ReactiveCache.getList({
|
|
title,
|
|
});
|
|
},
|
|
|
|
labels() {
|
|
const boardLabels = this.board().labels;
|
|
const cardLabels = boardLabels.filter(label => {
|
|
return (this.labelIds || []).includes(label._id);
|
|
});
|
|
return cardLabels;
|
|
},
|
|
});
|
|
|
|
export default Triggers;
|