Move Resos API key to central Settings service; add sidebar scrollbar styling

Removes the standalone resos_api_key from the forecasting app's own
system_config table. All credential fetches now go through
central_settings.get_resos_credentials() / get_resos_credentials_sync()
which pull from the Settings app (LXC 116) via the internal integration
endpoint — the same pattern already used for NewBook. The Resos API
Config section is removed from the forecasting Settings page; users
manage the key in the central Settings app instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-13 14:35:35 +00:00
parent 9057d764fa
commit 3650c92175
7 changed files with 51 additions and 282 deletions

View file

@ -137,81 +137,6 @@ async def test_newbook_settings(
return await _test_newbook(db)
# ============================================
# RESOS SETTINGS ENDPOINTS
# ============================================
class ResosSettingsResponse(BaseModel):
resos_api_key_set: bool = False
class ResosSettingsUpdate(BaseModel):
resos_api_key: Optional[str] = None
@router.get("/settings/resos", response_model=ResosSettingsResponse)
async def get_resos_settings(
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user)
):
"""Get Resos settings"""
result = await db.execute(
text("SELECT config_value FROM system_config WHERE config_key = 'resos_api_key'")
)
row = result.fetchone()
resos_api_key_set = bool(row and row.config_value)
return ResosSettingsResponse(resos_api_key_set=resos_api_key_set)
@router.post("/settings/resos")
async def update_resos_settings(
settings: ResosSettingsUpdate,
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user)
):
"""Update Resos settings"""
# Update Resos API key (encrypted)
if settings.resos_api_key:
encrypted_key = base64.b64encode(settings.resos_api_key.encode()).decode()
await db.execute(
text("""
INSERT INTO system_config (config_key, config_value, is_encrypted, updated_at, updated_by)
VALUES ('resos_api_key', :value, true, NOW(), :user)
ON CONFLICT (config_key) DO UPDATE SET
config_value = :value,
is_encrypted = true,
updated_at = NOW(),
updated_by = :user
"""),
{"value": encrypted_key, "user": current_user['username']}
)
await db.commit()
return {"status": "saved", "message": "Resos settings updated"}
@router.post("/settings/resos/test")
async def test_resos_settings(
db: AsyncSession = Depends(get_db),
current_user: dict = Depends(get_current_user)
):
"""Test Resos connection with current settings"""
try:
from services.resos_client import ResosClient
async with await ResosClient.from_db(db) as client:
if not client.api_key:
raise HTTPException(status_code=400, detail="Resos API key not configured")
success = await client.test_connection()
if success:
return {"status": "success", "message": "Connected to Resos API successfully"}
else:
raise HTTPException(status_code=400, detail="Connection failed - check API key")
except HTTPException:
raise
except Exception as e:
raise HTTPException(status_code=500, detail=f"Connection test failed: {str(e)}")
# ============================================
@ -840,8 +765,10 @@ async def _test_newbook(db: AsyncSession):
async def _test_resos(db: AsyncSession):
"""Test Resos API connection"""
import httpx
from services.central_settings import get_resos_credentials
api_key = await _get_config_value(db, "resos_api_key")
creds = await get_resos_credentials()
api_key = creds["api_key"] if creds else None
if not api_key:
raise HTTPException(status_code=400, detail="Resos API key not configured")