feat: Add display name to user profiles

Introduce `display_name` field to `User` struct for human-readable names
in the UI.
This falls back to the user's `slug` if not provided.

Update `AuthenticatedWebUser` and `MyCasesTemplate` to use this new
field for rendering.
Add tests for parsing `display_name` and ensure fallback logic works
correctly.
Update `users.toml.example` to document the new field.
This commit is contained in:
2026-05-04 11:46:19 +02:00
parent 03129ad592
commit 2fc7f8ddd2
6 changed files with 97 additions and 24 deletions
+12 -14
View File
@@ -270,7 +270,10 @@ struct DateGroup {
#[derive(Template)]
#[template(path = "my_cases.html")]
struct MyCasesTemplate {
slug: String,
/// Human-readable label rendered in the `<h1>`. Resolved upstream
/// from `users.toml` (`display_name` field, falling back to `slug`)
/// so the template stays presentation-only.
display_name: String,
groups: Vec<DateGroup>,
total: usize,
/// True iff the session user is an admin — toggles full case_id display.
@@ -572,16 +575,17 @@ pub async fn handle_my_cases(
// flip (new transcripts in, stale document, ...).
auto_trigger::try_enqueue_all_for_user(&user_root, &pipeline.analyze_tx, &events_tx).await;
// Single users.toml lookup feeds both the retention sweep below and
// the per-user preview-lines cap further down. Cheaper than walking
// `config.users` twice for the same slug on every page render.
let user_record = config.users.iter().find(|u| u.slug == user.slug);
let retention = user_record.map(|u| u.retention.clone()).unwrap_or_default();
let preview_lines = user_record.map(|u| u.preview_lines).unwrap_or(2);
// Lazy retention sweep: at most one disk scan per /web/cases visit,
// reusing the user's retention policy from users.toml. Runs before
// the listing scan so any auto-close/auto-purge actions are
// reflected in the same response.
let retention = config
.users
.iter()
.find(|u| u.slug == user.slug)
.map(|u| u.retention.clone())
.unwrap_or_default();
crate::retention::sweep_user_retention(&user_root, &user.slug, &retention, &events_tx).await;
let show_closed = query.include_closed();
@@ -610,15 +614,9 @@ pub async fn handle_my_cases(
};
let groups = group_by_utc_date(cases, &closed_extra);
let is_admin = user.is_admin();
let preview_lines = config
.users
.iter()
.find(|u| u.slug == user.slug)
.map(|u| u.preview_lines)
.unwrap_or(2);
MyCasesTemplate {
csrf_token: user.csrf_token,
slug: user.slug,
display_name: user.display_name,
groups,
total,
is_admin,