This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from importlib.metadata import PackageNotFoundError, version
|
||||
|
||||
from fastapi import Depends, FastAPI
|
||||
from fastapi import HTTPException, status
|
||||
@@ -20,6 +21,13 @@ from govoplan_core.core.runtime_coordination import (
|
||||
from govoplan_core.settings import Settings, settings
|
||||
|
||||
|
||||
def _core_distribution_version() -> str:
|
||||
try:
|
||||
return version("govoplan-core")
|
||||
except PackageNotFoundError:
|
||||
return "development"
|
||||
|
||||
|
||||
def _dev_bootstrap_needs_create_all(database_url: str) -> bool:
|
||||
try:
|
||||
return make_url(database_url).get_backend_name() == "sqlite"
|
||||
@@ -61,7 +69,7 @@ async def lifespan(app: FastAPI):
|
||||
)
|
||||
runtime_agent = RuntimeNodeAgent(
|
||||
settings=settings,
|
||||
software_version=app.version,
|
||||
software_version=_core_distribution_version(),
|
||||
module_ids=module_ids,
|
||||
metadata={"process": "api"},
|
||||
identity=configured_identity
|
||||
@@ -93,7 +101,7 @@ def register_health_details(
|
||||
):
|
||||
app.state.govoplan_runtime_identity = runtime_identity(
|
||||
active_settings,
|
||||
software_version=app.version,
|
||||
software_version=_core_distribution_version(),
|
||||
module_ids=module_ids,
|
||||
)
|
||||
bind_process_runtime_identity(app.state.govoplan_runtime_identity)
|
||||
|
||||
@@ -142,23 +142,58 @@ def _frontend_view_surfaces(manifest: ModuleManifest) -> list[dict[str, object]]
|
||||
def _documentation_help_contexts(manifest: ModuleManifest) -> list[dict[str, object]]:
|
||||
contexts: list[dict[str, object]] = []
|
||||
seen: set[str] = set()
|
||||
|
||||
def append_context(context_id: str, topic) -> None:
|
||||
if not context_id or context_id in seen:
|
||||
return
|
||||
seen.add(context_id)
|
||||
contexts.append(
|
||||
{
|
||||
"id": context_id,
|
||||
"topic_id": topic.id,
|
||||
"title": topic.title,
|
||||
"documentation_types": list(topic.documentation_types),
|
||||
}
|
||||
)
|
||||
|
||||
for topic in manifest.documentation:
|
||||
raw_contexts = topic.metadata.get("help_contexts", ())
|
||||
if isinstance(raw_contexts, str) or not isinstance(raw_contexts, (list, tuple, set)):
|
||||
continue
|
||||
for raw_context in raw_contexts:
|
||||
context_id = str(raw_context).strip()
|
||||
if not context_id or context_id in seen:
|
||||
continue
|
||||
seen.add(context_id)
|
||||
contexts.append(
|
||||
{
|
||||
"id": context_id,
|
||||
"topic_id": topic.id,
|
||||
"title": topic.title,
|
||||
"documentation_types": list(topic.documentation_types),
|
||||
}
|
||||
)
|
||||
append_context(context_id, topic)
|
||||
|
||||
frontend = manifest.frontend
|
||||
if frontend is None or not manifest.documentation:
|
||||
return contexts
|
||||
|
||||
ordered_topics = sorted(manifest.documentation, key=lambda item: (item.order, item.id))
|
||||
|
||||
def baseline_topic(documentation_type: str):
|
||||
return next(
|
||||
(
|
||||
topic
|
||||
for topic in ordered_topics
|
||||
if documentation_type in topic.documentation_types
|
||||
),
|
||||
ordered_topics[0],
|
||||
)
|
||||
|
||||
user_topic = baseline_topic("user")
|
||||
admin_topic = baseline_topic("admin")
|
||||
for route in frontend.routes:
|
||||
if route.surface_id:
|
||||
append_context(route.surface_id, user_topic)
|
||||
for route in frontend.settings_routes:
|
||||
if route.surface_id:
|
||||
append_context(route.surface_id, admin_topic)
|
||||
for item in frontend.nav_items:
|
||||
if item.surface_id:
|
||||
append_context(item.surface_id, user_topic)
|
||||
for surface in frontend.view_surfaces:
|
||||
topic = admin_topic if ".admin." in surface.id else user_topic
|
||||
append_context(surface.id, topic)
|
||||
return contexts
|
||||
|
||||
|
||||
@@ -253,6 +288,7 @@ def create_platform_router(settings: object | None = None) -> APIRouter:
|
||||
if manifest.architecture is not None
|
||||
else None
|
||||
),
|
||||
"information_governance": manifest.information_governance.to_dict(),
|
||||
"external_providers": [
|
||||
declaration.to_dict()
|
||||
for declaration in manifest.external_providers
|
||||
|
||||
Reference in New Issue
Block a user