feat: project role-bound postboxes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from dataclasses import asdict
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -10,11 +11,13 @@ from govoplan_core.core.institutional import (
|
||||
InstitutionalContextError,
|
||||
InstitutionalReference,
|
||||
)
|
||||
from govoplan_core.core.postbox import postbox_portal_projection_provider
|
||||
from govoplan_core.db.session import get_session
|
||||
from govoplan_portal.backend.schemas import (
|
||||
PortalServiceLaunchRequest,
|
||||
PortalServiceLaunchResponse,
|
||||
PortalServiceListResponse,
|
||||
PortalPostboxListResponse,
|
||||
)
|
||||
from govoplan_portal.backend.service_directory import (
|
||||
PortalServiceDirectory,
|
||||
@@ -66,6 +69,32 @@ def api_list_portal_services(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/postboxes", response_model=PortalPostboxListResponse)
|
||||
def api_list_portal_postboxes(
|
||||
limit: int = Query(default=100, ge=1, le=500),
|
||||
session: Session = Depends(get_session),
|
||||
principal: ApiPrincipal = Depends(get_api_principal),
|
||||
) -> PortalPostboxListResponse:
|
||||
if not has_scope(principal, READ_SCOPE):
|
||||
raise HTTPException(status_code=403, detail=f"Missing scope: {READ_SCOPE}")
|
||||
provider = postbox_portal_projection_provider(_registry)
|
||||
if provider is None:
|
||||
return PortalPostboxListResponse(
|
||||
provider_available=False,
|
||||
postboxes=[],
|
||||
)
|
||||
entries = provider.list_portal_entries(
|
||||
session,
|
||||
principal,
|
||||
tenant_id=principal.tenant_id,
|
||||
limit=limit,
|
||||
)
|
||||
return PortalPostboxListResponse(
|
||||
provider_available=True,
|
||||
postboxes=[asdict(entry) for entry in entries],
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/services/{service_id}/launch",
|
||||
response_model=PortalServiceLaunchResponse,
|
||||
|
||||
Reference in New Issue
Block a user