Files
wekan/models/lib/scrumCopy.js
T
Lauri Ojansivu 727ceedd01 Let a card be in more than one release.
A card had exactly one release, scrum.releaseId. Jira import kept only the
first fix version of an issue and reported the rest as lost, Jira export
wrote no fix versions at all, and the card UI could not show or pick more
than one release.

A card's releases are now a list, scrum.releaseIds, with releaseId kept as
its first entry so older servers, importers and REST readers still see one.
Existing cards are not migrated: every reader goes through cardReleaseIds(),
which reads the list and the old single field the same way, so cards saved
either way work side by side, and a card moves to the new form on its next
Scrum save. A save with releaseIds replaces the list; a save with only
releaseId, from an older client, replaces the first release and keeps the
others, and null clears them. Every release must belong to the board,
checked in one query; duplicates collapse and a releaseId that contradicts
the list is refused.

Copies and moves to another board link each release by name. The native
transfer writes one release exactly as before and adds releaseIds only for
cards with several, and remaps each of them on import. Jira import maps every
fix version and Jira export writes them all as fixVersions. Board View /
Sprints shows each release's cards and how many are done, counting a card in
each of its releases. Scrum History checks and guards every release, and
rule e-mails name them all. The Product Backlog and card details use a
multiple select.

tests/scrumMultipleReleases.test.cjs covers the rules and fails if any code
reads the single field directly; a Playwright spec drives the UI. New text is
in English, pending Transifex.

Thanks to xet7 !
2026-10-08 11:51:44 +03:00

75 lines
3.9 KiB
JavaScript

'use strict';
// A card's or swimlane's Scrum metadata on another board (copy or move).
// Whole-board duplication defers metadata to the shared transfer remapper
// instead.
//
// The sprint, past sprints, release and board-relative rank belong to the
// board the item leaves. Maintainer decision of 2026-10-02: the sprint and the
// release are linked to the destination board's own sprint and release OF THE
// SAME NAME when exactly one matches - a planned or active sprint, a release
// that is not cancelled - and dropped otherwise. Past sprints and the rank are
// always dropped: they describe the board left. Issue type, acceptance criteria
// and a swimlane's purpose stay.
//
// `planning` names both boards' records: { from: { sprints, releases },
// to: { sprints, releases } }, each a list of { _id, name, state }. Without it
// (no planning loaded, or a board without Scrum) the references are dropped.
//
// A card has several releases since 2026-10-08 (models/lib/scrum.js
// cardReleaseIds): EACH is linked by name on its own, and the ones without a
// single match are dropped, so a card keeps every release the destination
// also has. One stored the old way, `releaseId` alone, stays that way; one
// with the list keeps the list and its first entry in step.
const { cardReleaseIds, withCardReleaseIds } = require('./scrum');
const BOARD_SCOPED = ['sprintId', 'pastSprintIds', 'releaseId', 'releaseIds', 'backlogRank'];
const OPEN_SPRINT = ['planned', 'active'];
function counterpart(sourceId, from = [], to = [], usable) {
const source = from.find(record => record._id === sourceId);
const name = source && typeof source.name === 'string' ? source.name.trim() : '';
if (!name) return null;
const matches = to.filter(record => usable(record) && typeof record.name === 'string' && record.name.trim() === name);
return matches.length === 1 ? matches[0]._id : null;
}
function boardScrum(scrum, planning) {
const result = { ...scrum };
for (const key of BOARD_SCOPED) delete result[key];
if (!planning) return result;
const sprintId = scrum.sprintId && counterpart(scrum.sprintId, planning.from?.sprints, planning.to?.sprints,
record => OPEN_SPRINT.includes(record.state));
const releaseIds = [...new Set(cardReleaseIds(scrum).map(id => counterpart(id, planning.from?.releases, planning.to?.releases,
record => record.state !== 'cancelled')).filter(Boolean))];
if (sprintId) result.sprintId = sprintId;
if (Array.isArray(scrum.releaseIds)) return withCardReleaseIds(result, releaseIds);
if (releaseIds.length) result.releaseId = releaseIds[0];
return result;
}
function copiedScrumMetadata(card, destinationBoardId, { omit = false, planning = null } = {}) {
if (omit || !card.scrum) return {};
let scrum = { ...card.scrum };
if (Array.isArray(scrum.pastSprintIds)) scrum.pastSprintIds = [...scrum.pastSprintIds];
if (Array.isArray(scrum.releaseIds)) scrum.releaseIds = [...scrum.releaseIds];
if (card.boardId !== destinationBoardId) scrum = boardScrum(card.scrum, planning);
return { scrum, scrumRevision: 1 };
}
// A card or swimlane MOVED to another board follows the same rule as a copy
// there (2026-10-02); the references used to stay and point at the old board's
// records. Nothing to change, nothing written; otherwise the revision moves on,
// as for any Scrum metadata write.
function movedScrumMetadata(doc, destinationBoardId, planning = null) {
if (!doc.scrum || doc.boardId === destinationBoardId ||
!BOARD_SCOPED.some(key => Object.prototype.hasOwnProperty.call(doc.scrum, key))) return {};
return { scrum: boardScrum(doc.scrum, planning), scrumRevision: (doc.scrumRevision || 0) + 1 };
}
// The records `planning` needs, for a board pair: what a server caller loads
// (server/lib/scrumPlanningPair.js).
const PLANNING_FIELDS = { _id: 1, name: 1, state: 1 };
module.exports = { copiedScrumMetadata, copiedCardScrum: copiedScrumMetadata, movedScrumMetadata, boardScrum,
PLANNING_FIELDS };