21 lines
1.0 KiB
Python
21 lines
1.0 KiB
Python
from fastapi import APIRouter, Depends
|
|
from ..dependencies import users_active, permissions_checker, database
|
|
from ..models import users
|
|
from typing import Annotated
|
|
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/users", tags=["users"], response_model=list[users.UserOut])
|
|
async def read_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
|
listUsers = []
|
|
user_repository = users.UserRepository(database=database.database)
|
|
for fake in user_repository.find_by({}):
|
|
print(fake)
|
|
user = users.UserOut(id=fake.id, username=fake.username, disabled=fake.disabled, roles=fake.roles)
|
|
listUsers.append(user)
|
|
return listUsers
|
|
|
|
@router.get("/users/me",tags=["users"], response_model=users.User, response_model_exclude=["password"])
|
|
async def read_users_me(current_user: Annotated[users.User, Depends(users_active.get_current_active_user)], authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))]):
|
|
return current_user |