feat(settings): save display settings without an API key

Asking for the key every time a phone changes a chart option was friction
the owner doesn't want. These settings only change how data is displayed
(averaging, scale, chart range, language default), so PUT /api/settings is
now open. Inverter edits (name, kWp, ...) and ingest still need the key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 18:24:16 +03:00
co-authored by Claude Opus 5.5
parent 9ac86e2588
commit 80f82c8c63
7 changed files with 14 additions and 36 deletions
+4 -7
View File
@@ -139,14 +139,11 @@ def get_view_settings(conn: Db):
return _load_view_settings(conn)
@router.put(
"/settings",
response_model=ViewSettings,
dependencies=[Depends(require_api_key)],
tags=["settings"],
)
@router.put("/settings", response_model=ViewSettings, tags=["settings"])
def put_view_settings(conn: Db, body: ViewSettings):
"""Replace the display options for every viewer. Omitted keys reset to their default."""
"""Replace the display options for every viewer. Omitted keys reset to their default.
Open to anyone on purpose: these only change how data is displayed, and
the owner wants them adjustable without a key."""
set_meta(conn, SETTINGS_KEY, body.model_dump_json())
return body
+2 -2
View File
@@ -197,8 +197,8 @@ def test_view_settings_shared_defaults_and_auth(client):
body = {**s, "comparison_readings": 3, "comparison_scale": "custom", "comparison_custom_kw": 25,
"power_range": "run", "power_smoothing": "light", "future_option": True}
assert client.put("/api/settings", json=body, headers={"X-API-Key": "nope"}).status_code == 401
saved = client.put("/api/settings", json=body).json()
# No API key needed: display options only
saved = client.put("/api/settings", json=body, headers={"X-API-Key": ""}).json()
assert saved["comparison_custom_kw"] == 25 and "future_option" not in saved
assert client.get("/api/settings").json()["power_range"] == "run"