Fix setup persistence and load persisted runtime configuration
This commit is contained in:
@@ -10,10 +10,10 @@ from __future__ import annotations
|
||||
import structlog
|
||||
from fastapi import APIRouter, HTTPException, status
|
||||
|
||||
from app.dependencies import AppDep, DbDep
|
||||
from app.dependencies import AppDep, DbDep, SettingsDep
|
||||
from app.models.setup import SetupRequest, SetupResponse, SetupStatusResponse, SetupTimezoneResponse
|
||||
from app.services import setup_service
|
||||
from app.utils.setup_state import set_setup_complete_cache
|
||||
from app.utils.setup_state import is_setup_complete_cached, set_setup_complete_cache
|
||||
|
||||
log: structlog.stdlib.BoundLogger = structlog.get_logger()
|
||||
|
||||
@@ -25,14 +25,14 @@ router = APIRouter(prefix="/api/setup", tags=["setup"])
|
||||
response_model=SetupStatusResponse,
|
||||
summary="Check whether setup has been completed",
|
||||
)
|
||||
async def get_setup_status(db: DbDep) -> SetupStatusResponse:
|
||||
async def get_setup_status(app: AppDep) -> SetupStatusResponse:
|
||||
"""Return whether the initial setup wizard has been completed.
|
||||
|
||||
Returns:
|
||||
:class:`~app.models.setup.SetupStatusResponse` with ``completed``
|
||||
set to ``True`` if setup is done, ``False`` otherwise.
|
||||
"""
|
||||
done = await setup_service.is_setup_complete(db)
|
||||
done = is_setup_complete_cached(app)
|
||||
return SetupStatusResponse(completed=done)
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ async def post_setup(
|
||||
Raises:
|
||||
HTTPException: 409 if setup has already been completed.
|
||||
"""
|
||||
if await setup_service.is_setup_complete(db):
|
||||
if is_setup_complete_cached(app) or await setup_service.is_setup_complete(db):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_409_CONFLICT,
|
||||
detail="Setup has already been completed.",
|
||||
@@ -75,6 +75,14 @@ async def post_setup(
|
||||
session_duration_minutes=body.session_duration_minutes,
|
||||
)
|
||||
set_setup_complete_cache(app, True)
|
||||
app.state.settings = app.state.settings.model_copy(
|
||||
update={
|
||||
"database_path": body.database_path,
|
||||
"fail2ban_socket": body.fail2ban_socket,
|
||||
"timezone": body.timezone,
|
||||
"session_duration_minutes": body.session_duration_minutes,
|
||||
}
|
||||
)
|
||||
return SetupResponse()
|
||||
|
||||
|
||||
@@ -83,7 +91,7 @@ async def post_setup(
|
||||
response_model=SetupTimezoneResponse,
|
||||
summary="Return the configured IANA timezone",
|
||||
)
|
||||
async def get_timezone(db: DbDep) -> SetupTimezoneResponse:
|
||||
async def get_timezone(settings: SettingsDep) -> SetupTimezoneResponse:
|
||||
"""Return the IANA timezone configured during the initial setup wizard.
|
||||
|
||||
The frontend uses this to convert UTC timestamps to the local time zone
|
||||
@@ -94,5 +102,4 @@ async def get_timezone(db: DbDep) -> SetupTimezoneResponse:
|
||||
set to the stored IANA identifier (e.g. ``"UTC"`` or
|
||||
``"Europe/Berlin"``), defaulting to ``"UTC"`` if unset.
|
||||
"""
|
||||
tz = await setup_service.get_timezone(db)
|
||||
return SetupTimezoneResponse(timezone=tz)
|
||||
return SetupTimezoneResponse(timezone=settings.timezone)
|
||||
|
||||
Reference in New Issue
Block a user