Files
roboco/roboco/api/routes/settings.py
T
Renn F b034c64177 fix(gate): clear the xenon complexity failure + fixable test warnings
- transcript_retention.py: split select_prunable_transcripts into small helpers
  so the module averages complexity rank A (was B — failed make quality / xenon).
- pyproject: move the markers table from [tool.coverage.run] (coverage warned
  'Unrecognized option') to [tool.pytest.ini_options] where it belongs.
- HTTP_422_UNPROCESSABLE_ENTITY -> HTTP_422_UNPROCESSABLE_CONTENT (old name
  deprecated) in the tasks/product/settings routes + the validation middleware.
- conftest: drop pool_pre_ping on the per-test engine — pointless for a fresh
  per-test engine and it leaves an un-awaited asyncpg Connection._cancel
  coroutine that surfaced as a RuntimeWarning across ~30 integration tests.
2026-06-12 23:51:45 +02:00

38 lines
1.4 KiB
Python

"""System settings API — read and update runtime-editable settings.
Backs the panel settings page. Values persist in the ``system_settings`` table
and are read by the backend (e.g. the transcript-retention prune sweep) with a
``roboco.config`` default as the fallback when a key is unset.
"""
from fastapi import APIRouter, HTTPException, status
from roboco.api.deps import DbSession
from roboco.api.schemas.settings import SettingsResponse, SettingUpdate
from roboco.services.settings import SettingValidationError, get_settings_service
router = APIRouter()
@router.get("", response_model=SettingsResponse)
async def list_settings(db: DbSession) -> SettingsResponse:
"""Return every stored runtime-editable setting."""
return SettingsResponse(settings=await get_settings_service(db).all())
@router.put("/{key}", response_model=SettingsResponse)
async def update_setting(
key: str, data: SettingUpdate, db: DbSession
) -> SettingsResponse:
"""Validate and persist a single setting, returning the full updated map."""
service = get_settings_service(db)
try:
await service.set(key, data.value)
except SettingValidationError as exc:
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)
) from exc
# Write route commits explicitly (get_db auto-commit is unreliable).
await db.commit()
return SettingsResponse(settings=await service.all())