Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
🐛 Fix order of path operations, it matters
Browse files Browse the repository at this point in the history
  • Loading branch information
tiangolo committed Jan 12, 2019
1 parent aa74e3d commit 4e5399d
Showing 1 changed file with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,34 +92,6 @@ def route_users_post(
return user


@router.put("/users/{username}", tags=["users"], response_model=User)
def route_users_put(
*,
username: str,
user_in: UserInUpdate,
current_user: UserInDB = Depends(get_current_user),
):
"""
Update a user
"""
if not check_if_user_is_active(current_user):
raise HTTPException(status_code=400, detail="Inactive user")
elif not check_if_user_is_superuser(current_user):
raise HTTPException(
status_code=400, detail="The user doesn't have enough privileges"
)
bucket = get_default_bucket()
user = get_user(bucket, username)

if not user:
raise HTTPException(
status_code=404,
detail="The user with this username does not exist in the system",
)
user = update_user(bucket, user_in)
return user


@router.put("/users/me", tags=["users"], response_model=User)
def route_users_me_put(
*,
Expand Down Expand Up @@ -155,6 +127,36 @@ def route_users_me_get(current_user: UserInDB = Depends(get_current_user)):
return current_user


@router.post("/users/open", tags=["users"], response_model=User)
def route_users_post_open(
*,
username: str = Body(...),
password: str = Body(...),
email: EmailStr = Body(None),
full_name: str = Body(None),
):
"""
Create new user without the need to be logged in
"""
if not config.USERS_OPEN_REGISTRATION:
raise HTTPException(
status_code=403,
detail="Open user resgistration is forbidden on this server",
)
bucket = get_default_bucket()
user = get_user(bucket, username)
if user:
raise HTTPException(
status_code=400,
detail="The user with this username already exists in the system",
)
user_in = UserInCreate(
username=username, password=password, email=email, full_name=full_name
)
user = upsert_user(bucket, user_in, persist_to=1)
return user


@router.get("/users/{username}", tags=["users"], response_model=User)
def route_users_id_get(
username: str, current_user: UserInDB = Depends(get_current_user)
Expand All @@ -175,31 +177,29 @@ def route_users_id_get(
return user


@router.post("/users/open", tags=["users"], response_model=User)
def route_users_post_open(
@router.put("/users/{username}", tags=["users"], response_model=User)
def route_users_put(
*,
username: str = Body(...),
password: str = Body(...),
email: EmailStr = Body(None),
full_name: str = Body(None),
username: str,
user_in: UserInUpdate,
current_user: UserInDB = Depends(get_current_user),
):
"""
Create new user without the need to be logged in
Update a user
"""
if not config.USERS_OPEN_REGISTRATION:
if not check_if_user_is_active(current_user):
raise HTTPException(status_code=400, detail="Inactive user")
elif not check_if_user_is_superuser(current_user):
raise HTTPException(
status_code=403,
detail="Open user resgistration is forbidden on this server",
status_code=400, detail="The user doesn't have enough privileges"
)
bucket = get_default_bucket()
user = get_user(bucket, username)
if user:

if not user:
raise HTTPException(
status_code=400,
detail="The user with this username already exists in the system",
status_code=404,
detail="The user with this username does not exist in the system",
)
user_in = UserInCreate(
username=username, password=password, email=email, full_name=full_name
)
user = upsert_user(bucket, user_in, persist_to=1)
user = update_user(bucket, user_in)
return user

0 comments on commit 4e5399d

Please sign in to comment.