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.
54 lines
2.5 KiB
JavaScript
54 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// Pure helpers deciding which boards may be picked as a destination in the
|
|
// IFTTT-Rules "move card to the board" / "link card to the board" selectors.
|
|
// Extracted from client/components/rules/actions/boardActions.js so the choice
|
|
// is unit-testable without Meteor.
|
|
//
|
|
// #5698 (Impossible to select other board in rules): the board dropdown used to
|
|
// filter the (already access-scoped) client cache with `'members.userId': me`,
|
|
// i.e. it only kept boards where the user has a DIRECT member entry. A user who
|
|
// reaches a board through an Organization, Team or email-domain share — but is
|
|
// not listed individually in board.members — got an EMPTY dropdown (not even the
|
|
// current board showed up), while a colleague who was a direct member saw the
|
|
// boards. This mirrors the board-list publication / Boards.userBoards() rule:
|
|
// public OR active member OR active org OR active team OR active domain.
|
|
|
|
function hasActive(list, predicate) {
|
|
return Array.isArray(list) && list.some(entry => entry && predicate(entry));
|
|
}
|
|
|
|
// Does `board` match `ctx`'s visibility? ctx = { userId, orgIds, teamIds,
|
|
// emailDomains } — the last three are plain id arrays (empty when absent).
|
|
function boardVisibleToUserContext(board, ctx) {
|
|
if (!board || !ctx) return false;
|
|
if (board.permission === 'public') return true;
|
|
if (hasActive(board.members, m => m.userId === ctx.userId && !!m.isActive)) {
|
|
return true;
|
|
}
|
|
const inSet = (list, key, ids) =>
|
|
Array.isArray(ids) &&
|
|
hasActive(list, entry => !!entry.isActive && ids.includes(entry[key]));
|
|
if (inSet(board.orgs, 'orgId', ctx.orgIds)) return true;
|
|
if (inSet(board.teams, 'teamId', ctx.teamIds)) return true;
|
|
if (inSet(board.domains, 'domain', ctx.emailDomains)) return true;
|
|
return false;
|
|
}
|
|
|
|
// May this board appear in the rules board selector for `ctx`?
|
|
// Excludes archived boards, non-'board' types (e.g. template containers), the
|
|
// user's own templates board, and internal caret-wrapped helper boards
|
|
// (`^Subtasks^` etc.), then requires the board to be visible to the user.
|
|
function canSelectBoardInRules(board, ctx, templatesBoardId) {
|
|
if (!board || !ctx) return false;
|
|
if (board.archived) return false;
|
|
if (board.type && board.type !== 'board') return false;
|
|
if (typeof board.title === 'string' && /^\^.*\^$/.test(board.title)) {
|
|
return false;
|
|
}
|
|
if (templatesBoardId && board._id === templatesBoardId) return false;
|
|
return boardVisibleToUserContext(board, ctx);
|
|
}
|
|
|
|
export { canSelectBoardInRules, boardVisibleToUserContext };
|