mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
`/b/undefined/board/<cardId>` instead of the real board.** On the server `ReactiveCache.getBoard()` is async and returns a Promise, but `Cards.board()` did not await it, so the synchronous `Card.originRelativeUrl()`/`absoluteUrl()` interpolated a Promise — `board._id` and `board.slug` were `undefined`, producing `/b/undefined/board/<cardId>` in card activity notification emails (the client UI was unaffected because `this.board()` is synchronous there). Fixed by making `Card.originRelativeUrl(board)`/`absoluteUrl(board)` accept an already-resolved board and fall back to `this.boardId` (always available synchronously) when the board is a Promise, and by passing the awaited board from `server/models/activities.js` so the correct board id and slug are used. Thanks to titver968 and xet7 ! Fixes #6427
36 lines
1.7 KiB
JavaScript
36 lines
1.7 KiB
JavaScript
'use strict';
|
|
|
|
// Pure, isomorphic helper that builds a card's relative URL, matching the
|
|
// 'card' route '/b/:boardId/:slug/:cardId' (config/router.js).
|
|
//
|
|
// Why this is not just a template literal inline in Card.originRelativeUrl:
|
|
// on the server ReactiveCache.getBoard() (used by Card.board()) is async and
|
|
// returns a Promise, not a board document. Interpolating that Promise straight
|
|
// into the URL produced '/b/undefined/board/<cardId>' in card activity
|
|
// notification emails (issue #6427), because Promise._id / Promise.slug are
|
|
// undefined. This helper detects a Promise-shaped (thenable) board, ignores it,
|
|
// and falls back to the card's own boardId — which is always available
|
|
// synchronously — so the link stays valid even when the human-readable slug is
|
|
// unknown. Server callers should pass the already-awaited board to also get the
|
|
// correct slug.
|
|
|
|
function isThenable(value) {
|
|
return !!value && (typeof value === 'object' || typeof value === 'function')
|
|
&& typeof value.then === 'function';
|
|
}
|
|
|
|
function buildCardRelativeUrl(card, board) {
|
|
if (!card || !card._id) return undefined;
|
|
// A thenable is an unresolved Promise (server Card.board()); never read
|
|
// _id/slug off it — that is exactly what emitted '/b/undefined/board/...'.
|
|
const resolvedBoard = isThenable(board) ? undefined : board;
|
|
const boardId = (resolvedBoard && resolvedBoard._id) || card.boardId;
|
|
if (!boardId) return undefined;
|
|
const slug = (resolvedBoard && resolvedBoard.slug) || 'board';
|
|
// swimlaneId/listId were only ever appended as query params the route
|
|
// ignores, so they are dropped here.
|
|
return `/b/${boardId}/${slug}/${card._id}`;
|
|
}
|
|
|
|
module.exports = { isThenable, buildCardRelativeUrl };
|