Files
wekan/server/lib/linkedCardPermission.js
T
Lauri Ojansivu 49de60eb04 Edit linked card content from either board.
Delegate source-card edits through a visible active link when the user has write access on the board containing that link. Route content fields, attachments, checklists, subtasks, watchers, labels, custom fields, voting and poker to the source while retaining placement on the linked card.

Thanks to hever and xet7 !

Fixes #1995.
2026-08-18 18:45:14 +03:00

38 lines
1.5 KiB
JavaScript

import Boards from '/models/boards';
import Cards from '/models/cards';
import { allowIsBoardMemberWithWriteAccess } from '/server/lib/utils';
import { canUserSeeBoard } from '/server/lib/visibleBoardIds';
// 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) {
if (!userId || !card) return false;
const sourceBoard = knownSourceBoard || await Boards.findOneAsync(card.boardId);
if (allowIsBoardMemberWithWriteAccess(userId, sourceBoard)) return true;
// 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));
}