Files
xenia-pos-local/local_backend/tests/guards/test_no_perm_reads.py
T
bonaminandClaude Opus 5.5 7cbd0325a4 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>
2026-11-14 12:08:01 +02:00

23 lines
980 B
Python

"""Permission guard (D-7, plan step 1.5): nothing reads v1 perm_* attributes any more.
Permissions are keys checked with core.access (holds/can/require). The v1 projection
(core/access/legacy.py) is gone since step 2.99; only migrations still name the columns.
"""
import ast
from pathlib import Path
BACKEND = Path(__file__).resolve().parents[2]
ALLOWED: set[str] = set()
def test_no_perm_attribute_reads():
bad = []
for f in sorted(BACKEND.rglob("*.py")):
rel = f.relative_to(BACKEND).as_posix()
if rel.startswith(("tests/", "migrations/")) or "__pycache__" in rel or rel in ALLOWED:
continue
for node in ast.walk(ast.parse(f.read_text(encoding="utf-8"))):
if isinstance(node, ast.Attribute) and (node.attr.startswith("perm_") or node.attr == "can_cancel_orders"):
bad.append(f"{rel}:{node.lineno}: .{node.attr}")
assert bad == [], "use core.access.check.holds()/can() instead:\n" + "\n".join(bad)