fix(server): a locked audit retention also fixes the audit step and the switch

The audit retention in force ignored the audit clean-up's steps: with the
audit step unticked nothing was deleted, yet Settings › Logs still showed the
age limit. It is now 0 without that step, and setting a limit (Settings › Logs
or CHRONOS_AUDIT_RETENTION_DAYS at start) ticks the step again, so a saved or
fixed retention always takes effect. While the variable fixes a limit above 0,
an edit that drops the step is 409 setting_locked like turning the schedule off.

The admin panel's Scheduled tab disables what the variable fixes (the row's
switch, the form's Enabled and audit step, the age limit) with the locked
tooltip, and points a setting_locked refusal at the field actually refused.

The Copies kept tooltips now say the backups folder keeps as many copies as
the backup schedule that keeps the most; the LastDone and Newest comments
state the real first-copy rule; Keep audit is documented last-writer-wins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-10-27 10:39:49 +01:00
1 parent 94a5466c9f
commit e6e69782ed
12 files changed
+125 -45

No files matched your search

+45 -13
View File
@@ -30,8 +30,11 @@ const PARAM_KEYS = {
"cleanup.steps": "Steps", "cleanup.olderThanDays": "OlderDays",
};
const NUMBERS = { olderThanDays: 'min="0" max="3650"', percent: 'min="1" max="100"', keep: 'min="1" max="100"' };
/** Settings an environment variable fixes for a system schedule's age limit (ServerScheduleHost.LockedAgeOf). */
const LOCKED_AGES = { "audit-cleanup": ["AuditRetentionDays", "CHRONOS_AUDIT_RETENTION_DAYS"] };
/**
* Settings an environment variable fixes for a system schedule's age limit (ServerScheduleHost.LockedAgeOf): the setting,
* its variable and the steps the limit deletes with (ServerScheduleHost.AgedSteps).
*/
const LOCKED_AGES = { "audit-cleanup": { setting: "AuditRetentionDays", variable: "CHRONOS_AUDIT_RETENTION_DAYS", steps: ["audit"] } };
/** A schedule's name: a system schedule's in the panel's language (by its key), a user's as typed. */
export function scheduleName(schedule) {
@@ -195,6 +198,17 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
return schedules.find((s) => s.id === id);
}
/**
* What an environment variable fixes on the system schedule <paramref name="systemKey"/> whose age limit is
* <paramref name="days"/> (LOCKED_AGES), with the attributes of its fixed controls; null when nothing is fixed. While the
* limit deletes (more than 0 days) its switch and the steps it deletes with are fixed too (ScheduleEndpoints.ChangesLocked).
*/
function ageLock(systemKey, days) {
const age = LOCKED_AGES[systemKey];
if (!age || !locked.some((l) => l.toLowerCase() === age.setting.toLowerCase())) return null;
return { ...age, deletes: days > 0, attrs: `disabled title="${attr(t("Admin.Settings.Locked.Tip", age.variable))}"` };
}
/** Closes a schedule's runs and drops them. */
function forget(id) {
expanded.delete(id);
@@ -206,6 +220,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
const button = (act, key, extra = "") => `<button class="btn small${extra}" data-act="${act}" data-i18n="Admin.Schedules.${key}" data-i18n-title="Admin.Schedules.${key}.Tip"></button>`;
const buttons = button("run", "Run") + button("edit", "Edit") + (s.systemKey ? button("reset", "Reset") : button("delete", "Delete", " destructive"));
const when = recurrenceText(s.recurrence);
const lock = ageLock(s.systemKey, s.parameters?.olderThanDays ?? 0);
return `
<div class="row${s.enabled ? "" : " dim"}" role="row" data-key="${attr(s.id)}">
<span class="name-cell" role="cell"><button class="link ellipsis" data-toggle="${attr(s.id)}" aria-expanded="${expanded.has(s.id)}" aria-controls="runs-${attr(s.id)}"
@@ -216,7 +231,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
<span class="num nowrap" role="cell" title="${attr(t("Admin.Schedules.NextRun.Tip", zone))}">${escapeHtml(s.enabled ? zonedTime(s.nextRun, zone) : t("Admin.Schedules.Off"))}</span>
<span class="col-last ellipsis" role="cell">${lastResult(s)}</span>
<span role="cell"><input type="checkbox" role="switch" data-enable="${attr(s.id)}" ${s.enabled ? "checked" : ""}
aria-label="${attr(t("Admin.Schedules.EnabledFor", name))}" title="${attr(t("Admin.Schedules.Enabled.Tip"))}"></span>
aria-label="${attr(t("Admin.Schedules.EnabledFor", name))}" ${lock?.deletes ? lock.attrs : `title="${attr(t("Admin.Schedules.Enabled.Tip"))}"`}></span>
<span class="row-actions" role="cell">${buttons}</span>
</div>
${expanded.has(s.id) ? `<div class="row log-row" role="row"><div class="wide" role="cell" id="runs-${attr(s.id)}">${runsHtml(s)}</div></div>` : ""}`;
@@ -344,6 +359,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
const first = available.find((a) => a.available)?.name ?? "scan";
const draft = { recurrence: { every: 1, unit: "hours", time: "03:00", days: ["mon"], dayOfMonth: 1, ...(schedule?.recurrence ?? { kind: "daily" }) } };
const fixed = `disabled title="${attr(t("Admin.Schedules.Fixed.Tip"))}"`;
const lock = editing ? ageLock(schedule.systemKey, schedule.parameters?.olderThanDays ?? 0) : null;
const actionOptions = (editing && !available.some((a) => a.name === schedule.action) ? [{ name: schedule.action, available: false }] : available).map((a) =>
`<option value="${attr(a.name)}" ${a.name === (schedule?.action ?? first) ? "selected" : ""} ${a.available || a.name === schedule?.action ? "" : "disabled"}
title="${attr(a.available ? actionTip(a.name) : reasonTip(a.reason))}">${escapeHtml(actionLabel(a.name))}</option>`).join("");
@@ -363,7 +379,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
<select class="input" name="priority" data-i18n-title="Admin.Schedules.Priority.Tip">${PRIORITIES.map((p) =>
`<option value="${p}" ${p === (schedule?.priority ?? "background") ? "selected" : ""}>${escapeHtml(t(`Admin.Jobs.Priority.${cap(p)}`))}</option>`).join("")}</select></label>
<label class="check"><input type="checkbox" name="catchUp" ${schedule?.catchUp ?? true ? "checked" : ""} data-i18n-title="Admin.Schedules.CatchUp.Tip"><span data-i18n="Admin.Schedules.CatchUp"></span></label>
<label class="check"><input type="checkbox" name="enabled" ${schedule?.enabled ?? true ? "checked" : ""} data-i18n-title="Admin.Schedules.Enabled.Tip"><span data-i18n="Admin.Schedules.Enabled"></span></label>
<label class="check"><input type="checkbox" name="enabled" ${schedule?.enabled ?? true ? "checked" : ""} ${lock?.deletes ? lock.attrs : `data-i18n-title="Admin.Schedules.Enabled.Tip"`}><span data-i18n="Admin.Schedules.Enabled"></span></label>
<div class="buttons">
<button class="btn" type="button" id="close" data-i18n="Admin.Common.Cancel" data-i18n-title="Admin.Common.Cancel.Tip"></button>
<button class="btn primary" type="submit" data-i18n="${editing ? "Admin.Common.Save" : "Admin.Schedules.Create"}" data-i18n-title="${editing ? "Admin.Common.Save.Tip" : "Admin.Schedules.Create.Tip"}"></button>
@@ -398,7 +414,7 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
toast(t("Admin.Common.Saved"));
await load();
} catch (err) {
fieldError(form, err);
fieldError(form, err, schedule);
}
});
(form.querySelector("input:not([disabled]), select:not([disabled])"))?.focus();
@@ -433,26 +449,29 @@ export async function renderSchedules(root, { api, setMeta, actions, onEvent },
/** The parameters <paramref name="action"/> reads, filled from <paramref name="p"/>. */
function drawParameters(form, action, p, systemKey) {
const host = form.querySelector("#parameters");
const lockedAge = LOCKED_AGES[systemKey];
const ageLocked = lockedAge && locked.some((l) => l.toLowerCase() === lockedAge[0].toLowerCase());
const lock = ageLock(systemKey, p.olderThanDays ?? 0);
host.innerHTML = (PARAMETERS[action] ?? []).map((name) => {
const key = `Admin.Schedules.Param.${PARAM_KEYS[`${action}.${name}`]}`;
if (name === "steps") {
const tip = (step) => lock?.deletes && lock.steps.includes(step) ? lock.attrs : `title="${attr(stepTip(step))}"`;
return `<fieldset><legend data-i18n="${key}"></legend>${steps.map((step) => `<label class="check">
<input type="checkbox" name="step-${attr(step)}" value="${attr(step)}" ${(p.steps ?? []).includes(step) ? "checked" : ""} title="${attr(stepTip(step))}"><span>${escapeHtml(stepLabel(step))}</span></label>`).join("")}</fieldset>`;
<input type="checkbox" name="step-${attr(step)}" value="${attr(step)}" ${(p.steps ?? []).includes(step) ? "checked" : ""} ${tip(step)}><span>${escapeHtml(stepLabel(step))}</span></label>`).join("")}</fieldset>`;
}
if (name in NUMBERS) {
const lock = name === "olderThanDays" && ageLocked ? `disabled title="${attr(t("Admin.Settings.Locked.Tip", lockedAge[1]))}"` : `data-i18n-title="${key}.Tip"`;
return `<label><span data-i18n="${key}"></span><input class="input narrow num" type="number" name="${name}" ${NUMBERS[name]} value="${attr(p[name] ?? 0)}" ${lock}></label>`;
const fixed = name === "olderThanDays" && lock ? lock.attrs : `data-i18n-title="${key}.Tip"`;
return `<label><span data-i18n="${key}"></span><input class="input narrow num" type="number" name="${name}" ${NUMBERS[name]} value="${attr(p[name] ?? 0)}" ${fixed}></label>`;
}
return `<label class="check"><input type="checkbox" name="${name}" ${p[name] ? "checked" : ""} data-i18n-title="${key}.Tip"><span data-i18n="${key}"></span></label>`;
}).join("");
applyStrings(host);
}
/** An API failure on the side form: the field it concerns gets the error border, the message and the focus; a toast announces it. */
function fieldError(form, err) {
const field = fieldOf(form, err.code === "setting_locked" ? "parameters.olderThanDays" : err.code === "invalid_schedule" ? err.details : null);
/**
* An API failure on the side form of <paramref name="schedule"/> (null for a new one): the field it concerns gets the error
* border, the message and the focus; a toast announces it.
*/
function fieldError(form, err, schedule) {
const field = err.code === "setting_locked" ? lockedField(form, schedule) : fieldOf(form, err.code === "invalid_schedule" ? err.details : null);
const message = field && err.code === "invalid_schedule" ? invalidText(field) : errorText(err);
if (field) {
markInvalid(field, message);
@@ -517,6 +536,19 @@ function fieldOf(form, apiField) {
return el[name] ?? null;
}
/**
* The form field a <c>setting_locked</c> refusal concerns, in the server's order (ScheduleEndpoints.ChangesLocked): the
* switch turned off while the limit deletes, the age limit changed, a step the limit deletes with unticked; else the age limit.
*/
function lockedField(form, schedule) {
const el = form.elements;
const days = schedule?.parameters?.olderThanDays ?? 0;
if (days > 0 && !el.enabled.checked) return el.enabled;
if (el.olderThanDays && Number(el.olderThanDays.value) !== days) return el.olderThanDays;
const step = days > 0 ? (LOCKED_AGES[schedule?.systemKey]?.steps ?? []).map((s) => el[`step-${s}`]).find((box) => box && !box.checked) : null;
return step ?? el.olderThanDays ?? null;
}
function actionTip(action) {
const key = `Admin.Schedules.Action.${pascal(action)}.Tip`;
return has(key) ? t(key) : action;