mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
A feature's guide now sits under the menu it is used from, read from the templates rather than from where somebody once put it: Header-Bar, All-Boards, Pages, Board-Header (search and every Board View), Board-Sidebar (Board Settings, Filter, Members, Labels, Archive), Rules, Swimlanes, Lists, Cards, Member-Settings, Admin-Panel and Login-Page. Topics used from several menus (editor, history, theme, translations, email, troubleshooting) are in General. - Each area has a README mapping its menu entries to their guides and to the template or server module that implements them. Board-Header/README.md lists all 40 Board View entries with the template boardBody.jade renders; five views (Table, Calendar Mode, Time, Timeline, Map) have no guide of their own yet and say so. - Board-View.md listed 25 views while BOARD_VIEWS has 40; it now lists all of them with their English labels. - Pages keep their file names. Where a released changelog links an old path, a "# Moved" page stays there and points to the new one; test-menu.sh skips folders holding only those. - Undo was filed under Login; it is General/Undo now. - Every link in docs, code comments, scripts and tests follows the move; docsLinksResolve checks them all. Tests that read a doc follow it to its new place. boardViewSettings now fails when Board-View.md or Board-Header/README.md differs from BOARD_VIEWS, or names a template boardBody.jade does not render. Thanks to xet7 !
84 lines
4.0 KiB
JavaScript
84 lines
4.0 KiB
JavaScript
'use strict';
|
|
// Card dependencies ("Red Strings", #3392), #6732: who may see, edit and
|
|
// import them. Pure, so tests/dependencyAccess.test.cjs runs it without Meteor.
|
|
// The design is docs/Features/General/Editor/RedStrings/Board-And-My-Dependencies.md.
|
|
//
|
|
// - Showing or hiding dependencies is each user's OWN preference, in their
|
|
// profile, off by default. It never changes what another user sees, and
|
|
// anyone who can view a board may show its dependencies.
|
|
// - Board Dependencies are saved on the board's cards. A member whose role may
|
|
// edit OR move cards may edit them - and import them. An assigned-only member
|
|
// only on cards assigned to them, the cards they can see.
|
|
// - My Dependencies are saved in the user's profile; every user edits their
|
|
// own, between cards they can see.
|
|
// - An import only ADDS lines that are not there yet; existing lines are kept
|
|
// as they are.
|
|
const { memberCan } = require('./boardRoleCapabilities');
|
|
const { isAssignedOnlyMember } = require('./boardCardScope');
|
|
const { readableWithoutMembership } = require('./boardPermission');
|
|
|
|
const MY_DEPENDENCIES_MAX = 5000;
|
|
const text = value => typeof value === 'string' && value.length > 0 && value.length <= 128;
|
|
|
|
// Anyone who can view the board: an active member, anyone on a public board,
|
|
// or any signed-in user on an instance board - the rule every read uses.
|
|
function canViewBoard(board, userId) {
|
|
if (!board || board.archived === true) return false;
|
|
if (readableWithoutMembership(board.permission, text(userId))) return true;
|
|
return text(userId) && Array.isArray(board.members) &&
|
|
board.members.some(member => member && member.userId === userId && member.isActive === true);
|
|
}
|
|
|
|
function canEditBoardDependencies(board, userId) {
|
|
if (!board || !text(userId)) return false;
|
|
return memberCan(board, userId, 'write') || memberCan(board, userId, 'moveCard');
|
|
}
|
|
|
|
// May this user see this card at all (assigned-only members see their own)?
|
|
function canSeeCard(board, userId, card) {
|
|
if (!canViewBoard(board, userId) || !card || card.boardId !== board._id || card.archived === true) return false;
|
|
if (isAssignedOnlyMember(board, userId)) return Array.isArray(card.assignees) && card.assignees.includes(userId);
|
|
return true;
|
|
}
|
|
|
|
// A Board Dependency is stored on its source card; both ends must be visible.
|
|
function canEditCardDependency(board, userId, sourceCard, targetCard) {
|
|
return canEditBoardDependencies(board, userId) && canSeeCard(board, userId, sourceCard) &&
|
|
(targetCard === undefined || canSeeCard(board, userId, targetCard));
|
|
}
|
|
|
|
// The one key of a dependency line, whichever layer it is in.
|
|
const lineKey = (boardId, fromId, toId) => `${boardId}\u0000${fromId}\u0000${toId}`;
|
|
|
|
// My Dependencies: [{ boardId, cardId, targetCardId, type, color, icon }].
|
|
function normalizeMyDependencies(list, normalizeDependency) {
|
|
const seen = new Set(), result = [];
|
|
for (const row of Array.isArray(list) ? list : []) {
|
|
if (!row || !text(row.boardId) || !text(row.cardId) || !text(row.targetCardId) || row.cardId === row.targetCardId) continue;
|
|
const key = lineKey(row.boardId, row.cardId, row.targetCardId);
|
|
if (seen.has(key)) continue;
|
|
seen.add(key);
|
|
const dep = normalizeDependency({ cardId: row.targetCardId, type: row.type, color: row.color, icon: row.icon });
|
|
result.push({ boardId: row.boardId, cardId: row.cardId, targetCardId: row.targetCardId,
|
|
type: dep.type, color: dep.color, icon: dep.icon });
|
|
}
|
|
return result;
|
|
}
|
|
|
|
// Combine: keep every existing line, add only the incoming ones not yet there.
|
|
function mergeDependencyLines(existing, incoming, keyOf) {
|
|
const keys = new Set(existing.map(keyOf));
|
|
const added = [];
|
|
let skipped = 0;
|
|
for (const line of incoming) {
|
|
const key = keyOf(line);
|
|
if (keys.has(key)) { skipped++; continue; }
|
|
keys.add(key);
|
|
added.push(line);
|
|
}
|
|
return { added, skipped };
|
|
}
|
|
|
|
module.exports = { MY_DEPENDENCIES_MAX, canViewBoard, canEditBoardDependencies, canSeeCard, canEditCardDependency,
|
|
lineKey, normalizeMyDependencies, mergeDependencyLines };
|