feat(audit): every row keeps its date; dividers for Today, Yesterday, Last 7 days, Older (#5214)

The operator found "Today 08:03" in place of a date odd on the audit log,
and asked for the recency groups as dividers instead. |when now always
writes the date ("Thu 8 Oct 08:03"); mark_day_groups gives each entry its
group in the reader's zone, and a divider row opens each group. A scrolled
page carries the group the last one ended in, so it is not opened twice.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 08:22:03 -04:00
co-authored by Claude Opus 5.5
parent 31e93e96cf
commit 7a444da871
7 changed files with 100 additions and 26 deletions
+6 -3
View File
@@ -1,10 +1,11 @@
from __future__ import annotations
import json
from quart import Blueprint, render_template, request, current_app
from quart import Blueprint, render_template, request, current_app, session
from sqlalchemy import select
from steward.ansible.inventory_gen import scope_labels
from steward.audit.service import AREAS, action_text, detail_facts, entity_labels
from steward.audit.service import AREAS, action_text, detail_facts, entity_labels, mark_day_groups
from steward.auth.middleware import require_role
from steward.core import formatting as fmt
from steward.core.paging import keyset, next_page
from steward.models.audit import AuditEvent
from steward.models.users import UserRole
@@ -46,7 +47,9 @@ async def list_events():
item["action"] = action_text(e.action)
item["facts"] = detail_facts(item["detail"], scopes)
ctx = {"events": parsed, "after": after, "action_filter": action_filter, "areas": AREAS}
last_group = mark_day_groups(parsed, fmt.zone(session.get("tz")), request.args.get("group", ""))
ctx = {"events": parsed, "after": after, "action_filter": action_filter, "areas": AREAS,
"last_group": last_group}
if request.args.get("before"):
return await render_template("audit/_rows.html", **ctx)
return await render_template("audit/list.html", **ctx)
+13
View File
@@ -9,6 +9,7 @@ from __future__ import annotations
from sqlalchemy import select
from steward.ansible.inventory_gen import run_title, scope_labels
from steward.core.formatting import day_group
from steward.models.alerts import AlertRule, MaintenanceWindow
from steward.models.ansible import AnsibleRun
from steward.models.ansible_inventory import AnsibleGroup, AnsibleTarget
@@ -207,3 +208,15 @@ def detail_facts(detail: dict, scopes: dict[str, str]) -> list[dict]:
text = _plain(value)
facts.append({"label": label, "text": text, "url": url})
return facts
def mark_day_groups(items: list[dict], tz, group: str = "", now=None) -> str:
"""Give each newest-first entry its recency group (formatting.day_group,
in the reader's zone) and whether it opens one, so the page draws a
divider there. `group` is the one the previous page ended in: a group
split across pages is opened once. Returns the group this page ends in."""
for item in items:
item["group"] = day_group(item["event"].timestamp, tz, now)
item["opens_group"] = item["group"] != group
group = item["group"]
return group