Add user roles
This commit is contained in:
+11
-1
@@ -85,9 +85,19 @@ def get_current_user(authorization: Optional[str] = Header(None), db: Session =
|
||||
|
||||
def get_current_admin_user(current_user: User = Depends(get_current_user)) -> User:
|
||||
"""Get the current user and verify they are an admin"""
|
||||
if not current_user.is_admin:
|
||||
if current_user.role != "admin":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Not enough permissions. Admin access required."
|
||||
)
|
||||
return current_user
|
||||
|
||||
|
||||
def get_current_non_readonly_user(current_user: User = Depends(get_current_user)) -> User:
|
||||
"""Get the current user and verify they are not read-only"""
|
||||
if current_user.role == "readonly":
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Read-only users cannot perform this action."
|
||||
)
|
||||
return current_user
|
||||
|
||||
Reference in New Issue
Block a user