As a user I want to see the full edit history of a document so I can track what changed and who changed it #38
Reference in New Issue
Block a user
Delete Branch "%!s()"
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?
Background
Documents are edited collaboratively over time. There is currently no way to see what changed, when, or who made the change. A version history with a diff view makes edits transparent and allows mistakes to be spotted and corrected.
Depends on #35 (profile page) so that the editor's display name is available and meaningful.
Desired behaviour
Data model
New table
document_versions:editor_nameis denormalized at write time (first name + last name from #35, or username as fallback) so history stays readable even if the user is later deleted or renames themselves.snapshotis the full document as it looked after the save — the same shape as the existing document API response.Implementation notes
Backend
DocumentService.create()writes the first snapshot immediately — so "Version 1 — created by X" is always the baseline. Without this, the first diff would show all fields as "added" with no prior state.DocumentService.update()writes a snapshot row immediately after persisting the change — same transaction.GET /api/documents/{id}/versions— returns the version list (id, saved_at, editor_name, changed_fields summary) without full snapshotsGET /api/documents/{id}/versions/{versionId}— returns the full snapshot for one versionThe
changed_fieldssummary (a short list like["title", "transcription"]) is computed by diffing the new snapshot against the previous one at write time and stored in the row — avoids loading all snapshots just to render the version list.Version restore is out of scope for this issue but the data model fully supports it: a future
POST /api/documents/{id}/versions/{versionId}/restorewould re-save the snapshot as the current document state, which itself creates a new snapshot entry — keeping the full audit trail intact.Storage policy: Keep all versions indefinitely for now. If storage becomes a concern, a configurable retention policy (keep last N versions) can be added later without changing the schema.
Frontend
diffnpm package (diffWords()for text fields, simple comparison for scalars and relations)Testing
DocumentServiceTest— a snapshot row is written on create; a snapshot row is written on update; snapshot contains the correct field values;changed_fieldsreflects the actual change@WebMvcTest— versions endpoint returns the list; snapshot endpoint returns the correct JSONDependencies
editor_nameis only useful once users have a display nameUser Journey
User is on a document detail page. At the bottom they see a collapsible "History" section. They open it and see a list of entries — each shows who saved it and when, plus a brief note of which fields changed (e.g. "title, transcription"). They click an entry and a diff panel appears showing the title with changed words highlighted in green (added) and red with strikethrough (removed). Fields that didn't change are hidden. If they want to compare two specific versions — not necessarily adjacent — they pick both from dropdowns and the diff updates accordingly.
E2E Scenarios
marcel referenced this issue2026-03-20 19:26:30 +01:00