PR #270 · pramaan-io/pramaan-functions · merged 2026-06-08
Delete a forum still in use, and the audit trail cracks open.
Story nine-eighty-eight
Matters and proceedings keep their foreign keys. You just deleted their home.
The fix — Count the references before you delete the row. Archive is free, delete is earned.
sequenceDiagram
autonumber
participant client as Client
participant service as Forum Service
participant helper as Lifecycle Helper
participant db as DB (matters + proceedings)
client->>service: DELETE /app/forums/{id}
service->>service: load forum row
service->>helper: check in-use references
helper->>db: count matters + proceedings
db->>helper: 10 references
helper->>service: in use — true
service-->>client: pramaan.forum.in_use
| Method | in → out | what it does |
|---|---|---|
_view | (forum, usage_count) → ForumView | |
_in_use_references | (forum_id, firm_id) → tuple[InUseReference, ...] | |
_usage_count | (session, forum_id, firm_id) → int |
src/domains/forum/service.py+62 −28Forum service that builds the in-use reference list, computes usage count, and rejects delete when references exist.
| new method | signature |
|---|---|
_view | (forum, usage_count) → ForumView |
_in_use_references | (forum_id, firm_id) → tuple[InUseReference, ...] |
_usage_count | (session, forum_id, firm_id) → int |
src/shared/lifecycle.py+42 −2Shared in-use reference helper that packages one table reference and runs the existence check used by forum delete.
| new class | signature |
|---|---|
InUseReference | (entity, predicates) |
has_in_use_references | (session, references) → bool |
Forum response DTO that adds usage count, in-use flag, and can-delete flag so clients see deletability up front.
usage_count : intis_in_use : boolcan_delete : bool