mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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
@@ -94,6 +94,37 @@ test('a copy to another board lives there, with that board\'s labels and custom
|
||||
elsewhere.context), /command-invalid/);
|
||||
});
|
||||
|
||||
test('#1759: the labels another board lacks are created there, once, as Card.copy does', async () => {
|
||||
const elsewhere = await fixture({ boardId: 'other' });
|
||||
const subtaskDocs = [{ title: 'Sub', boardId: 'other', listId: 'next', swimlaneId: 'lane' }];
|
||||
const created = { _id: 'new-local', name: 'Local', color: 'blue' };
|
||||
const crossBoard = { labelIds: ['urgent-there', 'new-local'], createLabels: [created], customFields: [] };
|
||||
const command = elsewhere.prepare({ crossBoard, subtaskDocs });
|
||||
assert.deepEqual(command.createLabels, [created], 'the command names the labels to create');
|
||||
assert.deepEqual(command.card.labelIds, ['urgent-there', 'new-local'], 'and the copy carries them');
|
||||
assert.deepEqual(C.validateRuleCopyCardCommand(command, elsewhere.context), command);
|
||||
// A command stored before #1759 has no createLabels, and still runs.
|
||||
const resum = row => { const { checksum, recorded, ...content } = row;
|
||||
return { ...content, recorded, checksum: sha256(canonical(content)) }; };
|
||||
const { createLabels, ...older } = command;
|
||||
assert.deepEqual(C.validateRuleCopyCardCommand(resum(older), elsewhere.context), resum(older));
|
||||
// Negative: a label to create that the copy does not carry, or one without
|
||||
// a name, is refused when the command is made and when it is read back.
|
||||
assert.throws(() => elsewhere.prepare({ subtaskDocs,
|
||||
crossBoard: { ...crossBoard, createLabels: [{ _id: 'stray', name: 'Stray', color: 'red' }] } }), /invalid/);
|
||||
assert.throws(() => elsewhere.prepare({ subtaskDocs,
|
||||
crossBoard: { ...crossBoard, createLabels: [{ ...created, name: '' }] } }), /invalid/);
|
||||
assert.throws(() => C.validateRuleCopyCardCommand(resum({ ...command,
|
||||
createLabels: [{ _id: 'stray', name: 'Stray', color: 'red' }] }), elsewhere.context), /command-invalid/);
|
||||
// The runner plans them with Card.copy's own rule and creates each once.
|
||||
const plans = fs.readFileSync(path.join(ROOT, 'server/notifications/storedRulePlans.js'), 'utf8');
|
||||
assert.match(plans, /planCrossBoardLabels\(\{/);
|
||||
assert.match(plans, /canCreate: Boolean\(targetBoard && actorId && typeof targetBoard\.hasAdmin === 'function' && targetBoard\.hasAdmin\(actorId\)\)/);
|
||||
assert.match(plans, /Boards\.updateAsync\(\{ _id: boardId, 'labels\._id': \{ \$ne: label\._id \} \}/,
|
||||
'a label already there by its id is not added again on a replay');
|
||||
assert.match(plans, /await createPlannedLabels\(command\.targetBoardId, command\.createLabels, actor, guard\);\s*await insertCard\(command\.card\);/);
|
||||
});
|
||||
|
||||
test('negative: tampering and foreign records are refused; a noop stays a noop', async () => {
|
||||
const f = await fixture();
|
||||
const command = f.prepare();
|
||||
|
||||
Reference in new issue
Block a user