Hub 2.13.0: clear alerts by hand, sortable billing tables, no stray tab scrollbars
- Alerts: Clear one or Clear all. A cleared alert leaves the open list and dashboard count but stays open to the checks, so it isn't re-raised or re-emailed until the problem goes away and comes back. Audited. Migration 20261123120000_alert_cleared. - Billing invoices, payments, churches and a customer's invoices/payments can be sorted by column (remembered per browser). Invoices show the due date in its own column. - Tabs: the grey rule is an inset shadow, so the active underline no longer overflows the row by a pixel and makes it scroll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,9 @@ const { emailList } = require('../utils/emails');
|
||||
const router = express.Router();
|
||||
router.use(protect);
|
||||
|
||||
/** An open alert: a warning or critical problem that is neither resolved nor cleared by hand (Hub 2.13.0). */
|
||||
const OPEN_ALERT = { resolvedAt: null, clearedAt: null, level: { not: 'info' } };
|
||||
|
||||
const smtpTestLimiter = rateLimit({ windowMs: 15 * 60 * 1000, max: 10, standardHeaders: true, legacyHeaders: false, message: { message: 'Too many test emails — wait a few minutes.' } });
|
||||
|
||||
const wrap = fn => (req, res) => fn(req, res).catch(e => {
|
||||
@@ -76,7 +79,7 @@ router.get('/dashboard', wrap(async (req, res) => {
|
||||
const [customers, licences, openAlerts, billed, sentInvoices] = await Promise.all([
|
||||
prisma.customer.count({ where: { archivedAt: null } }),
|
||||
prisma.licence.groupBy({ by: ['product', 'status'], _count: { _all: true } }),
|
||||
prisma.installEvent.count({ where: { resolvedAt: null, level: { not: 'info' } } }),
|
||||
prisma.installEvent.count({ where: OPEN_ALERT }),
|
||||
prisma.customer.findMany({ where: { billingCycle: { not: 'none' } }, include: { licences: { include: { install: true } } } }),
|
||||
prisma.invoice.findMany({ where: { status: 'sent' }, include: { payments: true } }),
|
||||
]);
|
||||
@@ -335,7 +338,7 @@ router.post('/installs/:id/public-key/clear', wrap(async (req, res) => {
|
||||
// Hub 2.6.0: both paged (?page, ?pageSize) with a search (?q), instead of the last 200 / 300.
|
||||
router.get('/events', wrap(async (req, res) => {
|
||||
const and = [];
|
||||
if (req.query.open === 'true') and.push({ resolvedAt: null, level: { not: 'info' } });
|
||||
if (req.query.open === 'true') and.push(OPEN_ALERT);
|
||||
const term = searchTerm(req.query.q);
|
||||
if (term) {
|
||||
and.push({ OR: [
|
||||
@@ -350,6 +353,23 @@ router.get('/events', wrap(async (req, res) => {
|
||||
res.json({ events: out.rows, total: out.total, page: out.page, pageSize: out.pageSize, pages: out.pages });
|
||||
}));
|
||||
|
||||
// Hub 2.13.0: clear an open alert by hand (one, or every open one). It stays open to the checks, so it
|
||||
// is resolved as usual when the problem goes away, and raised (and emailed) again only if it comes back.
|
||||
router.post('/events/clear', wrap(async (req, res) => {
|
||||
const out = await prisma.installEvent.updateMany({ where: OPEN_ALERT, data: { clearedAt: new Date() } });
|
||||
await audit(req, 'alerts_cleared', null, { count: out.count });
|
||||
res.json({ cleared: out.count });
|
||||
}));
|
||||
|
||||
router.post('/events/:id/clear', wrap(async (req, res) => {
|
||||
const event = await prisma.installEvent.findUnique({ where: { id: req.params.id }, include: { install: { select: { name: true } } } });
|
||||
if (!event) throw bad('Alert not found', 404);
|
||||
if (event.level === 'info' || event.resolvedAt || event.clearedAt) throw bad('That alert is not open.', 409);
|
||||
const cleared = await prisma.installEvent.update({ where: { id: event.id }, data: { clearedAt: new Date() } });
|
||||
await audit(req, 'alert_cleared', event.id, { install: event.install?.name, message: event.message });
|
||||
res.json({ id: cleared.id, clearedAt: cleared.clearedAt });
|
||||
}));
|
||||
|
||||
router.get('/audit', wrap(async (req, res) => {
|
||||
const term = searchTerm(req.query.q);
|
||||
const where = term ? { OR: [
|
||||
|
||||
Reference in New Issue
Block a user