mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
"A must be done before B and C can start, so A is a subtask of both." A card now keeps every parent in parentIds, with parentId still the primary one (parentIds[0]), so everything that reads one parent keeps working and a card written before this has its one parent. Picking an existing card as a subtask adds this card as a further parent instead of replacing the one it had; Card -> More lists the other parents and removes one, and choosing the primary parent keeps the others. Children are found under any parent - the subtask list and counter, the parent filter, rule email Details and the exports - and the loop guard and the board publication walk every parent. Archiving or deleting a card takes only the subtasks it is the one parent of; a shared subtask just loses it. Every parent written must be on a board the writer can see (GHSA-jvv9-498p-hxrg), and board copy and WeKan import remap all of them. The old single-parent walker is removed. Thanks to ikomhoog and xet7 ! Fixes #3626,
84 lines
5.8 KiB
JavaScript
84 lines
5.8 KiB
JavaScript
"use strict";
|
|
(async () => {
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const root = path.resolve(__dirname, '..');
|
|
const source = fs.readFileSync(path.join(root, 'models/cards.js'), 'utf8');
|
|
// Keep exercising the runtime body when optional copy-pipeline arguments grow.
|
|
const copyBody = source.slice(source.indexOf(' async copy('), source.indexOf('\n async link('));
|
|
const linkStart = source.indexOf(' async link(');
|
|
const linkBody = source.slice(linkStart, source.indexOf('\n list()', linkStart));
|
|
const { normalizeDependencies } = await import('../models/metadata/dependencies.js');
|
|
const { filterCopiedLabelIds } = await import('../server/lib/cardCopyHelpers.js');
|
|
const { buildCopiedSubtaskFields } = await import('../models/lib/subtaskCopy.js');
|
|
async function exercise({ sameBoard = false, cache = true, fail = false, withChildren = false, cardIdMap = null } = {}) {
|
|
const original = {
|
|
_id: 'original', boardId: 'source', swimlaneId: 'old-swimlane', listId: 'old-list',
|
|
title: 'Template', labelIds: ['source-label'],
|
|
syncExternalId: 'KEY-1', syncSourceType: 'jira', syncSourceKey: 'original-project', syncLastSource: { title: 'Template' },
|
|
customFields: [{ _id: 'source-field', value: 'kept' }],
|
|
cardDependencies: [{ cardId: 'destination-card', type: 'related' }, { cardId: 'missing-card', type: 'related' }],
|
|
...(cache ? { __id: 'original' } : {}),
|
|
async mapCustomFieldsToBoard() { return [{ _id: 'destination-field', value: 'kept' }]; },
|
|
};
|
|
Object.defineProperty(original, 'mapCustomFieldsToBoard', { enumerable: false });
|
|
const before = JSON.stringify(original);
|
|
const inserted = [], children = [];
|
|
const boardId = sameBoard ? 'source' : 'destination';
|
|
const Cards = { async insertAsync(document) {
|
|
assert.equal(Object.hasOwn(document, '__id'), false, 'runtime cache must not reach schema validation');
|
|
assert.equal(Object.hasOwn(document, '_id'), false, 'copies require a new document ID');
|
|
for (const key of ['syncExternalId','syncSourceType','syncSourceKey','syncLastSource']) assert.equal(Object.hasOwn(document,key),false, 'copies must not inherit Sync identity');
|
|
if (fail) throw new Error('insert rejected');
|
|
inserted.push(structuredClone(document)); return `new-${inserted.length}`;
|
|
} };
|
|
const ReactiveCache = {
|
|
getCard: async id => id === original._id ? original : id === 'destination-card' ? { boardId } : null,
|
|
getBoard: async id => ({ _id: id, labels: [{ _id: id === 'source' ? 'source-label' : 'destination-label', name: 'Shared' }], async getNextCardNumber() { return 7; } }),
|
|
getChecklists: async query => withChildren && query.cardId === 'original' ? [{ async copy(id) { children.push(['checklist', id]); } }] : [],
|
|
getCards: async () => withChildren ? [{ _id: 'child', __id: 'child', boardId: 'source', parentId: 'original', title: 'Child' }] : [],
|
|
getCardComments: async () => withChildren ? [{ async copy(id, target) { children.push(['comment', id, target]); } }] : [],
|
|
};
|
|
// #3626: copy() finds the card's subtasks with the shared children selector.
|
|
const { childrenSelector } = require('../models/lib/cardParents');
|
|
const copy = new Function('ReactiveCache', 'Cards', 'Meteor', 'filterCopiedLabelIds', 'normalizeDependencies', 'require', 'childrenSelector',
|
|
`return ({${copyBody}}).copy;`)(ReactiveCache, Cards, { isServer: false }, filterCopiedLabelIds, normalizeDependencies,
|
|
specifier => {
|
|
// The copy path now also delegates Scrum metadata to its pure helper.
|
|
if (specifier === './lib/scrumCopy') return require('../models/lib/scrumCopy');
|
|
assert.equal(specifier, './lib/subtaskCopy'); return { buildCopiedSubtaskFields };
|
|
}, childrenSelector);
|
|
if (fail) await assert.rejects(copy.call(original, boardId, 'new-swimlane', 'new-list', cardIdMap), /insert rejected/);
|
|
else assert.equal(await copy.call(original, boardId, 'new-swimlane', 'new-list', cardIdMap), 'new-1');
|
|
assert.equal(JSON.stringify(original), before, 'successful and rejected copies must preserve the source card');
|
|
if (!fail) {
|
|
assert.equal(inserted[0].boardId, boardId);
|
|
assert.equal(inserted[0].listId, 'new-list');
|
|
assert.equal(inserted[0].swimlaneId, 'new-swimlane');
|
|
assert.equal(inserted[0].cardNumber, 7);
|
|
assert.equal(inserted[0].labelIds[0], sameBoard ? 'source-label' : 'destination-label');
|
|
assert.equal(inserted[0].customFields[0]._id, sameBoard ? 'source-field' : 'destination-field');
|
|
assert.equal(inserted[0].cardDependencies.length, cardIdMap ? 2 : 1);
|
|
if (withChildren) {
|
|
assert.equal(inserted[1].parentId, 'new-1'); assert.equal(inserted[1].boardId, boardId);
|
|
assert.deepEqual(children, [['checklist', 'new-1'], ['comment', 'new-1', boardId]]);
|
|
}
|
|
}
|
|
}
|
|
await exercise({ withChildren: true });
|
|
await exercise({ sameBoard: true, cache: false });
|
|
await exercise({ fail: true });
|
|
const map = {}; await exercise({ cardIdMap: map }); assert.equal(map.original, 'new-1');
|
|
const linked = { _id: 'original', __id: 'original', boardId: 'source', title: 'Source', labelIds: ['label'] };
|
|
const beforeLink = JSON.stringify(linked);
|
|
const link = new Function('Cards', `return ({${linkBody}}).link;`)({ async insertAsync(document) {
|
|
assert.equal(Object.hasOwn(document, '__id'), false); assert.equal(Object.hasOwn(document, '_id'), false);
|
|
assert.equal(document.linkedId, 'original'); assert.equal(document.type, 'cardType-linkedCard');
|
|
assert.equal(document.boardId, 'destination'); return 'linked';
|
|
} });
|
|
assert.equal(await link.call(linked, 'destination', 'swimlane', 'list'), 'linked');
|
|
assert.equal(JSON.stringify(linked), beforeLink);
|
|
console.log('card copy cache: 5 cases pass, including cross-board children, same-board copies, rejected inserts and linked cards');
|
|
})().catch(error => { console.error(error); process.exitCode = 1; });
|