feat(backend): KDS settings as device config, zone enforced for kitchen screens, KDS-only API (platform-v2 3.2a)
- KDS manifest: 23 typed settings (prep zone, board, waiting-time minutes and colours,
behaviour) replacing the KDS page's localStorage settings.
- ConfigField: colour type, "after" ordering (warning < late < flash), groups for the
manager's dialogs, ".none" text for an empty ref choice.
- routers/kds.py: a KDS device gets only its zone's orders, prints to its zone by default
and signs waiter messages with its zone/name. New GET /api/kds/context and
POST /api/kds/orders/{id}/retry-print so the screen never leaves its kds.* scope.
Unused v1 /items and /items/{id}/status endpoints removed (D-21).
- PATCH /api/devices/me/config: a screen changes its own settings when the signed-in
person holds core.devices.manage.
- Manager Devices dialogs: settings in sections, colour pickers, "All zones".
- Tests: test_kds_device.py, colour/ordered fields; terminal.mjs scope + zone checks;
manager.mjs settings sections; stack.mjs detaches the non-LAN network before the
restart check (one flaky 403).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -24,6 +24,9 @@ Agent notes:
|
||||
- Live (3.1a): an edit sends `device.updated` to the device's open sockets; reassign sends
|
||||
`device.updated` and closes them; revoke sends `device.revoked` and closes them
|
||||
(services/ws_bus.py). The screen re-reads GET /me or goes back to pairing.
|
||||
- A screen may change its own settings (PATCH /me/config, 3.2a, e.g. the KDS settings
|
||||
panel) when the person signed in on it holds core.devices.manage. That one key is checked
|
||||
without the device scope: the call can only ever change the calling device.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -47,6 +50,7 @@ from core.errors import XeniaError
|
||||
from core.modules.registry import registry
|
||||
from core.timeutil import iso_z, utcnow
|
||||
from database import get_db
|
||||
from routers.deps import get_current_user
|
||||
from models.device import Device, DevicePairRequest
|
||||
from services import ws_bus
|
||||
|
||||
@@ -310,6 +314,31 @@ def device_users(db: Session = Depends(get_db), device=Depends(require_device())
|
||||
for u in users if u.role != "superadmin"]
|
||||
|
||||
|
||||
class SelfConfigPatch(BaseModel):
|
||||
config: dict
|
||||
|
||||
|
||||
@router.patch("/me/config")
|
||||
def update_own_config(body: SelfConfigPatch, request: Request, db: Session = Depends(get_db),
|
||||
device=Depends(require_device()), user=Depends(get_current_user)):
|
||||
"""The screen changes its own settings (sent keys are merged into the stored ones).
|
||||
Needs a signed-in person holding core.devices.manage on this screen."""
|
||||
from core.access.check import check
|
||||
from core.access.context import context_for
|
||||
ctx = context_for(request, user, db)
|
||||
ctx.device = None # this key on this route acts on the calling device only (see Agent notes)
|
||||
check(ctx, MANAGE, db)
|
||||
if device.revoked_at is not None:
|
||||
raise XeniaError("device.revoked")
|
||||
fields = device_config.for_app(device.app_key)
|
||||
current = _effective_config(device, db)
|
||||
kept = {k: v for k, v in (device.config or {}).items() if k in current and current[k] == v}
|
||||
device.config = _config(device.app_key, {**kept, **body.config}, db)
|
||||
db.commit()
|
||||
ws_bus.notify_device([device.id])
|
||||
return {"config": device_config.effective(fields, device.config, db)}
|
||||
|
||||
|
||||
@router.get("/{device_id}")
|
||||
def get_device(device_id: int, db: Session = Depends(get_db), user=Depends(require(MANAGE))):
|
||||
return _out(_get(db, device_id), db)
|
||||
|
||||
Reference in New Issue
Block a user