mirror of
https://github.com/idrainformatica/PecFlow.git
synced 2026-06-16 20:55:41 +02:00
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""
|
||
Router Impostazioni Tenant (Fase 6).
|
||
|
||
Endpoint:
|
||
GET /settings → legge le impostazioni del tenant corrente (admin)
|
||
PUT /settings → aggiorna le impostazioni del tenant corrente (admin)
|
||
|
||
Solo gli admin e super_admin possono accedere.
|
||
La sezione "archiviazione" gestisce il toggle mock/produzione per il
|
||
conservatore AgID (Fase 6 – Archiviazione Sostitutiva).
|
||
"""
|
||
|
||
from fastapi import APIRouter
|
||
|
||
from app.dependencies import AdminUser, DB
|
||
from app.schemas.tenant_settings import TenantSettingsResponse, TenantSettingsUpdate
|
||
from app.services.tenant_settings_service import TenantSettingsService
|
||
|
||
router = APIRouter(prefix="/settings", tags=["Impostazioni"])
|
||
|
||
|
||
@router.get(
|
||
"",
|
||
response_model=TenantSettingsResponse,
|
||
summary="Legge le impostazioni del tenant",
|
||
description=(
|
||
"Restituisce la configurazione operativa del tenant: "
|
||
"modalità archiviazione (mock/produzione), endpoint e stato credenziali conservatore."
|
||
),
|
||
)
|
||
async def get_settings(
|
||
current_user: AdminUser,
|
||
db: DB,
|
||
) -> TenantSettingsResponse:
|
||
service = TenantSettingsService(db)
|
||
settings = await service.get_or_create(current_user.tenant_id)
|
||
return TenantSettingsService.to_response(settings)
|
||
|
||
|
||
@router.put(
|
||
"",
|
||
response_model=TenantSettingsResponse,
|
||
summary="Aggiorna le impostazioni del tenant",
|
||
description=(
|
||
"Aggiorna la configurazione operativa del tenant. "
|
||
"Tutti i campi sono opzionali (semantica PATCH). "
|
||
"Il passaggio a modalità 'production' richiede un endpoint conservatore configurato."
|
||
),
|
||
)
|
||
async def update_settings(
|
||
body: TenantSettingsUpdate,
|
||
current_user: AdminUser,
|
||
db: DB,
|
||
) -> TenantSettingsResponse:
|
||
service = TenantSettingsService(db)
|
||
settings = await service.update(current_user.tenant_id, body)
|
||
await db.commit()
|
||
await db.refresh(settings)
|
||
return TenantSettingsService.to_response(settings)
|