class UsersOut
This commit is contained in:
parent
95cfa7ff57
commit
86eb1dd4e5
@ -8,5 +8,11 @@ class User(BaseModel):
|
|||||||
roles: str
|
roles: str
|
||||||
disabled: bool
|
disabled: bool
|
||||||
|
|
||||||
|
class UserOut(BaseModel):
|
||||||
|
id: int
|
||||||
|
username: str
|
||||||
|
roles: str
|
||||||
|
disabled: bool
|
||||||
|
|
||||||
class UserInDB(User):
|
class UserInDB(User):
|
||||||
password: str
|
password: str
|
@ -6,10 +6,14 @@ from typing import Annotated
|
|||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
@router.get("/users/", tags=["users"], response_model=list[users.User])
|
@router.get("/users/", tags=["users"], response_model=list[users.UserOut])
|
||||||
async def read_users(current_user: Annotated[users.User, Depends(users_active.get_current_active_user)], authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
async def read_users(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
||||||
return users_active.fake_users
|
listUsers = []
|
||||||
|
for fake in users_active.fake_users:
|
||||||
|
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)
|
@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"]))]):
|
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
|
return current_user
|
Loading…
x
Reference in New Issue
Block a user