feat(audit): surface field-level before/after content in change history (PMS-204) #156

Merged
longjacksonle merged 1 commit from feat/pms-204-history-content into main 2026-06-11 04:28:20 +02:00

What

Backend half of PMS-204: the change-history feed now carries the actual before/after content of each edit, not just the field names.

Changes

  • EntityHistoryEntry (the GET /api/v1/audit-log/entity/{type}/{id} response) gains a changes array of { field, old, new }, computed from the audit_log before/after JSON snapshots by a new shared field_changes helper (noise columns excluded, sorted for a stable order). changed_fields is now derived from it, so the existing summary line is unchanged.
  • Assets use the separate asset_audit_log table, which previously stored no diff for updates. update_asset now snapshots the row before and after with to_jsonb and persists the same {field, old, new} diff into the row's changes column, so the asset detail page can show content too.

Tests

  • ticket_history_records_description_edit: now also asserts the entry's changes carries the description old ("Paper stuck in tray 2.") and new ("Paper stuck in tray 2 and toner low.").
  • asset_crud_and_filtering: asserts the status edit's audit row carries {field: status, old: active, new: in_repair}.

Pairs with a mokosh-apps PR that renders the before to after content on the ticket, project/task, and asset detail pages.

🤖 Generated with Claude Code

## What Backend half of PMS-204: the change-history feed now carries the actual before/after content of each edit, not just the field names. ## Changes - `EntityHistoryEntry` (the `GET /api/v1/audit-log/entity/{type}/{id}` response) gains a `changes` array of `{ field, old, new }`, computed from the `audit_log` before/after JSON snapshots by a new shared `field_changes` helper (noise columns excluded, sorted for a stable order). `changed_fields` is now derived from it, so the existing summary line is unchanged. - Assets use the separate `asset_audit_log` table, which previously stored no diff for updates. `update_asset` now snapshots the row before and after with `to_jsonb` and persists the same `{field, old, new}` diff into the row's `changes` column, so the asset detail page can show content too. ## Tests - `ticket_history_records_description_edit`: now also asserts the entry's `changes` carries the description `old` ("Paper stuck in tray 2.") and `new` ("Paper stuck in tray 2 and toner low."). - `asset_crud_and_filtering`: asserts the status edit's audit row carries `{field: status, old: active, new: in_repair}`. Pairs with a mokosh-apps PR that renders the before to after content on the ticket, project/task, and asset detail pages. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(audit): surface field-level before/after content in change history (PMS-204)
All checks were successful
E2E (staging) / Playwright against staging (pull_request) Successful in 1m7s
Check / fmt + clippy + compile + tests (pull_request) Successful in 3m25s
Create release / Create release from merged PR (pull_request) Has been skipped
Build OCI container / Build and push mokosh-api image (push) Successful in 7m35s
60f0e4f805
The per-record history showed who/when and the changed field names but not the actual content of the edit. Add a `changes` array of {field, old, new} to EntityHistoryEntry, computed from the audit_log before/after snapshots by a shared `field_changes` helper (noise columns still excluded, sorted for stable order). `changed_fields` is now derived from it. For assets (which use the separate asset_audit_log table), update_asset now snapshots the row before and after with to_jsonb and persists the same diff into the row's `changes` column, so the asset detail page can show content too. Tests assert tickets carry the description old/new and assets carry the status old/new.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
longjacksonle deleted branch feat/pms-204-history-content 2026-06-11 04:28:20 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/mokosh-server!156
No description provided.