Skip to content

Audit trail of row changes with a read endpoint #3439

Todo

Description

@rubenvdlinde

Is your feature request related to a problem? Please describe.

  • Applications for case work need to show who changed what. The events exist; nothing keeps them.
Why this is needed
  • Case workers and their supervisors must show who changed which field of a case and when. Tables sends row changes to the Activity app (ActivityManager, subject row_update with the changed columns and their old and new values), and writes a server audit log line when a row is deleted (WhenRowDeletedAuditLogListener). Activity is optional, keeps one copy per recipient and expires, and the Tables API cannot read it, so an application has no trail per row to show.
  • buildiq parity: buildiq reads OpenRegister's /audit-trails for the detail page and the audit-trail widget; Tables has the activity stream only (sections 2, 3 and 7 of the feature comparison).
  • The detail page shows it (Show the audit trail and the lock on the detail page #3448, and the activity tab of Sidebar of the detail page with files, relations and activity #3436), and acceptance path 5 tests it. Audit is fifth in the deferral order, so it leaves the freeze before the settings page type if sprint 4 runs late.

Describe the solution you'd like

  • Store who changed which cells of a row and when, from the row events Tables already dispatches, and add an api/2 endpoint that returns the trail of one row.
Diagram
sequenceDiagram
    actor U as User
    participant API as Rows API v2
    participant RS as RowService
    participant EV as Event dispatcher
    participant AL as New audit listener
    participant DB as New audit table
    U->>API: update a row
    API->>RS: update cells
    RS->>EV: RowUpdatedEvent with the previous data
    EV->>AL: handle
    AL->>DB: user, time, changed columns, old and new value
    U->>API: GET the row's audit route (new)
    API->>API: may the user read the row?
    API->>DB: entries of the row, newest first, paged
    API-->>U: one page of entries
Loading
Acceptance Criteria
  • Create, update and delete of a row write an entry with user, time and the changed columns with old and new value.
  • GET on the row's audit route returns its entries, newest first, paged.
  • Only users who may read the row may read its trail.
  • Entries of a deleted table are removed with it.
  • Unit tests, and a note on the storage growth on a busy table.
  • The audit route declares #[RequirePermission] (read) using a fixed node type, and the service checks read on the row before it answers. A reader who sees the row through a view gets only the columns of that view, the way Activity filters changeCols per view today.
  • Entries are stored in a new table: row id, table id, user and time in their own columns (the read filters and sorts on them), the changed values as JSON in a text column, never the database JSON column type (as agreed on Grid pages in applications (frontend) #3099).
  • Migration: a new table with an index on (row id, time); no empty-string defaults, since Oracle stores '' as NULL (as raised on Technical name for tables and applications, CRUD routes by application and table #3094); the version in appinfo/info.xml is bumped with the migration (as raised on feat(rows): add persistent UUIDv7 identifiers to rows #3229).
  • Every row write now also inserts an entry, so the write timings (single create and update, CSV import of 10k rows into the 100k table, before and after) go into the benchmark of Benchmark the rows API on a table of 100k rows #3424.
  • Deleting a table deletes its entries in the same transaction. A repair step that runs once after the upgrade removes leftovers, not a recurring cleanup job (as agreed on Grid pages in applications (data model and API) #3100).
Out of scope
  • Showing the trail on the detail page: Show the audit trail and the lock on the detail page #3448.
  • Versions of rows with restore and diff: deferred past 15 January in the plan.
  • Changes to tables, columns and views: only rows are in this issue.
  • Proposed slicing, one PR each in landing order: the table and the listener, then the read route.

Describe alternatives you've considered

Questions for maintainers

  1. A new audit table written from the row events, or reading the trail from the Activity app's events for tables_row? We would go with a new table, because Activity is optional, keeps one copy per recipient and expires, so it cannot be a trail.
  2. When a row is deleted: keep its entries (the delete is the last one) until the table is deleted, or delete them with the row? We would go with keeping them, because who deleted a case is what a supervisor asks most.
  3. A CSV import of many rows: one entry per created row with its values, or one entry per row without values? We would go with one entry per row without values, to keep the cost of an import low, and measure both in Benchmark the rows API on a table of 100k rows #3424.

Additional context

Linking to other objects
Relevant files:
Related issues

Drafted with AI assistance from the project plan; @rjzondervan reviews it. Part of #3419.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions