from ..dependencies import users_token from fastapi import Depends, HTTPException, status from ..models import users class PermissionChecker: def __init__(self, roles: list[str]) -> None: self.roles = roles def __call__(self, user: users.User = Depends(users_token.get_current_active_user)) -> bool: for role in self.roles: if role == user.roles: return True raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail='Roles unauthorized' )