rename rollback

This commit is contained in:
Jörn-Michael Miehe 2022-03-29 15:39:02 +00:00
parent fdc85bf529
commit ec0f7890ef
3 changed files with 10 additions and 8 deletions

View file

@ -89,7 +89,7 @@ async def get_current_user_if_exists(
return current_user return current_user
async def current_user_is_admin( async def get_current_user_if_admin(
current_user: User = Depends(get_current_user_if_exists), current_user: User = Depends(get_current_user_if_exists),
) -> User: ) -> User:
""" """
@ -99,6 +99,8 @@ async def current_user_is_admin(
if not current_user.can(UserCapabilityType.admin): if not current_user.can(UserCapabilityType.admin):
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
return current_user
async def get_user_by_name( async def get_user_by_name(
user_name: str, user_name: str,

View file

@ -8,7 +8,7 @@ from sqlmodel import select
from ..config import Config from ..config import Config
from ..db import Connection, User, UserCapabilityType, UserCreate from ..db import Connection, User, UserCapabilityType, UserCreate
from ._common import Responses, current_user_is_admin from ._common import Responses, get_current_user_if_admin
router = APIRouter(prefix="/admin", tags=["admin"]) router = APIRouter(prefix="/admin", tags=["admin"])
@ -79,7 +79,7 @@ async def create_initial_admin(
) )
async def set_config( async def set_config(
config: Config, config: Config,
_: User = Depends(current_user_is_admin), _: User = Depends(get_current_user_if_admin),
): ):
""" """
PUT ./config: Edit `kiwi-vpn` main config. PUT ./config: Edit `kiwi-vpn` main config.

View file

@ -8,7 +8,7 @@ from pydantic import BaseModel
from ..config import Config from ..config import Config
from ..db import User, UserCapabilityType, UserCreate, UserRead from ..db import User, UserCapabilityType, UserCreate, UserRead
from ._common import (Responses, current_user_is_admin, from ._common import (Responses, get_current_user_if_admin,
get_current_user_if_exists, get_user_by_name) get_current_user_if_exists, get_user_by_name)
router = APIRouter(prefix="/user", tags=["user"]) router = APIRouter(prefix="/user", tags=["user"])
@ -81,7 +81,7 @@ async def get_current_user(
) )
async def add_user( async def add_user(
user: UserCreate, user: UserCreate,
_: User = Depends(current_user_is_admin), _: User = Depends(get_current_user_if_admin),
) -> User: ) -> User:
""" """
POST ./: Create a new user in the database. POST ./: Create a new user in the database.
@ -114,7 +114,7 @@ async def add_user(
response_model=User, response_model=User,
) )
async def remove_user( async def remove_user(
_: User = Depends(current_user_is_admin), current_user: User = Depends(get_current_user_if_admin),
user: User = Depends(get_user_by_name), user: User = Depends(get_user_by_name),
): ):
""" """
@ -140,7 +140,7 @@ async def remove_user(
) )
async def extend_capabilities( async def extend_capabilities(
capabilities: list[UserCapabilityType], capabilities: list[UserCapabilityType],
_: User = Depends(current_user_is_admin), _: User = Depends(get_current_user_if_admin),
user: User = Depends(get_user_by_name), user: User = Depends(get_user_by_name),
): ):
""" """
@ -163,7 +163,7 @@ async def extend_capabilities(
) )
async def remove_capabilities( async def remove_capabilities(
capabilities: list[UserCapabilityType], capabilities: list[UserCapabilityType],
_: User = Depends(current_user_is_admin), _: User = Depends(get_current_user_if_admin),
user: User = Depends(get_user_by_name), user: User = Depends(get_user_by_name),
): ):
""" """