Files
leocrm/app/routes/miniapps.py
T
Agent Zero 03dd477899
Check Cross-Plugin Imports / check (push) Has been cancelled
feat(N4): Restliche Module — Tasks/Kommunikation/Wiki/Reports/Agents/Tags/Search + Navigation + Dashboard-Schnittstelle (#368)
- Scope-Deklarationen: tasks only_mine, kommunikation conversation_ids, wiki category_ids (NEUE contracts.py), report_generator template_ids, automation agent_ids (module_key agents), tags tag_ids, unified_search entity_types dynamisch aus Provider-Registry
- Core-Beiträge: navigation default_route (Startseite) + dashboard widget_app_ids (Widget-TYP-Angebot, Layout bleibt Phase M)
- Backend-Filter (additive UND): /tasks (only_mine), /comm/conversations, /wiki/articles+/categories (Subtree), /reports/print-templates, /agents, /tags, /search GET+POST (entity_types-Schnitt), /miniapps?host=dashboard
- apply_entity_type_scope-Helper (requested ∧ scope)
- Frontend: WorkspaceSwitcher default_route-Navigation, Sidebar workspace-menu_order-Sortierung, workspaceStore moduleMenuOrder()
- Tests: 18/18 Deklarationen + 11/11 Filter (TDD), Frontend 2/2 + Store 18/18, tsc clean, Build OK
- Regression 64 passed (4 Kombi-Failures = Suite-Isolation, solo-bewiesen); Checker 0; Ruff = Vorbestand (Stash-bewiesen)
2026-09-01 23:23:15 +02:00

66 lines
2.4 KiB
Python

"""MiniApps API — universal registry listing (Phase M1).
Platform-level endpoint (the registry is a platform concept, not owned by
a single plugin): lists MiniApps with server-side permission filtering
(fail-closed) and optional host filter.
"""
from __future__ import annotations
from fastapi import APIRouter, Depends, HTTPException
from app.deps import get_current_user, require_workspace_scope
from app.plugins.miniapp_registry import get_miniapp_registry, user_permits
router = APIRouter(prefix="/api/v1/miniapps", tags=["miniapps"])
# Backward-compatible alias (the canonical helper lives in the registry
# module since Phase M2 — shared with the personal dashboard seed).
_user_permits = user_permits
@router.get("")
async def list_miniapps(
host: str | None = None,
current_user: dict = Depends(get_current_user),
workspace_scope: dict | None = Depends(require_workspace_scope("dashboard")),
):
"""List MiniApps visible to the current user (permission-filtered).
``?host=chat|dashboard|window`` filters by the hosts declared on the
MiniApp definition.
Phase N4: a workspace scope with widget_app_ids limits the OFFERED
widget types — only for host=dashboard (admin boundary). Personal
layouts stay user-owned (Phase M split).
"""
registry = get_miniapp_registry()
items = [a for a in registry.list_apps(host=host) if _user_permits(current_user, a)]
if workspace_scope and host == "dashboard":
widget_ids = workspace_scope.get("widget_app_ids")
if isinstance(widget_ids, list) and widget_ids:
allowed = set(widget_ids)
items = [a for a in items if a.get("app_id") in allowed]
items.sort(key=lambda a: a.get("order", 100))
return {"items": items, "total": len(items)}
@router.get("/{app_id}")
async def get_miniapp(
app_id: str,
current_user: dict = Depends(get_current_user),
):
"""Get a single MiniApp definition (403 without permission, 404 unknown)."""
app = get_miniapp_registry().get_app(app_id)
if app is None:
raise HTTPException(404, detail={"detail": "MiniApp not found", "code": "not_found"})
data = app.model_dump()
if not _user_permits(current_user, data):
raise HTTPException(
403,
detail={
"detail": f"Permission '{data['permission']}' required",
"code": "forbidden",
},
)
return data