Panels become devices: per-device documents in the flow repo, a Devices tab
- flow/devices.py: DeviceDef in FLOWS_DIR/_devices/<id>.json, committed under
the flow store's write lock, 409 on a stale version; nonces in DEVICES_FILE
outside git; in-memory presence announced as device_status
- api/routes/devices.py: CRUD, pairing with an optional {name, board,
firmware}, a pending list adopted without a code from the LAN only, unpair;
/panels/pair, /panels/pair/{code} and GET /panels/{id} kept as aliases,
PUT /panels/ gone
- _device_may replaces _panel_may, JWT claims unchanged
- panels.json moves into devices once at startup, then .migrated
- MCP list_devices, get_device; search category device
- Devices tab (list, detail with presence, pairing, ordered dashboards,
touch, I/O), PanelsDialog removed, serialised optimistic saves
This commit is contained in:
+16
-21
@@ -24,7 +24,6 @@ from sqlmodel import Session
|
||||
from fluksio.api.deps import decode_token, user_from_token
|
||||
from fluksio.cloud import config as cloud_config
|
||||
from fluksio.core.config import settings
|
||||
from fluksio.flow.panels import PanelDef, PanelsConfig, write_config
|
||||
from fluksio.models import User
|
||||
from tests.utils.portal import ISSUER, jwks, portal_token
|
||||
from tests.utils.user import create_random_user
|
||||
@@ -261,14 +260,18 @@ def test_a_panel_scoped_portal_token_reaches_only_its_panel(
|
||||
The portal names the panel; everything about what that means is this
|
||||
instance's, which is the whole reason it may mint one at all.
|
||||
"""
|
||||
write_config(
|
||||
PanelsConfig(
|
||||
panels=[
|
||||
PanelDef(id="hallway", dashboards=["kitchen"]),
|
||||
PanelDef(id="workshop", dashboards=["bench"]),
|
||||
]
|
||||
devices = f"{settings.API_V1_STR}/devices"
|
||||
for device_id, dashboard in (("hallway", "kitchen"), ("workshop", "bench")):
|
||||
client.delete(f"{devices}/{device_id}", headers=superuser_token_headers)
|
||||
created = client.post(
|
||||
f"{devices}/{device_id}", headers=superuser_token_headers
|
||||
).json()
|
||||
saved = client.put(
|
||||
f"{devices}/{device_id}",
|
||||
headers=superuser_token_headers,
|
||||
json={**created, "dashboards": [dashboard]},
|
||||
)
|
||||
)
|
||||
assert saved.status_code == 200, saved.text
|
||||
for name in ("kitchen", "bench"):
|
||||
created = client.post(
|
||||
f"{settings.API_V1_STR}/dashboards/{name}", headers=superuser_token_headers
|
||||
@@ -290,10 +293,7 @@ def test_a_panel_scoped_portal_token_reaches_only_its_panel(
|
||||
token = portal_token(portal_key, subject="hallway", scope="panel")
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
assert (
|
||||
client.get(f"{settings.API_V1_STR}/panels/hallway", headers=headers).status_code
|
||||
== 200
|
||||
)
|
||||
assert client.get(f"{devices}/hallway", headers=headers).status_code == 200
|
||||
assert (
|
||||
client.get(
|
||||
f"{settings.API_V1_STR}/dashboards/kitchen", headers=headers
|
||||
@@ -307,19 +307,14 @@ def test_a_panel_scoped_portal_token_reaches_only_its_panel(
|
||||
).status_code
|
||||
== 403
|
||||
)
|
||||
assert (
|
||||
client.get(f"{settings.API_V1_STR}/panels/", headers=headers).status_code == 403
|
||||
)
|
||||
assert client.get(f"{devices}/", headers=headers).status_code == 403
|
||||
assert (
|
||||
client.get(f"{settings.API_V1_STR}/flows/", headers=headers).status_code == 403
|
||||
)
|
||||
|
||||
# Deleting the panel is how the screen is retired, whoever minted its token.
|
||||
write_config(PanelsConfig(panels=[PanelDef(id="workshop", dashboards=["bench"])]))
|
||||
assert (
|
||||
client.get(f"{settings.API_V1_STR}/panels/hallway", headers=headers).status_code
|
||||
== 401
|
||||
)
|
||||
# Deleting the device is how the screen is retired, whoever minted its token.
|
||||
client.delete(f"{devices}/hallway", headers=superuser_token_headers)
|
||||
assert client.get(f"{devices}/hallway", headers=headers).status_code == 401
|
||||
|
||||
|
||||
def test_a_panel_token_naming_no_panel_is_refused(
|
||||
|
||||
Reference in New Issue
Block a user