mirror of
https://github.com/cssgunc/compass.git
synced 2025-04-09 14:00:15 -04:00
resource service and permissions service wip
This commit is contained in:
parent
31b714e70d
commit
e8068ff2ea
37
backend/services/permissions.py
Normal file
37
backend/services/permissions.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
from fastapi import Depends
|
||||||
|
from ..database import db_session
|
||||||
|
from sqlalchemy.orm import Session
|
||||||
|
|
||||||
|
from ..models.user_model import User
|
||||||
|
from ..entities.user_entity import UserEntity
|
||||||
|
from exceptions import ResourceNotFoundException, UserPermissionException
|
||||||
|
from ..models.enum_for_models import UserTypeEnum
|
||||||
|
|
||||||
|
|
||||||
|
class PermissionsService:
|
||||||
|
|
||||||
|
def __init__(self, session: Session = Depends(db_session)):
|
||||||
|
self._session = session
|
||||||
|
|
||||||
|
def get_role_permissions(self, user: User) -> str:
|
||||||
|
"""
|
||||||
|
Gets a str group based on the user
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Query the resource table with id
|
||||||
|
obj = (
|
||||||
|
self._session.query(UserEntity)
|
||||||
|
.filter(UserEntity.id == user.id)
|
||||||
|
.one_or_none()
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if result is null
|
||||||
|
if obj is None:
|
||||||
|
raise ResourceNotFoundException(
|
||||||
|
f"No user permissions found for user with id: {user.id}"
|
||||||
|
)
|
||||||
|
|
||||||
|
return obj.role
|
Loading…
Reference in New Issue
Block a user