mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Stored Sync rules bring a card's labels to another board as Card.copy and Card.move do.
Since #1759 a card copied or moved to another board brings its labels: a label that board lacks is created there when the actor is its admin. The stored (durable) rule copyCard, move to another board and move-all onto another board still matched by name only and dropped the rest, so the durable copy or move was no longer the ordinary one - the parity three server tests check - and the card lost a label a direct copy would keep. The durable plans now use the same planCrossBoardLabels with the rule's actor. The labels to create are saved in the command (copy) or move (single move, and each move-all unit), so a replay creates nothing twice: each is pushed only when no label with its id is on that board yet, before the card that names it is written. In a move-all, a label created for one card is that board's label for the next, as when Card.move moves them one by one. Commands saved before this, without the labels, still validate. The server tests now expect the created label, once across a replay, and the ordinary copy or move finding it; the card-move test gains the negative of a mover who is not the new board's admin, where the label is dropped and its activity removed. The command tests cover the new field, its validation and an older command without it. Thanks to xet7 !
This commit is contained in:
1 parent
650849f98d
commit
d1de4a1fe6
8 files changed
+222
-57
No files matched your search
@@ -153,6 +153,41 @@ test('move-all onto another board: one whole move per card, each keeping its sor
|
||||
assert.deepEqual(M.prepareRuleMoveAllBoardCommand({ ...f.context, moves: [], createdAt: new Date(1) }).units, []);
|
||||
});
|
||||
|
||||
test('#1759: the labels the new board lacks are created there before the card names them', async () => {
|
||||
const f = await fixture();
|
||||
const created = { _id: 'local-to', name: 'Local', color: 'blue' };
|
||||
const mapped = { labelIds: ['urgent-to', 'local-to'], createLabels: [created], cardNumber: 41,
|
||||
customFields: [{ _id: 'cf-to', value: 1 }] };
|
||||
const command = f.prepare({ mapped });
|
||||
assert.deepEqual(command.createLabels, [created]);
|
||||
assert.deepEqual(command.after.fields.labelIds, ['urgent-to', 'local-to']);
|
||||
assert.deepEqual(command.effects.labelActivities, [{ _id: 'a1', labelId: 'urgent-to', boardId: 'to' },
|
||||
{ _id: 'a2', labelId: 'local-to', boardId: 'to' }], 'the second activity follows the created label');
|
||||
assert.deepEqual(M.validateRuleMoveBoardCommand(command, f.context), command);
|
||||
// Nothing to create: the command keeps its older shape, without the key.
|
||||
assert.ok(!Object.hasOwn(f.prepare(), 'createLabels'));
|
||||
// Negative: a label to create that the card does not carry, an unnamed one,
|
||||
// or an empty list written into a command, is refused.
|
||||
assert.throws(() => f.prepare({ mapped: { ...mapped, createLabels: [{ _id: 'stray', name: 'Stray', color: 'red' }] } }),
|
||||
/invalid/);
|
||||
assert.throws(() => f.prepare({ mapped: { ...mapped, createLabels: [{ ...created, name: '' }] } }), /invalid/);
|
||||
assert.throws(() => M.validateRuleMoveBoardCommand(resum({ ...command, createLabels: [] }), f.context), /command-invalid/);
|
||||
// Move-all: a unit carries its own labels to create.
|
||||
const all = await fixture([{ _id: 'all', boardId: 'to', actionType: 'moveAllCardsInList', fromListName: 'Doing',
|
||||
listName: 'Done' }]);
|
||||
const unit = { card: all.card, target: { boardId: 'to', listId: 'done', swimlaneId: 'lane-to', sort: null }, mapped,
|
||||
allowedMemberIds: ['actor'], titles: { boardName: 'To', oldBoardName: 'From', swimlaneName: 'Lane' } };
|
||||
const moveAll = M.prepareRuleMoveAllBoardCommand({ ...all.context, moves: [unit], createdAt: new Date(1) });
|
||||
assert.deepEqual(moveAll.units[0].createLabels, [created]);
|
||||
// The runner plans with Card.move's own rule, shares a created label with
|
||||
// the next card of a move-all, and creates each once before the update.
|
||||
const plans = fs.readFileSync(path.join(ROOT, 'server/notifications/storedRulePlans.js'), 'utf8');
|
||||
assert.match(plans, /const labels = crossBoardLabelPlan\(fromBoard, raw\.labelIds, toBoard, actorId\);/);
|
||||
assert.match(plans, /if \(labels\.create\.length\) toBoard\.labels = \[\.\.\.\(toBoard\.labels \|\| \[\]\), \.\.\.labels\.create\];/);
|
||||
assert.match(plans, /await createPlannedLabels\(place\.boardId, command\.createLabels, actor, guard\);\s*await guard\(\);\s*if \(!await raw\.findOne\(ruleMoveBoardAfter\(command\)\)\)/);
|
||||
assert.equal((plans.match(/actorId: plan\.actorId \}\)/g) || []).length >= 2, true, 'both captures pass the actor');
|
||||
});
|
||||
|
||||
test('wiring: move-all onto another board has its runner, and the guard follows its units', () => {
|
||||
const plans = fs.readFileSync(path.join(ROOT, 'server/notifications/storedRulePlans.js'), 'utf8');
|
||||
assert.match(plans, /moveAllCardsInList: \(\{ invocation \}\) => \(isOtherBoardMoveAll\(invocation\.action, plan\.boardId\)\s*\? runStoredSyncRuleMoveAllBoard : runStoredSyncRuleMoveAll\)/);
|
||||
|
||||
Reference in new issue
Block a user