[Bug-1076] Fix archive-aware management lists

Story 1076Epic None21 files · +554/−35

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

Why this matters

Pickers and management lists cannot share one filter.

Live-only pickers, opt-in archived lists — both true, but only with an explicit boundary.

One filter, two jobs — picker ends up serving retired items.

The fix — Management lists show everything on demand; pickers stay live-only by default.

How it flows

sequenceDiagram
  autonumber
  participant client as Client
  participant router as Router
  participant service as Service
  participant repo as Repository / SQL
  client->>router: GET /matter-types?includeArchived=true
  router->>router: parse param (default false)
  router->>service: include_archived=True
  service->>repo: include_archived=True
  repo->>repo: archive_status_clause(...) → SQL
  repo->>client: rows (active + archived)

src/shared/lifecycle.py + domain repos

Methodin → outwhat it does
archive_status_clause(column, include_archived, active_value) → Anybuilds the SQL filter for active/archived rows from one flag
visibility_availability_clause(column, include_archived, live_value, deleted_value) → Anybuilds the SQL filter for live/deleted semantic from one flag

What changed, file by file

Shared module that builds SQL clauses for active/archived and live/deleted filters, so every list reads the same archive rule. Added to centralize the doctrine and avoid per-list drift.

new methodsignature
archive_status_clause(column, include_archived, active_value) → Any
visibility_availability_clause(column, include_archived, live_value, deleted_value) → Any

Matter router that now accepts the includeArchived query param and forwards it to the service. Wires the boundary at the HTTP edge.

New fields: include_archived : Annotated[

Matter-type router exposing includeArchived for the management list while keeping picker consumers live-only. Splits the two views cleanly.

New fields: include_archived : Annotated[

Matter-type repository that builds the visible clause from include_archived and returns the list. Encapsulates the SQL toggle in one place.

new methodsignature
_visible_clause(include_archived) → Any
list_matter_types(db, include_archived) → list[MatterTypeRow]

Proceeding service that threads include_archived through kind and stage listings. Applies the same doctrine to proceedings.

New fields: include_archived : bool

Forum router that adds the includeArchived query param for admin views. Default false keeps live-only behavior for consumers.

New fields: include_archived : Annotated[

Matter-type service that passes include_archived to the repository and assembles the response. Bridges router and repo.

new methodsignature
list_matter_types(db, include_archived) → MatterTypeListResponse

Template service for matter templates, threaded with include_archived so the template list honors the doctrine. Picker stays live.

new methodsignature
list_matter_templates(session, include_archived) → MatterTemplateListResponse

Matter-template router exposing includeArchived for the management list. Default false preserves live-only pickers.

New fields: include_archived : Annotated[

Forum service that receives include_archived and forwards it down. Keeps forum list and picker behavior aligned with the doctrine.

New fields: include_archived : bool

Matter-type DTO module that adds a MatterTypeStatus class and a status field on the row. Lets the API surface live vs archived cleanly.

new classsignature
MatterTypeStatus(class)
New fields: status : MatterTypeStatus

Matter redesign service threaded with include_archived for related matter link listings. Same opt-in pattern, same doctrine.

New fields: include_archived : bool

Files changed (21)

File±
AGENTS.md+6
docs/agent-rules/hard-rules.md+6
openapi/app-api.json ★+91
src/app_api/router_matter_templates.py+10 −2
src/app_api/router_matter_types.py+18 −2
src/app_api/router_matters.py ★+20 −1
src/domains/forum/router.py+12 −2
src/domains/forum/service.py+8 −1
src/domains/matter/redesign_service.py+7 −1
src/domains/matter/service.py+6 −2
src/domains/matter_type/dtos/__init__.py+2
src/domains/matter_type/dtos/matter_type.py+8
src/domains/matter_type/repository.py+13 −5
src/domains/matter_type/service.py+12 −2
src/domains/matter_type/template_service.py+12 −2
src/domains/proceeding/service.py+13 −2
src/shared/lifecycle.py ★+34
tests/integration/test_app_forums.py+53 −3
tests/integration/test_app_matter_redesign.py+90 −3
tests/integration/test_app_matter_types.py+111 −5
tests/integration/test_app_matters.py+22 −2