mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 09:45:04 -05:00
POST /api/boards/:boardId/lists/:listId/cards with linkedId checked only READ access to the source card's board and cloned the whole source card with Card.link(), so a read-only, read-assigned-only or comment-assigned-only member could link and copy cards - including unassigned ones and their descriptions - into a board they control, which the createLinkedCard method refuses. Both now call one createLinkedCardFor(): write access to the source board, an assigned-only member links only cards assigned to them (a check the method lacked as well), the list and swimlane must belong to the destination board, and the link holds the title, not a copy. Refusals record LinkedWriteBleed with source rest:card-link. The tests that pinned the method's body follow the shared function; the negative test fails if the REST branch checks only read access or clones the card again. A browser test covers the REST roles. Thanks to xet7 !
69 lines
3.3 KiB
JavaScript
69 lines
3.3 KiB
JavaScript
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const test = require('node:test');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const server = fs.readFileSync(path.join(root, 'server/models/cards.js'), 'utf8');
|
|
const client = fs.readFileSync(
|
|
path.join(root, 'client/components/lists/listBody.js'),
|
|
'utf8',
|
|
);
|
|
|
|
test('#6613: card-link confirmation awaits an acknowledged server method', () => {
|
|
assert.match(client, /await Meteor\.callAsync\(\s*'createLinkedCard'/);
|
|
assert.match(client, /Filter\.addException\(_id\);\s*Popup\.back\(\)/);
|
|
assert.doesNotMatch(
|
|
client.slice(client.indexOf("async 'click .js-done'"), client.indexOf("async 'click .js-link-board'")),
|
|
/type:\s*'cardType-linkedCard'[\s\S]*Cards\.insert/,
|
|
);
|
|
});
|
|
|
|
test('#6613 follow-up: link position survives asynchronous confirmation', () => {
|
|
const created = client.slice(
|
|
client.indexOf('Template.linkCardPopup.onCreated'),
|
|
client.indexOf('Template.linkCardPopup.helpers'),
|
|
);
|
|
assert.match(created, /this\.position = Template\.currentData\(\)\?\.position/);
|
|
assert.match(created, /if \(this\.position === 'top'\)/);
|
|
assert.match(created, /else if \(this\.position === 'bottom'\)/);
|
|
assert.doesNotMatch(
|
|
created.slice(created.indexOf('this.getSortIndex')),
|
|
/Template\.currentData\(/,
|
|
'getSortIndex can run after await only when it no longer needs a Blaze view',
|
|
);
|
|
});
|
|
|
|
test('#6613: the server validates every link coordinate before inserting', () => {
|
|
// LinkedWriteBleed: the method and the REST route share createLinkedCardFor.
|
|
assert.match(server, /async createLinkedCard\(sourceCardId, boardId, swimlaneId, listId, sort\) \{\s*return createLinkedCardFor\(this\.userId,/);
|
|
const method = server.slice(
|
|
server.indexOf('async function createLinkedCardFor('),
|
|
server.indexOf('Meteor.methods({', server.indexOf('async function createLinkedCardFor(')),
|
|
);
|
|
for (const argument of ['sourceCardId', 'boardId', 'swimlaneId', 'listId']) {
|
|
assert.match(method, new RegExp(`check\\(${argument}, String\\)`));
|
|
}
|
|
assert.match(method, /check\(sort, Number\)/);
|
|
assert.match(method, /allowIsBoardMemberWithWriteAccess\(userId, sourceBoard\)/);
|
|
assert.match(method, /allowIsBoardMemberWithWriteAccess\(userId, destinationBoard\)/);
|
|
assert.match(method, /destinationList\.boardId !== boardId/);
|
|
assert.match(method, /destinationSwimlane\.boardId !== boardId/);
|
|
assert.match(method, /await Cards\.insertAsync\(/);
|
|
});
|
|
|
|
test('#5683: allow same-board sources while refusing archived, template and pointer targets', () => {
|
|
// LinkedWriteBleed: the method and the REST route share createLinkedCardFor.
|
|
assert.match(server, /async createLinkedCard\(sourceCardId, boardId, swimlaneId, listId, sort\) \{\s*return createLinkedCardFor\(this\.userId,/);
|
|
const method = server.slice(
|
|
server.indexOf('async function createLinkedCardFor('),
|
|
server.indexOf('Meteor.methods({', server.indexOf('async function createLinkedCardFor(')),
|
|
);
|
|
assert.doesNotMatch(method, /sourceCard\.boardId === boardId/);
|
|
assert.match(method, /sourceCard\.archived === true/);
|
|
for (const type of ['template-card', 'cardType-linkedCard', 'cardType-linkedBoard']) {
|
|
assert.ok(method.includes(`sourceCard.type === '${type}'`));
|
|
}
|
|
assert.match(method, /throw new Meteor\.Error\('invalid-linked-card'\)/);
|
|
});
|