fix(projects): emit Create audit row on task creation #282
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-318-create-task-audit-row"
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?
create_task INSERTed the task row and committed without ever calling audit_write, so the task's change-history feed never showed the create event even though the viewer endpoint and the sibling update_task/update_project paths in the same file already write audit rows. The fix is additive: thread the AuditCtx extractor into the create_task handler (mirroring update_task) and, inside the existing transaction, snapshot the inserted row via to_jsonb and call audit_write with action=Create, resource_type="tasks", before=NULL, after=row snapshot, before commit. Wrapping the audit row in the same tx as the INSERT means a rollback drops both.
Adds two integration tests: one asserting the create writes an entity-scoped create audit row (no before snapshot, after captures the row, actor = creating user), and one that forces the in-tx audit write to FK-violate after the INSERT and asserts neither the task nor an audit row survives the rollback.
#PMS-318
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com