Hub 2.6.1: the Failed jobs filter and alert search no longer answer 500

The status list had timed_out, which isn't a JobStatus (the enum has
expired), and alert search used contains on the EventLevel enum: Postgres
refused both queries. JOB_STATUSES now matches the enum (tested against
schema.prisma); Failed = failed,expired; unknown products refused; level
matched by name. All list queries checked on Postgres.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-19 21:58:28 +02:00
co-authored by Claude Opus 5.5
parent 22d78ac81c
commit 3893fb91e0
9 changed files with 39 additions and 10 deletions
+2 -1
View File
@@ -297,7 +297,8 @@ router.get('/events', wrap(async (req, res) => {
if (term) {
and.push({ OR: [
{ message: { contains: term, mode: 'insensitive' } },
{ level: { contains: term, mode: 'insensitive' } },
// `level` is an enum, which can't be searched as text: the levels whose name matches.
...(['info', 'warning', 'critical'].filter(l => l.includes(term.toLowerCase())).length ? [{ level: { in: ['info', 'warning', 'critical'].filter(l => l.includes(term.toLowerCase())) } }] : []),
{ install: { name: { contains: term, mode: 'insensitive' } } },
{ install: { url: { contains: term, mode: 'insensitive' } } },
] });
+7 -2
View File
@@ -600,7 +600,10 @@ async function lookForUnlinked(install, now = new Date()) {
}
}
const JOB_STATUSES = ['queued', 'scheduled', 'delivered', 'succeeded', 'failed', 'rolled_back', 'refused', 'missed', 'cancelled', 'timed_out'];
// Exactly the JobStatus enum (prisma/schema.prisma; a test checks it): a value Postgres doesn't
// know fails the whole query. 2.6.1: 2.6.0 listed a "timed_out" that doesn't exist, so the Failed
// filter answered 500 every time. Unknown values from a request are dropped.
const JOB_STATUSES = ['scheduled', 'queued', 'delivered', 'succeeded', 'failed', 'rolled_back', 'refused', 'expired', 'missed', 'cancelled'];
/** The jobs list's filters (Hub 2.6.0, GET /api/admin/jobs). */
async function listWhere(q = {}) {
@@ -616,6 +619,8 @@ async function listWhere(q = {}) {
if (q.deploymentId) and.push({ deploymentId: String(q.deploymentId) });
// By product or church: the matching installs first, then their jobs.
const term = searchTerm(q.q);
// Products are an enum too: an unknown one is refused, not sent to the database.
if (q.product && !PRODUCT_NAMES[String(q.product)]) throw fail(400, 'BAD_REQUEST', 'Unknown product.');
if (q.product || term) {
const dWhere = { AND: [
...(q.product ? [{ product: String(q.product) }] : []),
@@ -947,6 +952,6 @@ async function seedDemo({ deploymentId, profile, confirm }, admin, now = new Dat
module.exports = {
WINDOW_MIN, SCHEDULE_MIN_HOURS, EMERGENCY_MIN_MINUTES, setDemo, seedDemo,
makeJob, signedJob, jobConfig, poll, receiveReport, finish, tick, advanceBatch,
linkFromStatus, listWhere, lookForUnlinked, newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
JOB_STATUSES, linkFromStatus, listWhere, lookForUnlinked, newInstall, proxyDone, scheduleUpdate, cancelJob, scheduleUninstall, neverInstalled, removeFailedInstall, receiveExport, linkDeployment, scheduleAdopt, queueCentralCheck, runNow,
fastPanelText, jobReportText, scheduleWarnings, requireTotp, agentOnline, siteAdminEmail,
};