Files
wekan/client/lib/dependencyLayers.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

53 lines
2.3 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { ReactiveCache } from '/imports/reactiveCache';
import { Utils } from '/client/lib/utils';
import { normalizeDependency } from '/models/metadata/dependencies';
const { canEditBoardDependencies, canEditCardDependency, normalizeMyDependencies } = require('/models/lib/dependencyAccess');
// #6732: the two dependency layers as THIS user sees them
// (docs/Features/Editor/RedStrings/Board-And-My-Dependencies.md). Both are off
// until the user turns them on in Member Settings, and turning one on changes
// only their own view.
export function dependencyVisibility() {
const profile = (ReactiveCache.getCurrentUser() || {}).profile || {};
return { board: profile.showBoardDependencies === true, mine: profile.showMyDependencies === true };
}
export function canEditBoardDependenciesHere(board) {
return !!board && canEditBoardDependencies(board, Meteor.userId());
}
// Where a line drawn on the board goes: the Board Dependencies when they are
// shown and this user may edit them, otherwise My Dependencies when those are
// shown. With neither, nothing is drawn and no connect handle appears.
export function newLineLayer(board) {
const shown = dependencyVisibility();
if (shown.board && canEditBoardDependenciesHere(board)) return 'board';
if (shown.mine && Meteor.userId()) return 'mine';
return null;
}
// This user's own lines on one board.
export function myDependencyLines(boardId) {
const profile = (ReactiveCache.getCurrentUser() || {}).profile || {};
return normalizeMyDependencies(profile.myDependencies, normalizeDependency).filter(row => row.boardId === boardId);
}
// May this user edit this card's Board Dependencies? A linked card's live on
// the card it points at, as the server resolves them.
export function canEditCardDependenciesHere(card) {
const real = card && typeof card.getRealCard === 'function' ? card.getRealCard() : card;
const board = real && ReactiveCache.getBoard(real.boardId);
return !!(board && real && canEditCardDependency(board, Meteor.userId(), real));
}
// The open card's (card details).
Template.registerHelper('canEditBoardDependencies', () =>
canEditCardDependenciesHere(ReactiveCache.getCard(Utils.getCurrentCardId())));
Template.registerHelper('showAnyDependencies', () => {
const shown = dependencyVisibility();
return shown.board || shown.mine;
});