permissions added
This commit is contained in:
@@ -49,7 +49,7 @@ class CurrentUserService:
|
||||
)
|
||||
|
||||
|
||||
async def get_current_user(self, token:str)->UserOut:
|
||||
async def get_current_user(self, token:str, *permissions: str)->UserOut:
|
||||
|
||||
payload= await self.jwt_service.jwt_decode(token)
|
||||
sub=payload.get("sub")
|
||||
@@ -69,6 +69,12 @@ class CurrentUserService:
|
||||
if user.status is False:
|
||||
raise self.error.credentials_error(detail="This user is deactivated")
|
||||
|
||||
effective = {p.permission for p in user.direct_permissions} | {p.permission for group in user.group for p in group.permissions}
|
||||
missing = set(permissions) - effective
|
||||
|
||||
if missing:
|
||||
raise self.error.forbidden_error(detail=f"Missing: {missing}")
|
||||
|
||||
return UserOut.model_validate(user)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user