Repository navigation
Todo
Labels
enhancementNew feature or request
Description
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, subjectrow_updatewith 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-trailsfor 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/2endpoint 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
Acceptance Criteria
- Create, update and delete of a row write an entry with user, time and the changed columns with old and new value.
GETon 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 filterschangeColsper 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 inappinfo/info.xmlis 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
- 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. - 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.
- 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
- The issue creates audit entries that belong to one row.
- Today: rows have an integer id; row uuids are UUIDs for rows #3093 (PR feat(rows): add persistent UUIDv7 identifiers to rows #3229). Tables writes Activity events for its own objects. Links between rows and other objects do not exist yet.
- What this issue must do: key entries by row id. Should the trail ever travel in an export, the dedicated export endpoint maps ids to uuids there (as agreed on UUIDs for rows #3093). Keep the entry shape open for other kinds of change: once Link a row to objects in other apps: mails, Deck cards, files, rows of other tables #3468 lands, adding or removing a link is a change to the row that can show in the same trail (its concept writes link events on the Tables side). What happens to a row's entries when the row is deleted is question 2.
Relevant files:
Related issues
- UUIDs for rows #3093
- links between rows and other apps (Link a row to objects in other apps: mails, Deck cards, files, rows of other tables #3468)
Drafted with AI assistance from the project plan; @rjzondervan reviews it. Part of #3419.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity