This commit is contained in:
@@ -17,6 +17,7 @@ class AccountProfile(BaseModel):
|
||||
email: str
|
||||
name: str
|
||||
role: UserRole
|
||||
permissions: list[str] = Field(default_factory=list)
|
||||
organization_id: uuid.UUID
|
||||
organization_name: str
|
||||
deleted: bool
|
||||
|
||||
@@ -6,7 +6,7 @@ from sqlmodel import Session, func, or_, select
|
||||
|
||||
from inse.auth import service as auth_service
|
||||
from inse.auth.model import AccessTokenMetadata, Account, Organization, UserRole
|
||||
from inse.auth.permissions import Permission, has_permission
|
||||
from inse.auth.permissions import Permission, get_permission_values, has_permission
|
||||
|
||||
from .model import (
|
||||
AccountPage,
|
||||
@@ -40,6 +40,7 @@ def _account_to_profile(account: Account, token: AccessTokenMetadata) -> Account
|
||||
email=account.email,
|
||||
name=account.name,
|
||||
role=account.role,
|
||||
permissions=get_permission_values(token.effective_role),
|
||||
organization_id=account.organization_id,
|
||||
organization_name=organization_name,
|
||||
deleted=account.deleted,
|
||||
|
||||
@@ -37,4 +37,8 @@ def require_permission(role: UserRole, permission: Permission) -> None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
detail="Missing permission.",
|
||||
)
|
||||
)
|
||||
|
||||
def get_permission_values(role: UserRole) -> list[str]:
|
||||
permissions = ROLE_PERMISSIONS.get(role, set())
|
||||
return [permission.value for permission in permissions]
|
||||
Reference in New Issue
Block a user