Files
PecHub/backend/app/api/v1/settings.py
T
2026-03-19 14:43:36 +01:00

60 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
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)