refactor(backend): remove the v1 auth and permission leftovers no frontend uses

Platform-v2 step 2.99a. After 2.6 no frontend calls these any more:
- POST /api/auth/login needs `client` (manager/waiter/terminal); the no-`client`
  path with v1 rules and the `legacy_manager` single-session exception are gone.
- GET /api/setup/security-config (bootstrap's `login` replaced it in 2.6b).
- POST /api/recovery/use (a recovery code works in the normal login's
  password field).
- PUT /api/waiters/{id}/permission and /reset-permissions (the permission editor
  saves keys with PUT /{id}/permissions); staff create/update ignore perm_* fields.
- The v1 perm_* projection: core/access/legacy.py deleted, UserOut carries only
  `permissions` (no app reads the 13 booleans, waiter included).
e2e manager login sends client "manager"; smoke_routes too. Backend 281 passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 12:08:01 +02:00
co-authored by Claude Opus 5.5
parent eb22997f8e
commit 7cbd0325a4
17 changed files with 57 additions and 249 deletions
+2 -2
View File
@@ -26,6 +26,6 @@ access.override_possible instead of access.denied; a manager's PIN gives a one-t
token (POST /api/access/override) that check() or require_override() consumes.
Files: override.py (approval tokens), context.py (device lookup, scope, get_context, authorize), templates.py (role templates from manifests), check.py (the decision),
deps.py (route markers), legacy.py (temporary v1 perm_* projection for the current
frontends, §3.3), queries.py (find users holding a key).
deps.py (route markers), queries.py (find users holding a key). The v1 perm_* projection
(legacy.py) was removed in step 2.99: no frontend reads or writes the booleans.
"""
-48
View File
@@ -1,48 +0,0 @@
"""TEMPORARY v1 projection (APPS_PLATFORM §3.3). Delete with the last frontend that reads it.
The current manager dashboard and waiter app still read and write 13 boolean fields
(perm_access_dashboard ...). This file is the ONLY place that knows them:
- project(user): booleans computed from the user's keys, for UserOut
- apply_booleans(user, {field: bool}): a frontend toggled a boolean -> grant/revoke keys
Not for deployed v1 sites (D-21): it only keeps our own unconverted screens usable on
the branch. Plan: removed when the manager (phase 2/6) and waiter app (phase 4) use keys.
"""
from __future__ import annotations
from core.access.check import holds, user_keys
# boolean -> keys it stands for. Projection: True if the user holds the FIRST key.
LEGACY_MAP: dict[str, tuple[str, ...]] = {
"perm_access_dashboard": ("core.dashboard.access",),
"perm_access_waiter_app": ("waiter_app.access",),
"perm_access_kds": ("kds.access", "kds.bump"),
"perm_cancel_orders": ("ordering.orders.cancel",),
"perm_apply_discounts": ("pricing.discounts.apply",),
"perm_modify_prices": ("ordering.prices.modify",),
"perm_open_orders": ("ordering.orders.open",),
"perm_close_orders": ("ordering.orders.close",),
"perm_view_reports": ("reports.view", "history.view"),
"perm_manage_staff": ("core.staff.manage",),
"perm_manage_tables": ("catalog.tables.manage",),
"perm_manage_menu": ("catalog.menu.manage",),
"perm_manage_settings": ("core.settings.manage",),
}
LEGACY_FIELDS = tuple(LEGACY_MAP)
def project(user) -> dict[str, bool]:
return {field: holds(user, keys[0]) for field, keys in LEGACY_MAP.items()}
def apply_booleans(user, values: dict) -> None:
"""Grant/revoke the keys behind each boolean present in `values` (None = untouched)."""
from core.access.templates import set_user_keys
keys = set(user_keys(user))
for field, val in values.items():
if field not in LEGACY_MAP or val is None:
continue
if val:
keys |= set(LEGACY_MAP[field])
else:
keys -= set(LEGACY_MAP[field])
set_user_keys(user, keys)
+1 -5
View File
@@ -62,7 +62,7 @@ def single_session_rule(db, client: str) -> str:
# ── lifecycle ────────────────────────────────────────────────────────────────
def start(db, user, client: str, request=None, *, legacy_manager: bool = False, device=None, expires_at=None):
def start(db, user, client: str, request=None, *, device=None, expires_at=None):
"""Create a session for user (None user_id for the support account). Commits.
`device`: the paired device of a terminal login; its previous sessions are replaced
(a shared screen shows one user at a time)."""
@@ -71,10 +71,6 @@ def start(db, user, client: str, request=None, *, legacy_manager: bool = False,
raise ValueError(f"unknown client {client!r}")
user_id = getattr(user, "id", None) or None
rule = single_session_rule(db, client)
if legacy_manager and rule == "refuse_new":
# The current manager UI re-logs-in to unlock its lock screen; refusing would lock
# the owner out. Until the phase 2 manager has a real unlock, treat it as end_old.
rule = "end_old"
if user_id is not None and rule != "off":
active = db.query(LoginSession).filter(LoginSession.user_id == user_id, LoginSession.client == client,
LoginSession.ended_at.is_(None)).all()