From 2546763b03aa68ce2e1dde0240cb3db88b08d64a Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 31 Oct 2023 18:02:24 +0100 Subject: [PATCH] add method patch enable --- app/routers/users.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/routers/users.py b/app/routers/users.py index 325db86..e6e0fab 100644 --- a/app/routers/users.py +++ b/app/routers/users.py @@ -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 \ No newline at end of file + 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 \ No newline at end of file