"""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 only file that knows the 13 v1 booleans is core/access/legacy.py (temporary projection for the current frontends). The UserOut schema declares them as output fields, which isn't a read. """ import ast from pathlib import Path BACKEND = Path(__file__).resolve().parents[2] ALLOWED = {"core/access/legacy.py"} 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)