feat(audit-log): resolve user + entity names server-side so the SPA can display them #152
No reviewers
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
psa-systems/mokosh-server!152
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/audit-log-resolve-names"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The audit log table in mokosh-apps was the last surface in the UI showing raw UUIDs to the user (the 8-char "Entity ID" + "User" columns and the full UUIDs in the expanded detail row). Resolving them client-side would require either an N+1 of GET-by-id calls per page render or a pile of per-entity-type caches; doing the join server-side keeps the response shape flat and the SPA dumb.
Schema-touching is a single SQL change on the LIST query in
AuditService::list. The append/INSERT path is unchanged.AuditLogEntryResponsegains two new optional fields:user_name: from a LEFT JOIN againstusersonuser_id. Composed asNULLIF(TRIM(first_name || ' ' || last_name), '')so a JIT-created user whose names are still the synthetic email-derived placeholders (and whoselast_nameis empty) collapses to NULL instead of returning a half-formed " " string. The SPA renders "System" when null.entity_name: aCASE entity_type WHEN ... THEN (SELECT ... FROM ... WHERE id = al.entity_id)per known entity_type. Each subselect is a single PK lookup, so a 25-row page costs 25 trivial index hits. Covers every entity_type emitted by current audit_write callsites: companies, contacts (first_name || last_namewith the same NULLIF as users), sites, contracts, contract_items, rate_cards, invoices, tickets (formatted asT<ticket_number>), projects, assets, credential_vault, payment_gateway_configs, tax_rates, plus the syntheticauthentity_type (whose entity_id is itself a user_id, resolved against users the same wayuser_nameis). Unknown future entity_types fall through toELSE NULL; the SPA renders the short UUID in that case so the row still carries something the reader can correlate against.WHERE-clause condition strings now carry the
al.alias since the JOIN puts a secondid/user_id/etc. in scope, and the count query also aliasesaudit_log alto keep the sharedwhere_clausevalid against both queries without re-templating.AuditRowand theFrom<AuditRow> for AuditLogEntryResponsemapping pick the two new columns; the LIST handler signature is unchanged.Backwards-compat: the new fields are
Option<String>. An older SPA build hitting a newer server simply ignores them via serde's drop-unknown behaviour. A newer SPA build hitting an older server decodes the missing fields as None via#[serde(default)]on the client and falls back to the short-UUID rendering, so neither half of the rollout breaks the audit log page.Pairs with mokosh-apps
feat/audit-log-show-names.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.