Files
wekan/server/methods/repairBoardData.js
T
Lauri Ojansivu 136a14c88a Shared board data-repairs run on board open AND during the MongoDB <-> SQLite migration, shown in one blue, Product-name-branded progress dashboard.
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 !
2026-07-22 16:22:39 +03:00

41 lines
1.7 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { ReactiveCache } from '/imports/reactiveCache';
import { detectBoardRepairs, runBoardRepair } from '/server/lib/repairBoardData';
// Meteor methods behind the board-open self-heal (client/components/boards/
// boardBody.js -> maybeRepairBoard). The heavy lifting lives in
// /server/lib/repairBoardData.js, shared with the DB text migration.
Meteor.methods({
// Detection: called cheaply when a board opens. Board members may check; only a
// board admin may repair (canRepair), so the client auto-repairs only when there
// is something to fix AND the viewer is allowed to fix it.
async boardRepairNeeded(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const board = await ReactiveCache.getBoard(boardId);
if (!board || !board.hasMember(this.userId)) {
throw new Meteor.Error('not-authorized', 'You must be a board member.');
}
const counts = await detectBoardRepairs(boardId);
return { ...counts, canRepair: board.hasAdmin(this.userId) === true };
},
// Repair: board-admin only. Runs the shared repair set (#6484 list-unbind +
// missing-swimlane and orphaned cards). Idempotent. Returns what was fixed.
async repairBoardData(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const board = await ReactiveCache.getBoard(boardId);
if (!board || !board.hasAdmin(this.userId)) {
throw new Meteor.Error('not-authorized', 'You must be a board admin to repair this board.');
}
return runBoardRepair(boardId);
},
});