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
+10 -9
View File
@@ -22,10 +22,11 @@ def admin_h(make_user, login):
# ── manager logins ───────────────────────────────────────────────────────────
def test_current_manager_ui_login_keeps_v1_rules(client, make_user):
def test_login_needs_client(client, make_user): # the v1 no-`client` path is gone (2.99)
m = make_user(role="store_manager")
assert client.post("/api/auth/login", json={"username": m.username, "password": TEST_PASSWORD}).status_code == 200
assert client.post("/api/auth/login", json={"username": m.username, "pin": TEST_PIN}).status_code == 200 # lock screen
r = client.post("/api/auth/login", json={"username": m.username, "password": TEST_PASSWORD})
assert r.status_code == 422 and r.json()["error"]["code"].startswith("validation.")
assert client.post("/api/auth/login", json={"client": "manager", "username": m.username, "password": TEST_PASSWORD}).status_code == 200
def test_manager_password_mode_refuses_pin(client, make_user, admin_h):
@@ -46,10 +47,10 @@ def test_manager_none_mode_is_gone(client, admin_h): # D-8
def test_wrong_password_and_wrong_app(client, make_user):
m = make_user(role="store_manager")
r = client.post("/api/auth/login", json={"username": m.username, "password": "nope"})
r = client.post("/api/auth/login", json={"client": "manager", "username": m.username, "password": "nope"})
assert r.status_code == 401 and r.json()["error"]["code"] == "auth.invalid_credentials"
w = make_user(role="waiter")
r = client.post("/api/auth/login", json={"username": w.username, "password": TEST_PASSWORD})
r = client.post("/api/auth/login", json={"client": "manager", "username": w.username, "password": TEST_PASSWORD})
assert r.status_code == 403 and r.json()["error"] == {"code": "auth.client_not_allowed", "params": {"client": "manager"},
"message": "This account can't use the manager app."}
@@ -88,7 +89,7 @@ def test_waiter_modes(client, make_user, admin_h):
def test_token_carries_sid_and_logout_ends_it(client, make_user):
m = make_user(role="store_manager")
h = _bearer(client.post("/api/auth/login", json={"username": m.username, "password": TEST_PASSWORD}))
h = _bearer(client.post("/api/auth/login", json={"client": "manager", "username": m.username, "password": TEST_PASSWORD}))
payload = jwt.decode(h["Authorization"][7:], options={"verify_signature": False})
assert len(payload["sid"]) == 32
assert client.get("/api/auth/me", headers=h).status_code == 200
@@ -118,7 +119,7 @@ def test_refuse_new(client, make_user, admin_h):
def test_single_session_is_per_client(client, make_user, admin_h):
_set(client, admin_h, "auth.single_session_waiter", "end_old")
owner = make_user(role="owner") # owners can use both apps
mgr = _bearer(client.post("/api/auth/login", json={"username": owner.username, "password": TEST_PASSWORD}))
mgr = _bearer(client.post("/api/auth/login", json={"client": "manager", "username": owner.username, "password": TEST_PASSWORD}))
client.post("/api/auth/login", json={"client": "waiter", "user_id": owner.id, "pin": TEST_PIN})
assert client.get("/api/auth/me", headers=mgr).status_code == 200
@@ -146,7 +147,7 @@ def test_blocking_a_user_ends_their_sessions(client, make_user, login):
def test_refresh_keeps_the_session(client, make_user):
m = make_user(role="store_manager")
h = _bearer(client.post("/api/auth/login", json={"username": m.username, "password": TEST_PASSWORD}))
h = _bearer(client.post("/api/auth/login", json={"client": "manager", "username": m.username, "password": TEST_PASSWORD}))
new = _bearer(client.post("/api/auth/refresh", headers=h))
sid = lambda hh: jwt.decode(hh["Authorization"][7:], options={"verify_signature": False})["sid"] # noqa: E731
assert sid(new) == sid(h)
@@ -165,6 +166,6 @@ def test_session_survives_cache_loss_like_a_restart(client, make_user):
keeps the token valid. The real restart is checked in the plan notes."""
from core import sessions
m = make_user(role="store_manager")
h = _bearer(client.post("/api/auth/login", json={"username": m.username, "password": TEST_PASSWORD}))
h = _bearer(client.post("/api/auth/login", json={"client": "manager", "username": m.username, "password": TEST_PASSWORD}))
sessions.clear_cache()
assert client.get("/api/auth/me", headers=h).status_code == 200