464 lines
17 KiB
Python
464 lines
17 KiB
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from govoplan_core.core.module_guards import (
|
|
drop_table_retirement_provider,
|
|
persistent_table_uninstall_guard,
|
|
)
|
|
from govoplan_core.core.institutional import CAPABILITY_PARTY_RESOLVER
|
|
from govoplan_core.core.modules import (
|
|
CapabilityDocumentation,
|
|
DocumentationLink,
|
|
DocumentationTopic,
|
|
FrontendModule,
|
|
FrontendRoute,
|
|
MigrationSpec,
|
|
ModuleContext,
|
|
ModuleInterfaceProvider,
|
|
ModuleInterfaceRequirement,
|
|
ModuleManifest,
|
|
NavItem,
|
|
PermissionDefinition,
|
|
RoleTemplate,
|
|
)
|
|
from govoplan_core.core.views import ViewSurface
|
|
from govoplan_core.core.provider_governance import (
|
|
ModuleArchitectureDeclaration,
|
|
ModuleArchitectureDocumentation,
|
|
ModuleMaturityEvidence,
|
|
)
|
|
from govoplan_cases.backend.party_context import (
|
|
CAPABILITY_CASES_PARTY_CONTEXT,
|
|
CasePartyContext,
|
|
)
|
|
from govoplan_cases.backend.acl import CaseAclProvider
|
|
from govoplan_cases.backend.db import models as case_models
|
|
from govoplan_cases.backend.service_intake import (
|
|
CAPABILITY_CASES_SERVICE_INTAKE,
|
|
CaseServiceIntake,
|
|
)
|
|
from govoplan_cases.backend.service_launcher import (
|
|
CAPABILITY_CASES_SERVICE_LAUNCHER,
|
|
CaseServiceLauncher,
|
|
)
|
|
from govoplan_cases.backend.service import (
|
|
CAPABILITY_CASES_REGISTRY,
|
|
SqlCaseRegistry,
|
|
)
|
|
from govoplan_core.db.base import Base
|
|
|
|
|
|
MODULE_ID = "cases"
|
|
MODULE_VERSION = "0.1.15"
|
|
READ_SCOPE = "cases:case:read"
|
|
CREATE_SCOPE = "cases:case:create"
|
|
UPDATE_SCOPE = "cases:case:update"
|
|
ASSIGN_SCOPE = "cases:case:assign"
|
|
CLOSE_SCOPE = "cases:case:close"
|
|
SHARE_SCOPE = "cases:case:share"
|
|
ADMIN_SCOPE = "cases:case:admin"
|
|
|
|
|
|
def _party_context(context: ModuleContext) -> CasePartyContext:
|
|
return CasePartyContext(context.registry)
|
|
|
|
|
|
def _service_intake(context: ModuleContext) -> CaseServiceIntake:
|
|
del context
|
|
return CaseServiceIntake()
|
|
|
|
|
|
def _case_registry(context: ModuleContext) -> SqlCaseRegistry:
|
|
del context
|
|
return SqlCaseRegistry()
|
|
|
|
|
|
def _service_launcher(context: ModuleContext) -> CaseServiceLauncher:
|
|
del context
|
|
return CaseServiceLauncher()
|
|
|
|
|
|
def _router(context: ModuleContext):
|
|
del context
|
|
from govoplan_cases.backend.router import router
|
|
|
|
return router
|
|
|
|
|
|
def _permission(scope: str, label: str, description: str) -> PermissionDefinition:
|
|
module_id, resource, action = scope.split(":", 2)
|
|
return PermissionDefinition(
|
|
scope=scope,
|
|
label=label,
|
|
description=description,
|
|
category="Cases",
|
|
level="tenant",
|
|
module_id=module_id,
|
|
resource=resource,
|
|
action=action,
|
|
)
|
|
|
|
|
|
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
|
|
total = (
|
|
session.query(case_models.CaseIdentity)
|
|
.filter(case_models.CaseIdentity.tenant_id == tenant_id)
|
|
.count()
|
|
)
|
|
open_cases = (
|
|
session.query(case_models.CaseRecordRevision)
|
|
.filter(
|
|
case_models.CaseRecordRevision.tenant_id == tenant_id,
|
|
case_models.CaseRecordRevision.superseded_at.is_(None),
|
|
case_models.CaseRecordRevision.closed_at.is_(None),
|
|
)
|
|
.count()
|
|
)
|
|
return {"cases": total, "open_cases": open_cases}
|
|
|
|
|
|
manifest = ModuleManifest(
|
|
id=MODULE_ID,
|
|
name="Cases",
|
|
version=MODULE_VERSION,
|
|
optional_dependencies=(
|
|
"access",
|
|
"addresses",
|
|
"services",
|
|
"parties",
|
|
"mandates",
|
|
"decisions",
|
|
"forms_runtime",
|
|
"workflow_engine",
|
|
),
|
|
optional_capabilities=(CAPABILITY_PARTY_RESOLVER,),
|
|
permissions=(
|
|
_permission(READ_SCOPE, "View cases", "Read tenant cases and their governed history."),
|
|
_permission(CREATE_SCOPE, "Create cases", "Open a case from a configured case type or service intake."),
|
|
_permission(UPDATE_SCOPE, "Update cases", "Create a guarded immutable case revision."),
|
|
_permission(ASSIGN_SCOPE, "Assign cases", "Change stable function, assignment, or work-item references on a case."),
|
|
_permission(CLOSE_SCOPE, "Close cases", "Move a case to a configured terminal status."),
|
|
_permission(SHARE_SCOPE, "Share cases", "Restrict a case and grant object-level access to selected principals."),
|
|
_permission(ADMIN_SCOPE, "Administer cases", "Configure tenant case types and statuses."),
|
|
),
|
|
role_templates=(
|
|
RoleTemplate(
|
|
slug="case_manager",
|
|
name="Case manager",
|
|
description="Create, assign, update, and close tenant cases.",
|
|
permissions=(READ_SCOPE, CREATE_SCOPE, UPDATE_SCOPE, ASSIGN_SCOPE, CLOSE_SCOPE, SHARE_SCOPE),
|
|
),
|
|
RoleTemplate(
|
|
slug="case_reader",
|
|
name="Case reader",
|
|
description="Read cases and their governed history.",
|
|
permissions=(READ_SCOPE,),
|
|
),
|
|
RoleTemplate(
|
|
slug="case_administrator",
|
|
name="Case administrator",
|
|
description="Configure case types and statuses and manage cases.",
|
|
permissions=(READ_SCOPE, CREATE_SCOPE, UPDATE_SCOPE, ASSIGN_SCOPE, CLOSE_SCOPE, SHARE_SCOPE, ADMIN_SCOPE),
|
|
),
|
|
),
|
|
route_factory=_router,
|
|
nav_items=(
|
|
NavItem(
|
|
path="/cases",
|
|
label="Cases",
|
|
icon="briefcase-business",
|
|
required_any=(READ_SCOPE,),
|
|
order=35,
|
|
),
|
|
),
|
|
frontend=FrontendModule(
|
|
module_id=MODULE_ID,
|
|
package_name="@govoplan/cases-webui",
|
|
routes=(
|
|
FrontendRoute(
|
|
path="/cases",
|
|
component="CasesPage",
|
|
required_any=(READ_SCOPE,),
|
|
order=35,
|
|
),
|
|
FrontendRoute(
|
|
path="/cases/:caseId",
|
|
component="CaseDetailPage",
|
|
required_any=(READ_SCOPE,),
|
|
order=36,
|
|
),
|
|
),
|
|
nav_items=(
|
|
NavItem(
|
|
path="/cases",
|
|
label="Cases",
|
|
icon="briefcase-business",
|
|
required_any=(READ_SCOPE,),
|
|
order=35,
|
|
),
|
|
),
|
|
view_surfaces=(
|
|
ViewSurface(
|
|
id="cases.navigation",
|
|
module_id=MODULE_ID,
|
|
kind="navigation",
|
|
label="Cases navigation",
|
|
order=10,
|
|
),
|
|
ViewSurface(
|
|
id="cases.list",
|
|
module_id=MODULE_ID,
|
|
kind="route",
|
|
label="Case list",
|
|
order=20,
|
|
),
|
|
ViewSurface(
|
|
id="cases.list.filters",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Case search and filters",
|
|
parent_id="cases.list",
|
|
order=10,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail",
|
|
module_id=MODULE_ID,
|
|
kind="route",
|
|
label="Case details",
|
|
order=30,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.summary",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Case summary",
|
|
parent_id="cases.detail",
|
|
order=10,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.editor",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Case lifecycle editor",
|
|
parent_id="cases.detail",
|
|
order=20,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.references",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Institutional references",
|
|
parent_id="cases.detail",
|
|
order=30,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.timeline",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Case timeline",
|
|
parent_id="cases.detail",
|
|
order=40,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.history",
|
|
module_id=MODULE_ID,
|
|
kind="section",
|
|
label="Immutable case history",
|
|
parent_id="cases.detail",
|
|
order=50,
|
|
),
|
|
ViewSurface(
|
|
id="cases.detail.access",
|
|
module_id=MODULE_ID,
|
|
kind="action",
|
|
label="Case access",
|
|
parent_id="cases.detail",
|
|
order=60,
|
|
),
|
|
),
|
|
),
|
|
provides_interfaces=(
|
|
ModuleInterfaceProvider(name="cases.service_intake", version="0.1.0"),
|
|
ModuleInterfaceProvider(name="cases.party_context", version="0.1.0"),
|
|
ModuleInterfaceProvider(name="cases.registry", version="0.1.0"),
|
|
ModuleInterfaceProvider(name="cases.service_launcher", version="0.1.0"),
|
|
),
|
|
requires_interfaces=(
|
|
ModuleInterfaceRequirement(name="services.definition", version_min="0.1.0", version_max_exclusive="0.2.0", optional=True),
|
|
ModuleInterfaceRequirement(name="parties.procedure", version_min="0.1.0", version_max_exclusive="0.2.0", optional=True),
|
|
ModuleInterfaceRequirement(name="parties.representation", version_min="0.1.0", version_max_exclusive="0.2.0", optional=True),
|
|
),
|
|
capability_factories={
|
|
CAPABILITY_CASES_SERVICE_INTAKE: _service_intake,
|
|
CAPABILITY_CASES_PARTY_CONTEXT: _party_context,
|
|
CAPABILITY_CASES_REGISTRY: _case_registry,
|
|
CAPABILITY_CASES_SERVICE_LAUNCHER: _service_launcher,
|
|
},
|
|
capability_documentation={
|
|
CAPABILITY_CASES_SERVICE_INTAKE: CapabilityDocumentation(
|
|
label="Case service intake",
|
|
summary="Preserves a governed Service version in a case intake plan.",
|
|
contract_version="0.1.0",
|
|
),
|
|
CAPABILITY_CASES_PARTY_CONTEXT: CapabilityDocumentation(
|
|
label="Case party context",
|
|
summary="Resolves provider-owned procedure parties or a bounded local compatibility projection.",
|
|
contract_version="0.1.0",
|
|
),
|
|
CAPABILITY_CASES_REGISTRY: CapabilityDocumentation(
|
|
label="Case registry",
|
|
summary="Persists tenant-scoped case identities, immutable revisions, and lifecycle events.",
|
|
contract_version="0.1.0",
|
|
),
|
|
CAPABILITY_CASES_SERVICE_LAUNCHER: CapabilityDocumentation(
|
|
label="Case service launcher",
|
|
summary="Starts a replay-safe case from an exact available Service revision.",
|
|
contract_version="0.1.0",
|
|
),
|
|
},
|
|
migration_spec=MigrationSpec(
|
|
module_id=MODULE_ID,
|
|
metadata=Base.metadata,
|
|
script_location=str(Path(__file__).with_name("migrations") / "versions"),
|
|
retirement_supported=True,
|
|
retirement_provider=drop_table_retirement_provider(
|
|
case_models.CaseTimelineEntry,
|
|
case_models.CaseAccessGrant,
|
|
case_models.CaseRecordRevision,
|
|
case_models.CaseIdentity,
|
|
case_models.CaseTypeDefinition,
|
|
case_models.CaseStatusDefinition,
|
|
label="Cases",
|
|
),
|
|
retirement_notes="Destructive retirement requires a database snapshot and removes case identities, immutable revisions, catalogs, and timeline evidence.",
|
|
),
|
|
uninstall_guard_providers=(
|
|
persistent_table_uninstall_guard(
|
|
case_models.CaseIdentity,
|
|
case_models.CaseRecordRevision,
|
|
case_models.CaseTimelineEntry,
|
|
case_models.CaseAccessGrant,
|
|
case_models.CaseTypeDefinition,
|
|
case_models.CaseStatusDefinition,
|
|
label="Cases",
|
|
),
|
|
),
|
|
resource_acl_providers=(CaseAclProvider(),),
|
|
tenant_summary_providers=(_tenant_summary,),
|
|
documentation=(
|
|
DocumentationTopic(
|
|
id="cases.institutional-context",
|
|
title="Case institutional context",
|
|
summary="Cases retain service and party references without taking ownership of institutional definitions or subject masters.",
|
|
body=(
|
|
"Case types and statuses are tenant configuration. Every create or update writes "
|
|
"an immutable OCC-guarded revision and a replay-safe timeline event. Service "
|
|
"intake retains the exact Service, Mandate, jurisdiction, legal basis, form, "
|
|
"workflow, and result bindings. Procedure parties come from an optional provider "
|
|
"or a limited Cases-only compatibility projection. Assignment, evidence, Decision, "
|
|
"and record links remain stable references owned by their source modules."
|
|
),
|
|
layer="available",
|
|
documentation_types=("admin", "user"),
|
|
audience=("user", "operator", "module_admin"),
|
|
links=(
|
|
DocumentationLink(
|
|
label="Cases concept",
|
|
href="govoplan-cases/docs/CONCEPT.md",
|
|
kind="repository",
|
|
),
|
|
),
|
|
metadata={
|
|
"help_contexts": [
|
|
"cases.list",
|
|
"cases.detail",
|
|
"cases.state.read-only",
|
|
"cases.state.restricted",
|
|
],
|
|
},
|
|
),
|
|
DocumentationTopic(
|
|
id="cases.reference.lifecycle-access-and-evidence",
|
|
title="Case lifecycle, access, and evidence reference",
|
|
summary="Explains revision, status, access, and reference fields together with their durable consequences.",
|
|
body=(
|
|
"Title and status changes append an immutable case revision guarded by the "
|
|
"expected revision and a stable idempotency key. Every accepted change also "
|
|
"appends a timeline entry with actor, time, and change reason; a terminal "
|
|
"status additionally requires the case-close permission. Case visibility is "
|
|
"tenant-wide or restricted. Restricted cases remain visible only through "
|
|
"administrative authority, assignment or unit context, creator authority, or "
|
|
"an explicit account/group grant. Access changes append another immutable "
|
|
"revision and require confirmation. Service, party, assignment, Decision, and "
|
|
"record references identify provider-owned objects; Cases preserves their "
|
|
"stable identifiers and versions without copying or silently changing them."
|
|
),
|
|
layer="available",
|
|
documentation_types=("admin", "user"),
|
|
audience=("user", "operator", "module_admin"),
|
|
links=(
|
|
DocumentationLink(
|
|
label="Cases interface pattern migration",
|
|
href="govoplan-cases/docs/INTERFACE_PATTERN_MIGRATION.md",
|
|
kind="repository",
|
|
),
|
|
),
|
|
metadata={
|
|
"help_contexts": [
|
|
"cases.field.title",
|
|
"cases.field.status",
|
|
"cases.field.change-reason",
|
|
"cases.field.visibility",
|
|
"cases.field.access-grant",
|
|
"cases.state.close-unavailable",
|
|
],
|
|
"consequence_classes": {
|
|
"update_case": "append an OCC-guarded immutable revision and timeline event",
|
|
"close_case": "append a terminal revision after close-scope authorization",
|
|
"change_access": "append a confirmed visibility/grant revision and timeline event",
|
|
},
|
|
},
|
|
),
|
|
),
|
|
architecture=ModuleArchitectureDeclaration(
|
|
layer="human_work_procedure",
|
|
kind="domain",
|
|
maturity="vertical_slice",
|
|
evidence=(
|
|
ModuleMaturityEvidence(
|
|
kind="test",
|
|
reference="tests/test_institutional_consumers.py",
|
|
summary="Proves versioned service intake and optional procedure-party resolution.",
|
|
),
|
|
ModuleMaturityEvidence(
|
|
kind="documentation",
|
|
reference="docs/CONCEPT.md",
|
|
summary="Defines Cases ownership and optional institutional providers.",
|
|
),
|
|
),
|
|
known_limits=(
|
|
"The first Cases workspace covers list, detail, status/title revision, history, and timeline; richer procedure-specific panels remain module contributions.",
|
|
"The compatibility party path deliberately excludes representation lifecycle ownership.",
|
|
),
|
|
owned_concepts=("case identity", "case lifecycle", "case-local links"),
|
|
non_owned_concepts=(
|
|
"institutional service definition",
|
|
"party subject master",
|
|
"representation power lifecycle",
|
|
"formal decision lifecycle",
|
|
),
|
|
reference_packages=("product.service-to-decision",),
|
|
documentation=ModuleArchitectureDocumentation(
|
|
migration=("docs/CONCEPT.md",),
|
|
recovery=("docs/CONCEPT.md",),
|
|
security=("docs/CONCEPT.md",),
|
|
operations=("docs/CONCEPT.md",),
|
|
),
|
|
),
|
|
)
|
|
|
|
|
|
def get_manifest() -> ModuleManifest:
|
|
return manifest
|