feat: add role-based admin support for multiple admin users
- Add Role model and user_roles association table (many-to-many) - Add password_hash column to User model (nullable, for future bcrypt) - Keep is_admin boolean for backward compatibility - Add is_admin_effective property: true if legacy is_admin OR 'admin' role - Update auth dependency (get_current_admin_user) to use is_admin_effective - Update bootstrap login to auto-create 'admin' role and assign on login - Update Google OAuth login to use is_admin_effective for token creation - Add migrate_roles.py: idempotent migration script to backfill roles - Add unit tests for Role, User, association table, and is_admin_effective
This commit is contained in:
+5
-2
@@ -98,8 +98,11 @@ async def get_current_user(
|
||||
async def get_current_admin_user(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> User:
|
||||
"""Raise 403 if the current user is not an admin."""
|
||||
if not current_user.is_admin:
|
||||
"""Raise 403 if the current user is not an admin.
|
||||
|
||||
Checks both the legacy is_admin flag and the new role-based admin role.
|
||||
"""
|
||||
if not current_user.is_admin_effective:
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail="Admin access required")
|
||||
return current_user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user