Files
wekan/models/lib/cardLinkRedirect.js
T
Lauri Ojansivu d6908cf418 Convert client-reachable CJS helpers from CommonJS to ES modules (2/2).
A transitive walk from client/main.js found the remaining CommonJS
(module.exports) helpers that the rspack client build pulls into the ES
module graph and rejects: 3 client/lib helpers (cardDragGeometry,
inlinedFormManager, popupOffset), 4 imports/lib helpers (boardAutoScroll,
datePickerTime, fileNameDisplay, staleWhileRevalidate), imports/simpleSchema
(its meteor/aldeed:simple-schema require becomes a namespace import),
imports/i18n/loadHelpers, and 4 more models/lib helpers (cardLinkRedirect,
sandstormAutoOpen, securityCategories, securityLogFormat). All become
`export { ... }`; their .cjs unit tests use `await import(...js)`.

The only CJS files still reachable in the walk are server-only: the
server/lib/* files (Meteor never bundles server/ to the client) and the
fs-using models/lib file-storage helpers (reached only via the server-side
fileStoreStrategy; they would fail on require("fs") if they were actually in
the client bundle). Those correctly stay CommonJS.

Full tests/*.test.cjs suite: same 7 pre-existing failures, no new ones.
2026-07-23 18:59:30 +03:00

28 lines
1.2 KiB
JavaScript

'use strict';
// Pure decision for #4758 ("Link to a card should still work when the card was
// moved to another board"). A card URL is /b/:boardId/:slug/:cardId; after the
// card is moved, :boardId is the OLD board, which no longer contains the card, so
// the link would open the old board and find nothing.
//
// The client resolves the card via the permission-checked `card` publication
// (server/publications/cards.js — it only returns the card when the current user
// MAY see the card's board). Given the URL's boardId and that resolved card doc,
// this returns the board id to redirect to so the card opens in its CURRENT
// board, or null when no redirect is needed or possible:
// - card missing (moved to a board the user cannot access, deleted, or not yet
// loaded) -> null: stay on the URL's board (the card simply will not show);
// - card already on the URL's board (the normal case) -> null;
// - card on a DIFFERENT board the user can see -> that board's id (redirect).
function cardBoardRedirectTarget(urlBoardId, card) {
if (!card || typeof card.boardId !== 'string' || card.boardId.length === 0) {
return null;
}
if (card.boardId === urlBoardId) {
return null;
}
return card.boardId;
}
export { cardBoardRedirectTarget };