Files
wekan/server/lib/tests/dependencyLayers.tests.js
T
Lauri Ojansivu cff80a9d7b Make showing dependencies each user's own choice, and add My Dependencies.
Issue #6732: the board-header "Show dependencies" button wrote one shared
board field, so one user turning the lines on or off did it for everybody,
and only board admins could write that field, so a member - or anyone on a
public board - who could see the board could not turn them on at all.

The button is gone from the header. At the top of Member Settings are now:

- Show My Dependencies
- Show Board Dependencies
- Import
- Export

Both switches are off by default and saved in the user's profile, so each
user decides for themselves and anyone who can view a board may show its
dependencies.

Board Dependencies stay on the board's cards. They may now be edited by
every role that can edit OR move cards - a Worker included - and by an
assigned-only member on the cards assigned to them; one rule
(models/lib/dependencyAccess.js) is applied by new server methods, by the
card details, the line popup, drawing on the board, Import and the REST
routes. My Dependencies are a new layer in the user's profile: each user's
own lines between cards they can see, drawn dashed and seen only by them.
The client cannot write them directly; only the methods, which check card
access, can.

Import and Export work on the open board in the Board Settings / Export
formats (JSON, and SVG that re-imports). Importing Board Dependencies is
offered only to roles that may edit or move cards, and every import now
combines: a line already there is kept exactly as it is, and only missing
lines are added - also for All Boards / Import / Dependencies, which used to
overwrite an existing line's type and colour. The design is written up in
docs/Features/Editor/RedStrings/Board-And-My-Dependencies.md.

Tests: the role table, viewing, assigned-only scope, normalizing and
combining (unit), with guards that the header toggle and every reader of
the old board flag are gone and every write goes through the rule; a
full-app test drives the methods as admin, Worker, read-only, assigned-only
and a stranger; Playwright covers the menu order and defaults, a per-user
switch that leaves another member's view alone, a read-only member's My
Dependencies (dashed, unseen by the owner) with import and export, and a
Worker's combining board import - in Chromium and WebKit. Header, fold and
mobile guards that listed the old button are updated. 567 server tests pass.

Thanks to nalilord and xet7 !

Fixes #6732.
2026-10-01 19:18:58 +03:00

95 lines
6.5 KiB
JavaScript

import assert from 'node:assert/strict';
import { Meteor } from 'meteor/meteor';
import { DDP } from 'meteor/ddp';
import { Random } from 'meteor/random';
import Boards from '/models/boards';
import Cards from '/models/cards';
import { hasForbiddenUserUpdateField } from '/models/users';
// #6732: showing dependencies is each user's own choice; Board Dependencies
// are edited by roles that may edit or move cards; My Dependencies live in the
// user's profile; imports only add what is missing.
describe('Board and My Dependencies (#6732)', function () {
this.timeout(30000);
it('applies visibility per user, the edit rule, and merge-only imports', async function () {
if (!Meteor.isAppTest) this.skip();
const ids = { admin: Random.id(), worker: Random.id(), reader: Random.id(), assigned: Random.id(), stranger: Random.id() };
const boardId = Random.id(), [c1, c2, c3] = [Random.id(), Random.id(), Random.id()];
const call = (who, method, ...args) => {
const context = { userId: ids[who], isSimulation: false, connection: null, setUserId() {}, unblock() {} };
return DDP._CurrentMethodInvocation.withValue(context, () => Meteor.server.method_handlers[method].apply(context, args));
};
const profile = async who => ((await Meteor.users.findOneAsync(ids[who])) || {}).profile || {};
const deps = async id => ((await Cards.findOneAsync(id)) || {}).cardDependencies || [];
try {
await Meteor.users.rawCollection().insertMany(Object.entries(ids).map(([name, _id]) => ({ _id, username: `${name}-${_id}`, profile: {} })));
await Boards.rawCollection().insertOne({ _id: boardId, title: 'Deps', permission: 'private', archived: false, members: [
{ userId: ids.admin, isAdmin: true, isActive: true },
{ userId: ids.worker, isWorker: true, isActive: true },
{ userId: ids.reader, isReadOnly: true, isActive: true },
{ userId: ids.assigned, isNormalAssignedOnly: true, isActive: true },
] });
await Cards.rawCollection().insertMany([c1, c2, c3].map((_id, i) => ({ _id, boardId, listId: 'l', swimlaneId: 's',
title: `Card ${i + 1}`, cardNumber: i + 1, archived: false, sort: i, assignees: i === 0 ? [ids.assigned] : [] })));
// Visibility: one user's switch is theirs alone; a read-only member may use it.
await call('reader', 'setDependencyVisibility', 'board', true);
assert.equal((await profile('reader')).showBoardDependencies, true);
assert.equal((await profile('admin')).showBoardDependencies, undefined, 'nobody else is affected');
await call('admin', 'setDependencyVisibility', 'mine', true);
assert.deepEqual([(await profile('admin')).showMyDependencies, (await profile('reader')).showMyDependencies], [true, undefined]);
// Board Dependencies: a Worker (moves, cannot edit) may; read-only and strangers may not.
await call('worker', 'setBoardDependency', c1, c2, { type: 'blocks' });
assert.deepEqual((await deps(c1)).map(d => [d.cardId, d.type]), [[c2, 'blocks']]);
await assert.rejects(call('reader', 'setBoardDependency', c2, c3, {}), /not-authorized/);
await assert.rejects(call('stranger', 'setBoardDependency', c2, c3, {}), /not-authorized/);
await assert.rejects(call('reader', 'removeBoardDependency', c1, c2), /not-authorized/);
// Assigned-only: both cards must be theirs to see.
await assert.rejects(call('assigned', 'setBoardDependency', c1, c3, {}), /not-authorized/);
await Cards.rawCollection().updateOne({ _id: c3 }, { $set: { assignees: [ids.assigned] } });
await call('assigned', 'setBoardDependency', c1, c3, { type: 'fixes' });
assert.equal((await deps(c1)).length, 2);
await call('assigned', 'removeBoardDependency', c1, c3);
assert.equal((await deps(c1)).length, 1);
// Import combines: the existing line stays as it is, a missing one is added.
const res = await call('admin', 'importBoardDependencies', boardId, [
{ from: c1, to: c2, type: 'fixes' },
{ fromCardNumber: 2, toCardNumber: 3, type: 'related-to' },
{ fromTitle: 'No such card', toTitle: 'Card 1' },
]);
assert.deepEqual(res, { imported: 1, skipped: 1, unmatched: 1 });
assert.equal((await deps(c1))[0].type, 'blocks', 'never overwritten');
assert.deepEqual((await deps(c2)).map(d => d.cardId), [c3]);
await assert.rejects(call('reader', 'importBoardDependencies', boardId, [{ from: c3, to: c1 }]), /not-authorized/,
'only roles that may edit or move cards import Board Dependencies');
// My Dependencies: in the profile, theirs alone; a read-only member may keep them.
await call('reader', 'setMyDependency', c3, c1, { type: 'blocks' });
const mine = (await profile('reader')).myDependencies;
assert.deepEqual(mine.map(row => [row.boardId, row.cardId, row.targetCardId, row.type]), [[boardId, c3, c1, 'blocks']]);
assert.equal((await deps(c3)).length, 0, 'nothing written on the board');
const merged = await call('reader', 'importMyDependencies', boardId, [{ from: c3, to: c1, type: 'fixes' }, { from: c2, to: c1 }]);
assert.deepEqual(merged, { imported: 1, skipped: 1, unmatched: 0 });
assert.equal((await profile('reader')).myDependencies.find(row => row.cardId === c3).type, 'blocks');
await call('reader', 'removeMyDependency', boardId, c2, c1);
assert.equal((await profile('reader')).myDependencies.length, 1);
// A private board's cards are not a stranger's to link (negative); a public board's are.
await assert.rejects(call('stranger', 'setMyDependency', c1, c2, {}), /not-authorized/);
await Boards.rawCollection().updateOne({ _id: boardId }, { $set: { permission: 'public' } });
await call('stranger', 'setMyDependency', c1, c2, {});
assert.equal((await profile('stranger')).myDependencies.length, 1);
// The client cannot write My Dependencies directly (only through the checks above).
assert.equal(hasForbiddenUserUpdateField(['profile.myDependencies'], { $set: { 'profile.myDependencies': [] } }), true);
assert.equal(hasForbiddenUserUpdateField(['profile'], { $set: { profile: { myDependencies: [] } } }), true);
assert.equal(hasForbiddenUserUpdateField(['profile.showMyDependencies'], { $set: { 'profile.showMyDependencies': true } }), false);
} finally {
await Cards.rawCollection().deleteMany({ boardId });
await Boards.rawCollection().deleteMany({ _id: boardId });
await Meteor.users.rawCollection().deleteMany({ _id: { $in: Object.values(ids) } });
}
});
});