mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 10:48:06 -05:00
The board-open self-heal is broadened from the #6484 list-unbind alone to a shared repair set (models/lib/boardRepair.js planner + server/lib/repairBoardData.js): - #6484: lists wrongly bound to a swimlane -> cleared back to board-wide, so the list stops "disappearing" from the other swimlanes; - cards with no swimlaneId (null/''/missing), which never render in the Swimlanes view -> assigned to the board's first swimlane; - orphaned cards whose swimlaneId points at a DELETED swimlane (invisible cards) -> reassigned to the first swimlane. A card on an existing but archived swimlane is NOT treated as orphaned. The same repair set now runs in BOTH places: - Board open: boardBody.js maybeRepairBoard -> boardRepairNeeded / repairBoardData (server/methods/repairBoardData.js), once per board, admin-gated, fire-and-forget. - MongoDB <-> FerretDB v1 (SQLite) text migration: migrateTextDatabase runs repairAllBoards() on the live database BEFORE copying, so the migrated copy is clean too. It reports a new "repairing" phase (boardsDone/boardsTotal/repaired). Both flows drive ONE shared progress dashboard (migrationProgress), now: - mounted app-wide (defaultLayout) so it shows for an Admin Panel database migration as well as a board-open repair; - fed from the DB-migration status poll (attachments.js driveMigrationDashboard); - styled in WeKan blue (#2980b9) instead of the old purple/green; - branded with the configured Product name (from the earlier commit). Tests: tests/boardRepair.test.cjs (planner + server/migration/dashboard source guards, 11 checks) and the updated tests/listUnbindRepair.test.cjs pass. Thanks to xet7 !
61 lines
2.5 KiB
JavaScript
61 lines
2.5 KiB
JavaScript
'use strict';
|
|
|
|
// Pure planner for the board data-repairs run both on board open and during the
|
|
// MongoDB <-> FerretDB v1 (SQLite) text-data migration. Given one board's raw
|
|
// swimlanes / lists / cards (plain arrays), it decides what to fix — no DB access,
|
|
// so it is unit-testable. The server side (server/lib/repairBoardData.js) applies
|
|
// the plan.
|
|
//
|
|
// Repairs planned:
|
|
// * #6484 list-unbind — a board-wide list (swimlaneId null) that was wrongly
|
|
// bound to a single swimlane, so it "disappeared" from the other swimlanes;
|
|
// its swimlaneId is cleared back to null. (models/lib/listUnbindRepair.js)
|
|
// * missing-swimlane cards — a card with no swimlaneId (null / '' / missing),
|
|
// which never renders in the Swimlanes view; assigned to the first swimlane.
|
|
// * orphaned cards — a card whose swimlaneId points at a swimlane that no longer
|
|
// exists on the board (deleted swimlane), so the card is invisible; reassigned
|
|
// to the first swimlane. (An ARCHIVED swimlane still exists, so cards on it are
|
|
// left alone — that is not an orphan.)
|
|
|
|
const { listsToUnbind } = require('./listUnbindRepair');
|
|
|
|
function planBoardRepair(swimlanes, lists, cards) {
|
|
const swimlaneIds = new Set(
|
|
(Array.isArray(swimlanes) ? swimlanes : [])
|
|
.filter(s => s && typeof s._id === 'string' && s._id.length > 0)
|
|
.map(s => s._id),
|
|
);
|
|
|
|
// #6484: lists wrongly bound to a swimlane -> clear back to board-wide (null).
|
|
const listsUnbind = listsToUnbind(lists);
|
|
|
|
const cardsMissing = []; // no swimlaneId at all
|
|
const cardsOrphaned = []; // swimlaneId points at a swimlane not on the board
|
|
for (const card of Array.isArray(cards) ? cards : []) {
|
|
if (!card || typeof card._id !== 'string' || card._id.length === 0) continue;
|
|
const sid = card.swimlaneId;
|
|
if (typeof sid !== 'string' || sid.length === 0) {
|
|
cardsMissing.push(card._id);
|
|
} else if (!swimlaneIds.has(sid)) {
|
|
cardsOrphaned.push(card._id);
|
|
}
|
|
}
|
|
|
|
return { listsUnbind, cardsMissing, cardsOrphaned };
|
|
}
|
|
|
|
// Flatten a plan to the counts shown in the progress dashboard / Problems view.
|
|
function repairCounts(plan) {
|
|
const listsUnbound = (plan && plan.listsUnbind ? plan.listsUnbind : []).length;
|
|
const cardsAssigned = (plan && plan.cardsMissing ? plan.cardsMissing : []).length;
|
|
const cardsRescued = (plan && plan.cardsOrphaned ? plan.cardsOrphaned : []).length;
|
|
return {
|
|
listsUnbound,
|
|
cardsAssigned,
|
|
cardsRescued,
|
|
total: listsUnbound + cardsAssigned + cardsRescued,
|
|
};
|
|
}
|
|
|
|
module.exports = { planBoardRepair, repairCounts };
|