From e76de17ff5031f8e8f007cce75cab511982c51ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Tue, 15 Mar 2022 17:38:31 +0000 Subject: [PATCH] check user is admin --- api/kiwi_vpn_api/routers/user.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/kiwi_vpn_api/routers/user.py b/api/kiwi_vpn_api/routers/user.py index 50db0e7..8a96b89 100644 --- a/api/kiwi_vpn_api/routers/user.py +++ b/api/kiwi_vpn_api/routers/user.py @@ -49,6 +49,15 @@ async def get_current_user(token: str = Depends(SCHEME)): return user -@router.get("/current", response_model=User) +@router.get("/current_user/get", response_model=User) async def get_current_user(current_user: User = Depends(get_current_user)): return current_user + + +async def is_admin(current_user: User = Depends(get_current_user)): + return ("admin" in current_user.capabilities) + + +@router.get("/current_user/is_admin") +async def current_user_is_admin(is_admin: bool = Depends(is_admin)): + return {"is_admin": is_admin}