feat(audit): emit Create audit row on mileage entry creation #284

Merged
nrupard merged 1 commit from feat/pms-315-mileage-create-audit into main 2026-06-16 21:35:06 +02:00
Owner

What

Adds the Create audit row to create_mileage_entry, the one create path the PMS-318 sweep could not cover because mileage_tracking (PMS-315, PR #277) merged to main only after the sweep branch was cut.

create_mileage_entry now takes the AuditCtx (threaded from its route handler) and, inside the existing transaction, snapshots the inserted row via to_jsonb and calls audit_write(action=Create, "mileage_entries", before=NULL, after=row) before commit. A rollback drops both the entry and its audit row; the change-history viewer surfaces the create event with no client change.

Tests

  • Service-level tests that call create_mileage_entry directly now pass an AuditCtx.
  • New create_mileage_entry_writes_create_audit_row: asserts the create audit row is entity-scoped, has no before snapshot, captures the row in after, and records the ctx user as actor.

Verification

cargo fmt --all --check, cargo clippy --all-targets -- -D warnings, cargo check --all-targets, cargo test --lib (168 passed) all green via the local toolchain. The Postgres-backed integration tests run in CI.

Note

The broad sweep across the other 12 modules is in a separate PR (PMS-318). This PR is the mileage tail of the same effort.

#PMS-318

## What Adds the Create audit row to `create_mileage_entry`, the one create path the PMS-318 sweep could not cover because `mileage_tracking` (PMS-315, PR #277) merged to main only after the sweep branch was cut. `create_mileage_entry` now takes the `AuditCtx` (threaded from its route handler) and, inside the existing transaction, snapshots the inserted row via `to_jsonb` and calls `audit_write(action=Create, "mileage_entries", before=NULL, after=row)` before commit. A rollback drops both the entry and its audit row; the change-history viewer surfaces the create event with no client change. ## Tests - Service-level tests that call `create_mileage_entry` directly now pass an `AuditCtx`. - New `create_mileage_entry_writes_create_audit_row`: asserts the create audit row is entity-scoped, has no `before` snapshot, captures the row in `after`, and records the ctx user as actor. ## Verification `cargo fmt --all --check`, `cargo clippy --all-targets -- -D warnings`, `cargo check --all-targets`, `cargo test --lib` (168 passed) all green via the local toolchain. The Postgres-backed integration tests run in CI. ## Note The broad sweep across the other 12 modules is in a separate PR (PMS-318). This PR is the mileage tail of the same effort. #PMS-318
feat(audit): emit Create audit row on mileage entry creation
All checks were successful
Create release / Create release from merged PR (pull_request) Has been skipped
E2E / Playwright against staging (pull_request) Successful in 1m11s
Check / fmt + clippy + compile + unit/doc tests (pull_request) Successful in 3m15s
Integration / integration tests (pull_request) Successful in 7m18s
5f0f3e1905
Completes the PMS-318 create-path audit sweep for mileage_tracking, which landed on main only after the sweep branch was cut (PMS-315, PR #277). create_mileage_entry now takes the AuditCtx (threaded from its route handler) and, inside the existing transaction, snapshots the inserted row via to_jsonb and calls audit_write(action=Create, "mileage_entries", before=NULL, after=row) before commit, so the entry's change-history feed shows the create event and a rollback drops both. Service-level tests that call create_mileage_entry directly now pass an AuditCtx, and a new test asserts the create audit row lands entity-scoped with no before snapshot, the row in after, and the ctx user as actor.

#PMS-318
nrupard deleted branch feat/pms-315-mileage-create-audit 2026-06-16 21:35:07 +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!284
No description provided.