Repository navigation
feat(roles): replace is_superuser with admin/manager/member - #2534
Closed
zachross90210 wants to merge 3 commits into
Closed
zachross90210 wants to merge 3 commits into
zachross90210 wants to merge 3 commits into
Conversation
Add UserRole and a role column backed by a check constraint. The migration backfills admin from is_superuser and member for everyone else, then drops is_superuser. Routes authorize through require_roles with AdminUser and StaffUser aliases. Staff can read users and the new /metrics endpoint. Only admins mutate users or bypass item ownership. Roles are read from the database on each request, so changes apply to existing tokens. Co-authored-by: Cursor <cursoragent@cursor.com>
Regenerate the client from OpenAPI. Staff reach /admin and the new /metrics page; members are redirected. Only admins see Add User and row actions. The superuser checkbox becomes a role select. handleApiError now logs out only on session errors (401, Inactive user, invalid credentials). Authorization 403s refresh the current user instead of wiping the token. Co-authored-by: Cursor <cursoragent@cursor.com>
python -m app.seed_demo_users creates demo-admin, demo-manager, and demo-member users and converges them to their role, active state, and password on rerun. It refuses to run unless FASTAPI_ENV is development and leaves FIRST_SUPERUSER untouched. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Add admin, manager, and member access levels so user management and metrics can be role-gated without putting role claims in JWTs.
What changed
is_superuserwithUserRole(admin/manager/member), including a populated-DB Alembic backfill.require_roles(AdminUser/StaffUser); addGET /metrics/./adminand/metrics, and fixeshandleApiErrorso authz 403 no longer logs users out while inactive users do.python -m app.seed_demo_usersfor three demo accounts.Scope
Backend auth/users/items/metrics, one migration, regenerated OpenAPI client, admin/metrics UI, seed CLI. No unrelated refactors.
Tradeoffs
VARCHAR+ check constraint.is_superuserin the same wave instead of a dual-field compatibility layer.FIRST_SUPERUSER*setting names.Blast Radius
Breaking OpenAPI change (
is_superuser→role). Existing sessions keep working because tokens staysub-only and roles load from the DB each request.Verification
handleApiError.