Merge pull request #3458 from jrsupplee/issue-2924

Issue 2924: Rules not copied during board copy
This commit is contained in:
Lauri Ojansivu 2021-01-22 16:57:18 +02:00 committed by GitHub
commit 1971037049
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 80 additions and 8 deletions

View file

@ -508,6 +508,7 @@ Boards.helpers({
copy() {
const oldId = this._id;
delete this._id;
delete this.slug;
const _id = Boards.insert(this);
// Copy all swimlanes in board
@ -537,7 +538,52 @@ Boards.helpers({
},
});
});
// copy rules, actions, and triggers
const actionsMap = {};
Actions.find({ boardId: oldId }).forEach(action => {
const id = action._id;
delete action._id;
action.boardId = _id;
actionsMap[id] = Actions.insert(action);
});
const triggersMap = {};
Triggers.find({ boardId: oldId }).forEach(trigger => {
const id = trigger._id;
delete trigger._id;
trigger.boardId = _id;
triggersMap[id] = Triggers.insert(trigger);
});
Rules.find({ boardId: oldId }).forEach(rule => {
delete rule._id;
rule.boardId = _id;
rule.actionId = actionsMap[rule.actionId];
rule.triggerId = triggersMap[rule.triggerId];
Rules.insert(rule);
});
},
/**
* Return a unique title based on the current title
*
* @returns {string|null}
*/
copyTitle() {
const m = this.title.match(/^(?<title>.*?)\s*(\[(?<num>\d+)]\s*$|\s*$)/);
const title = m.groups.title;
let num = 0;
Boards.find({ title: new RegExp(`^${title}\\s*\\[\\d+]\\s*$`) }).forEach(
board => {
const m = board.title.match(/^(?<title>.*?)\s*\[(?<num>\d+)]\s*$/);
if (m) {
const n = parseInt(m.groups.num, 10);
num = num < n ? n : num;
}
},
);
return `${title} [${num + 1}]`;
},
/**
* Is supplied user authorized to view this board?
*/