add method patch enable

This commit is contained in:
Valentin CZERYBA 2023-10-31 18:02:24 +01:00
parent 1286f0a3f2
commit 2546763b03

View File

@ -175,4 +175,23 @@ async def patch_users_id(item_id : str, authorize: Annotated[bool, Depends(permi
user = user_repository.find_one_by_id(ObjectId(item_id))
user.status = 1
user_repository.save(user)
return user
return user
@router.patch("/users/groups",tags=["users"])
async def patch_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userids: list[str] = []):
if len(userids) == 0:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="userids should be greater than 0"
)
user_repository = users.UserRepository(database=database.database)
content = {"roles":user.roles,"message": "users are enabled"}
for i in userids:
user = user_repository.find_one_by_id(ObjectId(i))
user.status = 1
user_repository.save(current_user)
response = JSONResponse(content=content)
return response