feat: implement formal decision registry
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from govoplan_core.core.institutional import CAPABILITY_DECISION_REGISTRY
|
||||
from govoplan_core.core.module_guards import drop_table_retirement_provider, persistent_table_uninstall_guard
|
||||
from govoplan_core.core.modules import CapabilityDocumentation, DocumentationLink, DocumentationTopic, MigrationSpec, ModuleContext, ModuleInterfaceProvider, ModuleManifest, PermissionDefinition, RoleTemplate
|
||||
from govoplan_core.core.provider_governance import declared_module_architecture
|
||||
from govoplan_core.db.base import Base
|
||||
from govoplan_decisions.backend.db import models as decision_models
|
||||
from govoplan_decisions.backend.service import SqlDecisionRegistry
|
||||
|
||||
|
||||
MODULE_ID = "decisions"
|
||||
MODULE_NAME = "Decisions"
|
||||
MODULE_VERSION = "0.1.14"
|
||||
READ_SCOPE = "decisions:decision:read"
|
||||
SENSITIVE_READ_SCOPE = "decisions:decision:read_sensitive"
|
||||
WRITE_SCOPE = "decisions:decision:write"
|
||||
ADMIN_SCOPE = "decisions:decision:admin"
|
||||
|
||||
|
||||
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="Decisions", level="tenant", module_id=module_id, resource=resource, action=action)
|
||||
|
||||
|
||||
def _router(_context: ModuleContext):
|
||||
from govoplan_decisions.backend.router import router
|
||||
|
||||
return router
|
||||
|
||||
|
||||
def _registry(_context: ModuleContext) -> SqlDecisionRegistry:
|
||||
return SqlDecisionRegistry()
|
||||
|
||||
|
||||
manifest = ModuleManifest(
|
||||
id=MODULE_ID,
|
||||
name=MODULE_NAME,
|
||||
version=MODULE_VERSION,
|
||||
optional_dependencies=("mandates", "approvals", "committee", "cases", "audit", "policy", "records", "files", "postbox", "mail"),
|
||||
provides_interfaces=(ModuleInterfaceProvider(name="decisions.formal_outcome", version="0.1.0"), ModuleInterfaceProvider(name="decisions.reconstruction", version="0.1.0")),
|
||||
permissions=(
|
||||
_permission(READ_SCOPE, "View Decision metadata", "View formal Decision metadata and evidence references."),
|
||||
_permission(SENSITIVE_READ_SCOPE, "View protected Decisions", "View protected reasoning, operative results, and conditions."),
|
||||
_permission(WRITE_SCOPE, "Record Decisions", "Record governed formal outcomes and lifecycle revisions."),
|
||||
_permission(ADMIN_SCOPE, "Administer Decisions", "Administer Decision access, lifecycle, and recovery."),
|
||||
),
|
||||
role_templates=(
|
||||
RoleTemplate(slug="decision_officer", name="Decision officer", description="Record and inspect formal Decisions.", permissions=(READ_SCOPE, SENSITIVE_READ_SCOPE, WRITE_SCOPE)),
|
||||
RoleTemplate(slug="decision_auditor", name="Decision auditor", description="Reconstruct protected formal outcomes.", permissions=(READ_SCOPE, SENSITIVE_READ_SCOPE)),
|
||||
),
|
||||
route_factory=_router,
|
||||
capability_factories={CAPABILITY_DECISION_REGISTRY: _registry},
|
||||
capability_documentation={CAPABILITY_DECISION_REGISTRY: CapabilityDocumentation(label="Formal Decision registry", summary="Records and resolves immutable, reconstructable formal outcomes.", 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(decision_models.FormalDecisionRevision, label="Decisions"),
|
||||
retirement_notes="Destructive retirement requires a database snapshot and removes formal Decision history.",
|
||||
),
|
||||
uninstall_guard_providers=(persistent_table_uninstall_guard(decision_models.FormalDecisionRevision, label="Decisions"),),
|
||||
documentation=(
|
||||
DocumentationTopic(
|
||||
id="decisions.formal-outcome",
|
||||
title="Formal institutional Decisions",
|
||||
summary="Reconstruct authority, evidence, reasoning, outcome, effects, and review history.",
|
||||
body="Decisions preserves immutable formal outcomes. Corrections and revocations create linked revisions; requested and observed effects remain distinct for reconciliation.",
|
||||
layer="configured",
|
||||
documentation_types=("admin", "user"),
|
||||
audience=("user", "operator", "module_admin", "auditor"),
|
||||
links=(DocumentationLink(label="Decisions domain and recovery", href="govoplan-decisions/docs/DECISIONS_DOMAIN.md", kind="repository"),),
|
||||
),
|
||||
),
|
||||
architecture=declared_module_architecture(
|
||||
layer="governance_accountability",
|
||||
kind="domain",
|
||||
maturity="vertical_slice",
|
||||
documentation_ref="docs/DECISIONS_DOMAIN.md",
|
||||
test_ref="tests/test_decisions.py",
|
||||
known_limits=("No dedicated Decision WebUI is included; consuming procedure modules present outcomes in context.",),
|
||||
supported_authority_modes=("native_authoritative",),
|
||||
owned_concepts=("formal decision", "decision correction", "decision effect observation"),
|
||||
non_owned_concepts=("approval gate", "committee deliberation", "effect execution", "record binary"),
|
||||
reference_packages=("product.service-to-decision",),
|
||||
migration_docs=("docs/DECISIONS_DOMAIN.md",),
|
||||
recovery_docs=("docs/DECISIONS_DOMAIN.md",),
|
||||
security_docs=("docs/DECISIONS_DOMAIN.md",),
|
||||
operations_docs=("docs/DECISIONS_DOMAIN.md",),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
def get_manifest() -> ModuleManifest:
|
||||
return manifest
|
||||
Reference in New Issue
Block a user