feat: implement definition-aware forms runtime

This commit is contained in:
2026-08-01 17:48:35 +02:00
parent 396d6b0c90
commit 9dc49fe27b
25 changed files with 4180 additions and 79 deletions
+271 -43
View File
@@ -1,20 +1,59 @@
from __future__ import annotations
from govoplan_core.core.access import CAPABILITY_AUTH_PERMISSION_EVALUATOR, CAPABILITY_AUTH_PRINCIPAL_RESOLVER
from govoplan_core.core.modules import DocumentationLink, DocumentationTopic, ModuleManifest, PermissionDefinition, RoleTemplate
from pathlib import Path
from govoplan_core.core.access import (
CAPABILITY_AUTH_PERMISSION_EVALUATOR,
CAPABILITY_AUTH_PRINCIPAL_RESOLVER,
)
from govoplan_core.core.institutional import CAPABILITY_FORM_DEFINITIONS
from govoplan_core.core.module_guards import (
drop_table_retirement_provider,
persistent_table_uninstall_guard,
)
from govoplan_core.core.modules import (
CapabilityDocumentation,
DocumentationLink,
DocumentationTopic,
FrontendModule,
FrontendRoute,
MigrationSpec,
ModuleContext,
ModuleInterfaceProvider,
ModuleInterfaceRequirement,
ModuleManifest,
NavItem,
PermissionDefinition,
RoleTemplate,
)
from govoplan_core.core.provider_governance import declared_module_architecture
from govoplan_core.core.views import ViewSurface
from govoplan_core.db.base import Base
from govoplan_forms_runtime.backend.db import models as runtime_models
from govoplan_forms_runtime.backend.service import (
CAPABILITY_FORMS_RUNTIME_POLICY_EVALUATOR,
CAPABILITY_FORMS_RUNTIME_REGISTRY,
CAPABILITY_FORMS_RUNTIME_SERVICE_LAUNCHER,
FormRuntimeService,
FormsServiceLauncher,
)
MODULE_ID = "forms_runtime"
MODULE_NAME = "Forms Runtime"
MODULE_VERSION = "0.1.8"
MODULE_VERSION = "0.1.14"
PARTICIPATE_SCOPE = "forms_runtime:submission:participate"
READ_SCOPE = "forms_runtime:workspace:read"
WRITE_SCOPE = "forms_runtime:workspace:write"
ADMIN_SCOPE = "forms_runtime:workspace:admin"
OPTIONAL_DEPENDENCIES = (
"forms",
"files",
"approvals",
"workflow_engine",
"portal",
"cases",
"policy",
"audit",
)
@@ -24,7 +63,7 @@ def _permission(scope: str, label: str, description: str) -> PermissionDefinitio
scope=scope,
label=label,
description=description,
category="Forms Runtime",
category=MODULE_NAME,
level="tenant",
module_id=module_id,
resource=resource,
@@ -33,66 +72,255 @@ def _permission(scope: str, label: str, description: str) -> PermissionDefinitio
PERMISSIONS = (
_permission(READ_SCOPE, "View forms runtime workspace", "Read forms runtime records, configuration, and workflow context."),
_permission(WRITE_SCOPE, "Manage forms runtime workspace", "Create and update forms runtime records and workflow state."),
_permission(ADMIN_SCOPE, "Administer forms runtime workspace", "Configure forms runtime policies, templates, and tenant-level administration."),
_permission(
PARTICIPATE_SCOPE,
"Complete assigned forms",
"Start, read, save, and submit the acting account's own Form instances.",
),
_permission(
READ_SCOPE,
"View form submissions",
"Read tenant Form instances, immutable history, and status evidence.",
),
_permission(
WRITE_SCOPE,
"Manage form submissions",
"Review, transition, and hand off tenant Form submissions.",
),
_permission(
ADMIN_SCOPE,
"Administer Forms Runtime",
"Administer Forms Runtime policy, recovery, and retirement.",
),
)
ROLE_TEMPLATES = (
RoleTemplate(
slug="forms_runtime_participant",
name="Forms participant",
description="Complete the acting account's own Forms.",
permissions=(PARTICIPATE_SCOPE,),
default_authenticated=True,
),
RoleTemplate(
slug="forms_runtime_manager",
name="Forms Runtime manager",
description="Manage forms runtime records and workflow state.",
permissions=(READ_SCOPE, WRITE_SCOPE),
description="Review, transition, and hand off Form submissions.",
permissions=(PARTICIPATE_SCOPE, READ_SCOPE, WRITE_SCOPE),
),
RoleTemplate(
slug="forms_runtime_viewer",
name="Forms Runtime viewer",
description="Read forms runtime records and workflow context.",
description="Read Form submissions and their immutable history.",
permissions=(READ_SCOPE,),
),
)
DOCUMENTATION = (
DocumentationTopic(
id=f"{MODULE_ID}.module-boundary",
title=f"{MODULE_NAME} module boundary",
summary="Runtime form submissions for validation, drafts, attachments, signatures, status tracking, and handoff to domain modules.",
body=(
"This repository is currently a platform module seed. It registers the domain boundary, "
"permission surface, role templates, and documentation metadata before runtime APIs, "
"database models, migrations, and WebUI routes are introduced."
),
layer="available",
documentation_types=("admin",),
audience=("operator", "module_admin", "product_owner"),
order=100,
related_modules=OPTIONAL_DEPENDENCIES,
links=(
DocumentationLink(
label="Repository domain boundary",
href="govoplan-forms-runtime/docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",
kind="repository",
),
),
metadata={
"seed": True,
"domain_objects": ['form submissions', 'draft state', 'runtime validation results', 'attachment references', 'signature state', 'handoff status'],
"first_slice": "Define submission, draft, validation, attachment, signature, status, and handoff contracts around existing form definitions.",
},
),
)
def _router(context: ModuleContext):
from govoplan_forms_runtime.backend.router import create_router
return create_router(context.registry)
def _registry(context: ModuleContext) -> FormRuntimeService:
return FormRuntimeService(context.registry)
def _service_launcher(context: ModuleContext) -> FormsServiceLauncher:
return FormsServiceLauncher(context.registry)
def _tenant_summary(session, tenant_id: str) -> dict[str, int]:
current = session.query(runtime_models.FormInstanceRevision).filter(
runtime_models.FormInstanceRevision.tenant_id == tenant_id,
runtime_models.FormInstanceRevision.superseded_at.is_(None),
)
return {
"form_instances": current.count(),
"open_form_instances": current.filter(
runtime_models.FormInstanceRevision.status.in_(
("started", "draft", "submitted", "validated", "needs_review")
)
).count(),
}
manifest = ModuleManifest(
id=MODULE_ID,
name=MODULE_NAME,
version=MODULE_VERSION,
dependencies=("access",),
dependencies=("access", "forms"),
optional_dependencies=OPTIONAL_DEPENDENCIES,
required_capabilities=(CAPABILITY_AUTH_PRINCIPAL_RESOLVER, CAPABILITY_AUTH_PERMISSION_EVALUATOR),
required_capabilities=(
CAPABILITY_AUTH_PRINCIPAL_RESOLVER,
CAPABILITY_AUTH_PERMISSION_EVALUATOR,
CAPABILITY_FORM_DEFINITIONS,
),
optional_capabilities=(CAPABILITY_FORMS_RUNTIME_POLICY_EVALUATOR,),
permissions=PERMISSIONS,
role_templates=ROLE_TEMPLATES,
documentation=DOCUMENTATION,
route_factory=_router,
nav_items=(
NavItem(
path="/forms-runtime",
label="Forms",
icon="form",
required_any=(PARTICIPATE_SCOPE, READ_SCOPE),
order=37,
),
),
frontend=FrontendModule(
module_id=MODULE_ID,
package_name="@govoplan/forms-runtime-webui",
routes=(
FrontendRoute(
path="/forms-runtime",
component="FormsRuntimePage",
required_any=(PARTICIPATE_SCOPE, READ_SCOPE),
order=37,
),
FrontendRoute(
path="/forms-runtime/:instanceId",
component="FormInstancePage",
required_any=(PARTICIPATE_SCOPE, READ_SCOPE),
order=38,
),
),
nav_items=(
NavItem(
path="/forms-runtime",
label="Forms",
icon="form",
required_any=(PARTICIPATE_SCOPE, READ_SCOPE),
order=37,
),
),
view_surfaces=(
ViewSurface(
id="forms_runtime.navigation",
module_id=MODULE_ID,
kind="navigation",
label="Forms navigation",
order=10,
),
ViewSurface(
id="forms_runtime.workspace",
module_id=MODULE_ID,
kind="route",
label="Forms workspace",
order=20,
),
ViewSurface(
id="forms_runtime.instance",
module_id=MODULE_ID,
kind="route",
label="Form instance",
order=30,
),
),
),
provides_interfaces=(
ModuleInterfaceProvider(name="forms_runtime.registry", version="0.1.0"),
ModuleInterfaceProvider(name="forms_runtime.service_launcher", version="0.1.0"),
),
requires_interfaces=(
ModuleInterfaceRequirement(
name="forms.definitions",
version_min="0.1.0",
version_max_exclusive="0.2.0",
),
),
capability_factories={
CAPABILITY_FORMS_RUNTIME_REGISTRY: _registry,
CAPABILITY_FORMS_RUNTIME_SERVICE_LAUNCHER: _service_launcher,
},
capability_documentation={
CAPABILITY_FORMS_RUNTIME_REGISTRY: CapabilityDocumentation(
label="Forms Runtime registry",
summary="Manages tenant-bound, revisioned Form instances and handoff evidence.",
contract_version="0.1.0",
),
CAPABILITY_FORMS_RUNTIME_SERVICE_LAUNCHER: CapabilityDocumentation(
label="Form-bound Service launcher",
summary="Starts a replay-safe Form instance from an exact published Service and Form 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"),
migration_after=("forms",),
retirement_supported=True,
retirement_provider=drop_table_retirement_provider(
runtime_models.FormInstanceEvent,
runtime_models.FormInstanceRevision,
runtime_models.FormInstanceIdentity,
label=MODULE_NAME,
),
retirement_notes="Destructive retirement removes submissions and immutable status evidence and requires a verified database and referenced-evidence recovery plan.",
),
uninstall_guard_providers=(
persistent_table_uninstall_guard(
runtime_models.FormInstanceIdentity,
runtime_models.FormInstanceRevision,
runtime_models.FormInstanceEvent,
label=MODULE_NAME,
),
),
tenant_summary_providers=(_tenant_summary,),
documentation=(
DocumentationTopic(
id="forms_runtime.submissions",
title="Complete and manage Forms",
summary="Save permitted drafts, submit validated values, and retain exact definition and handoff evidence.",
body=(
"Every instance resolves one immutable published Form revision. Draft and final values are validated on the server; final submission also enforces attachment, signature, and policy requirements. "
"Service launches retain the exact Service and binding. History, receipts, and handoffs are append-only, replay-safe, and optimistic-concurrency guarded."
),
layer="configured",
documentation_types=("admin", "user"),
audience=("user", "operator", "module_admin", "product_owner"),
links=(
DocumentationLink(
label="Forms Runtime security and recovery",
href="govoplan-forms-runtime/docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",
kind="repository",
),
),
),
),
architecture=declared_module_architecture(
layer="human_work_procedure",
kind="runtime",
maturity="vertical_slice",
documentation_ref="docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",
test_ref="tests/test_forms_runtime.py",
known_limits=(
"Anonymous public intake, concrete Files/signature adapters, and automatic target handoff execution remain adapter depth; authenticated Portal entry is supported.",
),
supported_authority_modes=("native_authoritative",),
owned_concepts=(
"form instance",
"form submission",
"runtime validation",
"submission receipt",
"form handoff evidence",
),
non_owned_concepts=(
"form definition",
"file content",
"case",
"workflow definition",
"signature key custody",
),
reference_packages=("product.service-to-decision",),
migration_docs=("docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",),
recovery_docs=("docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",),
security_docs=("docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",),
operations_docs=("docs/FORMS_RUNTIME_DOMAIN_BOUNDARY.md",),
),
)