|
1 | 1 | from datetime import datetime, timedelta, UTC
|
2 |
| -from typing import Optional, Literal, Dict |
| 2 | +from typing import Optional |
3 | 3 | from jose import JWTError, jwt
|
4 | 4 | from passlib.context import CryptContext
|
5 | 5 | from fastapi import Depends, HTTPException, status, Cookie, Header, Request
|
|
9 | 9 | from app.db.database import get_db
|
10 | 10 | from sqlalchemy.orm import Session
|
11 | 11 | from app.db.models import DBUser, DBAPIToken
|
12 |
| -from app.core.roles import UserRole as RoleClass |
13 | 12 | from app.core.rbac import (
|
14 | 13 | require_system_admin,
|
15 | 14 | require_team_admin,
|
16 | 15 | require_key_creator_or_higher,
|
17 |
| - require_read_only_or_higher, |
18 | 16 | require_sales_or_higher,
|
19 |
| - require_any_role |
20 | 17 | )
|
21 | 18 |
|
22 | 19 | logger = logging.getLogger(__name__)
|
|
27 | 24 | # Custom bearer scheme
|
28 | 25 | bearer_scheme = HTTPBearer(auto_error=False)
|
29 | 26 |
|
30 |
| -# Define valid user roles as a Literal type - MUST match existing values exactly |
31 |
| -UserRole = Literal["admin", "key_creator", "read_only", "user", "system_admin", "sales"] |
32 |
| - |
33 |
| -# Define a hierarchy for roles - updated to include new roles |
34 |
| -user_role_hierarchy: Dict[UserRole, int] = { |
35 |
| - "system_admin": 0, |
36 |
| - "admin": 1, |
37 |
| - "user": 2, |
38 |
| - "key_creator": 3, |
39 |
| - "read_only": 4, |
40 |
| - "sales": 5, |
41 |
| -} |
42 |
| - |
43 | 27 | def verify_password(plain_password: str, hashed_password: str) -> bool:
|
44 | 28 | """Verify a password against its hash."""
|
45 | 29 | return pwd_context.verify(plain_password, hashed_password)
|
@@ -152,16 +136,6 @@ async def check_system_admin(current_user: DBUser = Depends(get_current_user_fro
|
152 | 136 | dependency = require_system_admin()
|
153 | 137 | return dependency.check_access(current_user)
|
154 | 138 |
|
155 |
| -def get_user_role(minimum_role: UserRole, current_user: DBUser): |
156 |
| - if current_user.is_admin: |
157 |
| - return "system_admin" |
158 |
| - elif user_role_hierarchy[current_user.role] > user_role_hierarchy[minimum_role]: |
159 |
| - raise HTTPException( |
160 |
| - status_code=status.HTTP_403_FORBIDDEN, |
161 |
| - detail="Not authorized to perform this action" |
162 |
| - ) |
163 |
| - return current_user.role |
164 |
| - |
165 | 139 | async def get_role_min_team_admin(current_user: DBUser = Depends(get_current_user_from_auth)):
|
166 | 140 | """Require team admin role or higher."""
|
167 | 141 | dependency = require_team_admin()
|
|
0 commit comments