mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The Summary page reported "Broken cards N" and told the admin to "open the board to auto-repair, or run the repair migration", but there was no button anywhere to run one - and worse, no repair in the app could actually clear that count. countBrokenCards() counts every card missing a boardId OR a swimlaneId OR a listId. repairAllBoards() walks only NON-ARCHIVED boards and only ever sets swimlaneId, so three kinds of counted card could never be repaired by anything: cards on an archived board, cards with a missing listId, and cards with no boardId at all. The count sat there forever with nothing to press. The new repairBrokenCards method (admin only) runs the standard per-board pass and then closes those gaps: orphaned-swimlane cards on archived boards, and cards missing a listId and/or swimlaneId on any board, are assigned to that board's first usable list/swimlane (creating a default one if the board has none). Each board resolves its default list/swimlane once rather than once per card. Cards with no boardId cannot be placed on any board - guessing would drop a user's card onto an unrelated board - so they are reported back as `unfixable` and left alone, never deleted, and the result line says so instead of leaving a count that never reaches zero unexplained. What counts as broken now lives in one pure module, models/lib/brokenCardsRepair.js, used by BOTH the count and the repair, so they can no longer drift apart and leave the admin pressing a button that does not move the number. Progress is persisted through setBoardRepairStatus, so a running repair shows up in the same "in progress" list as the startup pass. Adds unit tests (positive + negative) for the shared rule, including the regression itself: every card the count reports as broken must be either repairable or explicitly unfixable, never silently neither. Thanks to xet7 !
119 lines
4.3 KiB
JavaScript
119 lines
4.3 KiB
JavaScript
import { TAPi18n } from '/imports/i18n';
|
|
|
|
// Admin Panel → Problems → Summary page: a checkbox list of problem areas
|
|
// (Security / Speed / Tests) with each area's menu path and its count of NEW
|
|
// (unacknowledged) problems, plus ONE Acknowledge button that acknowledges every
|
|
// checked area. This is the ONLY place problems are acknowledged — the Security /
|
|
// Speed / Tests detail pages are read-only.
|
|
// Design: docs/Security/Remediation/WeKan.md. Data: the admin-only
|
|
// eventLogProblemAreas / acknowledgeEventLog methods (models/eventLog.js).
|
|
|
|
const STREAM_LABEL_KEY = {
|
|
security: 'securityReportTitle',
|
|
speed: 'speedReportTitle',
|
|
tests: 'testsReportTitle',
|
|
};
|
|
|
|
Template.problemsSummary.onCreated(function () {
|
|
this.areas = new ReactiveVar([]);
|
|
// "Broken cards N" repair button state (see the repairBrokenCards method in
|
|
// server/methods/repairBrokenCards.js).
|
|
this.repairRunning = new ReactiveVar(false);
|
|
this.repairResult = new ReactiveVar('');
|
|
// Status overview: everything in progress (migrations / repairs) + detected
|
|
// problems (broken cards, login-page "Must be logged in" causes). Same data as
|
|
// `snap run wekan.problems`.
|
|
this.status = new ReactiveVar(null);
|
|
this.reload = () => {
|
|
Meteor.call('eventLogProblemAreas', (err, res) => {
|
|
if (!err) this.areas.set(Array.isArray(res) ? res : []);
|
|
});
|
|
Meteor.call('systemStatusReport', (err, res) => {
|
|
if (!err) this.status.set(res || null);
|
|
});
|
|
};
|
|
this.reload();
|
|
this.timer = Meteor.setInterval(this.reload, 30000);
|
|
});
|
|
|
|
Template.problemsSummary.onDestroyed(function () {
|
|
if (this.timer) Meteor.clearInterval(this.timer);
|
|
});
|
|
|
|
Template.problemsSummary.helpers({
|
|
areas() {
|
|
return Template.instance().areas.get();
|
|
},
|
|
hasProblems() {
|
|
return (Template.instance().areas.get() || []).length > 0;
|
|
},
|
|
areaLabel(stream) {
|
|
return TAPi18n.__(STREAM_LABEL_KEY[stream] || stream);
|
|
},
|
|
statusOverview() {
|
|
const s = Template.instance().status.get();
|
|
return s && s.overview ? s.overview : null;
|
|
},
|
|
inProgress() {
|
|
const s = Template.instance().status.get();
|
|
return s && s.overview ? s.overview.inProgress : [];
|
|
},
|
|
statusProblems() {
|
|
const s = Template.instance().status.get();
|
|
return s && s.overview ? s.overview.problems : [];
|
|
},
|
|
// Only the broken-cards problem gets a Repair button — the other detected
|
|
// problems (login-page causes) are configuration, not repairable data.
|
|
isBrokenCards(problem) {
|
|
return !!problem && problem.id === 'broken-cards';
|
|
},
|
|
repairRunning() {
|
|
return Template.instance().repairRunning.get();
|
|
},
|
|
repairResult() {
|
|
return Template.instance().repairResult.get();
|
|
},
|
|
});
|
|
|
|
Template.problemsSummary.events({
|
|
// Run the broken-card repair migration over every board. The button stays
|
|
// disabled while it runs; when it finishes the overview is reloaded so the
|
|
// "Broken cards N" count reflects the repair straight away.
|
|
'click .js-repair-broken-cards'(event, templateInstance) {
|
|
event.preventDefault();
|
|
if (templateInstance.repairRunning.get()) return;
|
|
templateInstance.repairRunning.set(true);
|
|
templateInstance.repairResult.set('');
|
|
Meteor.call('repairBrokenCards', (error, res) => {
|
|
templateInstance.repairRunning.set(false);
|
|
if (error) {
|
|
templateInstance.repairResult.set(error.reason || error.message || String(error));
|
|
return;
|
|
}
|
|
const fixed =
|
|
(res.cardsAssigned || 0) +
|
|
(res.cardsRescued || 0) +
|
|
(res.archivedCardsFixed || 0) +
|
|
(res.listsAssigned || 0) +
|
|
(res.swimlanesAssigned || 0);
|
|
// Cards with no boardId at all cannot be placed on any board, so say so
|
|
// explicitly instead of leaving a count that never reaches zero unexplained.
|
|
const unfixable = res.unfixable || 0;
|
|
templateInstance.repairResult.set(
|
|
unfixable > 0
|
|
? TAPi18n.__('repair-broken-cards-done-unfixable', { fixed, unfixable })
|
|
: TAPi18n.__('repair-broken-cards-done', { fixed }),
|
|
);
|
|
templateInstance.reload();
|
|
});
|
|
},
|
|
|
|
'click .js-ack-checked'(event, templateInstance) {
|
|
const streams = Array.from(templateInstance.findAll('.js-problem-check:checked'))
|
|
.map(el => el.getAttribute('data-stream'))
|
|
.filter(Boolean);
|
|
if (!streams.length) return;
|
|
Meteor.call('acknowledgeEventLog', streams, () => templateInstance.reload());
|
|
},
|
|
});
|