3 Commits

Author SHA1 Message Date
polaris-smart
b9b41dd529 style(tests): ruff-format the role normalization tests 2026-09-24 08:19:40 +08:00
polaris-smart
85c6cad6b2 feat(auth): admit "teacher" and "student" role values in the single role whitelist
Extend the role vocabulary admitted by the single source of truth
(VALID_ROLES + normalize_role + the Role literal) that #1556 introduced.
Authorization stays least-privilege: only "admin" elevates, defaults are
unchanged, unknown values still degrade to "user", and the diff is fully
revertible one line per value. Capability wiring for the new roles stays
deployment policy; "parent" is deliberately out of scope.

Tests: parametrized passthrough over the four documented roles, set_role
round-trip for the new values, non-elevation assertions, and a "parent"
negative control proving the whitelist decides.
2026-09-24 08:19:39 +08:00
Hermes
3f621d403a refactor(auth): converge all role whitelists on normalize_role, add set_role tests
- models.py: add VALID_ROLES + normalize_role as the single source of truth
- identity.py: route _canonical_record/_migrate_legacy_users/load_users/set_role through normalize_role
- context.py: token payload role mapping via normalize_role
- services/auth.py + api/routers/auth.py: set_role guards validate against VALID_ROLES
- tests/multi_user/test_role_normalization.py: 16 tests, first set_role coverage in repo

Zero behavior change: legal roles pass through; unknown values keep the
same least-privilege degrade path; only guard error strings derived from
sorted(VALID_ROLES) differ.
2026-09-23 01:21:17 +08:00