mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Opening a board's Scrum view checked every card's edit permission one at a time, querying each card's links and then their boards. One batch now answers the same for all of the board's cards, and a server test confirms it agrees with the per-card check for writers, read-only and comment-only members, and outsiders with links. The Product Backlog and Sprints tables, whose rows each carry an edit form, show 100 rows at a time in Scrum order, with a button to show more. New interface text is in English, pending Transifex. Thanks to xet7 !
58 lines
3.6 KiB
JavaScript
58 lines
3.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Random } from 'meteor/random';
|
|
import Boards from '/models/boards';
|
|
import Cards from '/models/cards';
|
|
import { canEditCardOrLinkedCard, editableCardIds } from '/server/lib/linkedCardPermission';
|
|
|
|
// The Scrum view asks editableCardIds for every card of a board in one batch;
|
|
// it must answer exactly what canEditCardOrLinkedCard answers card by card.
|
|
describe('editableCardIds', function () {
|
|
this.timeout(30000);
|
|
it('agrees with the per-card check for writers, readers with and without links, and blocked roles', async function () {
|
|
if (!Meteor.isAppTest) this.skip();
|
|
const [writer, reader, commenter, outsider] = [Random.id(), Random.id(), Random.id(), Random.id()];
|
|
const source = Random.id(), mine = Random.id(), theirs = Random.id();
|
|
const [linkedHere, linkedTheirs, plain] = [Random.id(), Random.id(), Random.id()];
|
|
try {
|
|
await Boards.rawCollection().insertMany([
|
|
{ _id: source, title: 'Source', permission: 'public', members: [
|
|
{ userId: writer, isAdmin: false, isActive: true },
|
|
{ userId: reader, isAdmin: false, isActive: true, isNoComments: false, isCommentOnly: false, isReadOnly: true },
|
|
{ userId: commenter, isAdmin: false, isActive: true, isCommentOnly: true }] },
|
|
{ _id: mine, title: 'Reader writes here', permission: 'private', members: [
|
|
{ userId: reader, isAdmin: true, isActive: true }, { userId: commenter, isAdmin: true, isActive: true },
|
|
{ userId: outsider, isAdmin: true, isActive: true }] },
|
|
{ _id: theirs, title: 'Reader only reads here', permission: 'private', members: [
|
|
{ userId: reader, isAdmin: false, isActive: true, isReadOnly: true },
|
|
{ userId: outsider, isAdmin: false, isActive: true, isReadOnly: true }] },
|
|
]);
|
|
await Cards.rawCollection().insertMany([
|
|
{ _id: linkedHere, boardId: source, title: 'Linked where the reader writes' },
|
|
{ _id: linkedTheirs, boardId: source, title: 'Linked where the reader reads' },
|
|
{ _id: plain, boardId: source, title: 'Not linked' },
|
|
{ _id: Random.id(), boardId: mine, type: 'cardType-linkedCard', linkedId: linkedHere, title: 'link' },
|
|
{ _id: Random.id(), boardId: theirs, type: 'cardType-linkedCard', linkedId: linkedTheirs, title: 'link' },
|
|
]);
|
|
const board = await Boards.findOneAsync(source);
|
|
const cards = await Cards.find({ boardId: source }).fetchAsync();
|
|
for (const userId of [writer, reader, commenter, outsider, null]) {
|
|
const batch = await editableCardIds(userId, cards, board);
|
|
for (const card of cards) {
|
|
assert.equal(batch.has(card._id), await canEditCardOrLinkedCard(userId, card, board, { recordDenial: false }),
|
|
`${userId === reader ? 'reader' : userId === commenter ? 'commenter' : userId === writer ? 'writer' : 'other'}: ${card.title}`);
|
|
}
|
|
}
|
|
// Someone with no role on the (public) source board edits through a link
|
|
// on a board they write, and only there; an explicit read-only role on
|
|
// the source is a ceiling.
|
|
assert.deepEqual([...await editableCardIds(outsider, cards, board)], [linkedHere], 'only through a writable link');
|
|
assert.deepEqual([...await editableCardIds(reader, cards, board)], [], 'a read-only role blocks links');
|
|
assert.equal((await editableCardIds(writer, cards, board)).size, cards.length);
|
|
} finally {
|
|
await Cards.rawCollection().deleteMany({ boardId: { $in: [source, mine, theirs] } });
|
|
await Boards.rawCollection().deleteMany({ _id: { $in: [source, mine, theirs] } });
|
|
}
|
|
});
|
|
});
|