Files
wekan/server/lib/ruleCopyCard.js
T
Lauri Ojansivu ee24453dcb A rule action into a list that refuses the triggering user's role is skipped.
Decided by the maintainer on 2026-11-18 (TODO.md). A rule's move, archive,
unarchive, create-card, copy, link, sort-list and move-all-cards actions
checked only board write access. Each now asks the lists it writes in as
the user who triggered the rule (#4527); a refusing list skips that
action, and the rest of the rule still runs. The skip shows in Admin
Panel / Problems as ListLockRule (authz.rule-list-locked, detected, low,
never disables): it is a rule meeting a locked list, not an attack.

List Sync's journaled rule replay is not changed yet - a skip there needs
a receipt of its own - and stays in TODO.md.

tests/listLockRules.test.cjs runs the check and copyRuleCard against a
locked list and pins every action.

Thanks to xet7 !
2026-11-18 23:08:06 +02:00

35 lines
2.1 KiB
JavaScript

import { AsyncLocalStorage } from 'node:async_hooks';
const copies = new AsyncLocalStorage();
// Copies insert cards and activities, which can trigger another copy rule.
// A copy action may run once per causal copy chain; independent events
// have separate contexts and may copy the same source again.
// `listWritable(board, listId)`: the per-list role exception of the copy's
// destination (decided 2026-11-18, TODO.md); a refusing list skips the copy.
export async function copyRuleCard({ activity, action, cache, canWrite, listWritable = async () => true }) {
const destinationId = action.boardId || activity.boardId;
if (![activity.cardId, activity.boardId, activity.userId, destinationId,
action.listId, action.swimlaneId].every(value => typeof value === 'string' && value)) return null;
const key = action._id || JSON.stringify([activity.boardId, destinationId, action.listId, action.swimlaneId]);
const chain = copies.getStore() || new Set();
if (chain.has(key)) return null;
return copies.run(new Set([...chain, key]), async () => {
const card = await cache.getCard(activity.cardId);
if (!card || card.boardId !== activity.boardId || card.archived) return null;
const [source, destination, list, swimlane] = await Promise.all([
cache.getBoard(card.boardId), cache.getBoard(destinationId),
cache.getList(action.listId), cache.getSwimlane(action.swimlaneId),
]);
if (!source || !destination || source.archived || destination.archived ||
!canWrite(activity.userId, source) || !canWrite(activity.userId, destination) ||
!list || list.archived || list.boardId !== destinationId ||
!swimlane || swimlane.archived || swimlane.boardId !== destinationId) return null;
if (!(await listWritable(destination, list._id))) return null;
// Keep the cached source unchanged, including its placement and sort order.
const copy = Object.assign(Object.create(Object.getPrototypeOf(card)), card);
copy.sort = (await card.getSort(list._id, swimlane._id, false)) + 1;
return await copy.copy(destinationId, swimlane._id, list._id);
});
}