Files
wekan/server/lib/linkedCardPermission.js
T
Lauri Ojansivu 7595727917 Boards every signed-in user may edit, per-list permissions, board keys and shared labels.
A board can let every signed-in user edit it, when Admin Panel / Settings /
Visibility allows it: a non-member then comments, edits and moves cards like
a Normal member, and their first edit makes them one. Board-wide settings
stay members-only.

Lists can allow or refuse editing and commenting per role (list menu, board
admins): built-in roles, custom roles and, on an open board, everyone signed
in. The server applies it to card, checklist, attachment and comment writes
and to moves into the list; the REST API honours a list's refusal on every
per-list card route. A direct client write of the setting is refused and
shown in Admin Panel / Problems.

Every board has a key, unique in the instance, suggested from its title and
set for existing boards at startup; card numbers show as KEY-7 and searching
for KEY-7 finds the card.

Shared labels in Admin Panel / Labels, for every board or an organization's
or team's boards; a board uses them beside its own, and a rename or colour
change reaches every board that uses it.

New strings translated in all languages. Low confidence: chr, tlh, wal, ay,
ace, nah, gn, iu, zgh, rup, wo, se, ff, tig, vo, bm, kl, bua, nap, mai, to,
ks, qu, bo, fj, haw, om, ss, ts, ve-PP, lld, scn.

Thanks to Meeques, justinr1234, tiFabGrinch, ejlkemper and xet7 !

Fixes #4575,
Fixes #4527,
Fixes #2449,
Fixes #2450,
Fixes #2761,
Fixes #4698.
2026-10-14 09:28:45 +03:00

85 lines
4.6 KiB
JavaScript

import Boards from '/models/boards';
import Cards from '/models/cards';
import { allowIsBoardMemberWithWriteAccess } from '/server/lib/utils';
import { canUserSeeBoard } from '/server/lib/visibleBoardIds';
import { sourceRoleBlocksDelegation, recordLinkedWriteDenial } from '/models/lib/linkedWritePolicy';
import { listException } from '/server/lib/listPermissionGate';
import Lists from '/models/lists';
const { exceptionFor } = require('/models/lib/listPermissions');
// Editing a linked card is delegated by the board that contains the link. A
// user may therefore edit the source when they can write either the source
// board itself or at least one board containing a live link to that source.
// Merely knowing a source id is insufficient: the linked Card document must
// exist and its destination board must grant write access.
export async function canEditCardOrLinkedCard(userId, card, knownSourceBoard, { recordDenial = true } = {}) {
if (!userId || !card) return false;
const sourceBoard = knownSourceBoard || await Boards.findOneAsync(card.boardId);
// #4527: the card's list may say otherwise for this user's role, either way.
// A list that refuses is final - a link on another board is not a way round it.
const listRule = await listException(userId, sourceBoard, card.listId, 'write');
if (listRule !== undefined) return listRule;
if (allowIsBoardMemberWithWriteAccess(userId, sourceBoard)) return true;
// An explicit non-writing source role is a ceiling, including for links
// minted before link creation was restricted. A self-owned destination must
// not turn source comment/read access into general source write access.
if (sourceRoleBlocksDelegation(userId, sourceBoard)) {
if (recordDenial) recordLinkedWriteDenial('linked-card:source-write');
return false;
}
// Delegation applies only to a link whose source is still visible. If source
// access is revoked, a stale link on another board must not remain a write
// tunnel into the now-hidden card.
if (!(await canUserSeeBoard(userId, card.boardId))) return false;
const links = await Cards.find(
{
linkedId: card._id,
type: 'cardType-linkedCard',
archived: { $ne: true },
},
{ fields: { boardId: 1 } },
).fetchAsync();
if (!links.length) return false;
const boards = await Boards.find(
{ _id: { $in: [...new Set(links.map(link => link.boardId))] } },
{ fields: { members: 1 } },
).fetchAsync();
return boards.some(board =>
allowIsBoardMemberWithWriteAccess(userId, board));
}
// canEditCardOrLinkedCard for every card of ONE board at once, without its
// denial logging: the ids of the ones the user may edit. A board's Scrum view
// asks this for all its cards, and one query per card - the links of each,
// then their boards - was the cost of opening it on a large board. The same
// rules: board writers edit them all, an explicit non-writing role edits none,
// otherwise a card is editable through a link on a board the user may write.
export async function editableCardIds(userId, cards, sourceBoard) {
if (!userId || !sourceBoard || !cards.length) return new Set();
// #4527: cards in a list with an exception for this user's role are decided
// by it; the rest by the rules below.
const excepted = await Lists.find({ boardId: sourceBoard._id, roleExceptions: { $exists: true } },
{ fields: { roleExceptions: 1 } }).fetchAsync();
const listRule = new Map(excepted.map(list => [list._id, exceptionFor(sourceBoard, list, userId, 'write')]));
const decided = new Set();
for (const card of cards) {
const rule = listRule.get(card.listId);
if (rule === true) decided.add(card._id);
}
const open = cards.filter(card => listRule.get(card.listId) === undefined);
const ids = open.map(card => card._id);
if (!ids.length) return decided;
if (allowIsBoardMemberWithWriteAccess(userId, sourceBoard)) return new Set([...decided, ...ids]);
if (sourceRoleBlocksDelegation(userId, sourceBoard) || !(await canUserSeeBoard(userId, sourceBoard._id))) return decided;
const links = await Cards.find({ linkedId: { $in: ids }, type: 'cardType-linkedCard', archived: { $ne: true } },
{ fields: { boardId: 1, linkedId: 1 } }).fetchAsync();
if (!links.length) return decided;
const boards = await Boards.find({ _id: { $in: [...new Set(links.map(link => link.boardId))] } },
{ fields: { members: 1 } }).fetchAsync();
const writable = new Set(boards.filter(board => allowIsBoardMemberWithWriteAccess(userId, board)).map(board => board._id));
return new Set([...decided, ...links.filter(link => writable.has(link.boardId)).map(link => link.linkedId)]);
}