mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.
Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
61 lines
2.7 KiB
JavaScript
61 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, Meteor-free helpers that scope the Filter / MultiSelection card
|
|
// selectors to a single board. Extracted so they are unit-testable in plain
|
|
// Node (mirrors models/lib/calendarFilter.js and models/lib/swimlaneFilter.js).
|
|
//
|
|
// #2306 ("filter to selection"): the filter sidebar's "To selection" button
|
|
// queried the client card cache with ONLY the Filter's selector — no boardId —
|
|
// so it swept up matching cards from every board present in Minimongo (cards
|
|
// from a board being navigated away from, linked-board subscriptions, the
|
|
// notifications drawer, popup card data, ...). A later bulk action (archive,
|
|
// move, label, ...) on the selection then silently mutated cards on other
|
|
// boards. These helpers AND a `boardId` clause into the relevant selectors so
|
|
// both the selection query and every bulk action stay contained to the board
|
|
// the user is looking at.
|
|
|
|
// Scope a Filter selector (the object produced by Filter._getMongoSelector())
|
|
// to one board. Without a boardId (e.g. on a non-board page) the selector is
|
|
// returned unchanged. The board clause is combined via `$and` so it can never
|
|
// collide with the Filter's own top-level `$or`.
|
|
function boardScopedFilterSelector(filterSelector, boardId) {
|
|
const base =
|
|
filterSelector && typeof filterSelector === 'object' ? filterSelector : {};
|
|
if (!boardId) return base;
|
|
return { $and: [base, { boardId }] };
|
|
}
|
|
|
|
// Selector for the cards of a multi-selection, scoped to one board. Bulk
|
|
// actions iterate the cards this selector matches, so even if a stale
|
|
// selection still holds ids from a previously visited board (the selection is
|
|
// not always reset on every navigation path), those foreign cards are never
|
|
// touched.
|
|
function boardScopedSelectionSelector(selectedCardIds, boardId) {
|
|
const selector = {
|
|
_id: { $in: Array.isArray(selectedCardIds) ? selectedCardIds : [] },
|
|
};
|
|
if (boardId) selector.boardId = boardId;
|
|
return selector;
|
|
}
|
|
|
|
// Keep only the card ids that belong to `boardId`. `getCard` is a lookup
|
|
// (id -> card doc or undefined/null). Ids whose card cannot be found or has no
|
|
// boardId are kept (they cannot be positively identified as foreign, and a
|
|
// card missing from the cache cannot be acted on anyway); ids whose card
|
|
// verifiably lives on ANOTHER board are dropped. Without a boardId or lookup
|
|
// function the input is returned unchanged.
|
|
function cardIdsOnBoard(cardIds, boardId, getCard) {
|
|
if (!Array.isArray(cardIds)) return cardIds;
|
|
if (!boardId || typeof getCard !== 'function') return cardIds;
|
|
return cardIds.filter(cardId => {
|
|
const card = getCard(cardId);
|
|
return !card || !card.boardId || card.boardId === boardId;
|
|
});
|
|
}
|
|
|
|
export {
|
|
boardScopedFilterSelector,
|
|
boardScopedSelectionSelector,
|
|
cardIdsOnBoard,
|
|
};
|