[Bug-1077] Delete only unused forum catalog items

Story 1077Epic None7 files · +167/−31

PR #270 · pramaan-io/pramaan-functions · merged 2026-06-08

Why this matters

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.

How it flows

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

service.py · +62 — new methods

Methodin → outwhat it does
_view(forum, usage_count) → ForumView
_in_use_references(forum_id, firm_id) → tuple[InUseReference, ...]
_usage_count(session, forum_id, firm_id) → int

What changed, file by file

Forum service that builds the in-use reference list, computes usage count, and rejects delete when references exist.

new methodsignature
_view(forum, usage_count) → ForumView
_in_use_references(forum_id, firm_id) → tuple[InUseReference, ...]
_usage_count(session, forum_id, firm_id) → int

Shared in-use reference helper that packages one table reference and runs the existence check used by forum delete.

new classsignature
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.

New fields: usage_count : intis_in_use : boolcan_delete : bool

Files changed (7)

File±
AGENTS.md+6
openapi/app-api.json ★+19
src/domains/forum/dtos/forum.py+10
src/domains/forum/service.py ★+62 −28
src/shared/lifecycle.py ★+42 −2
tests/contract/test_app_forums_openapi.py+6
tests/integration/test_app_forums.py+22 −1