diff --git a/app/models/users.py b/app/models/users.py index bacfa46..9d71f9d 100644 --- a/app/models/users.py +++ b/app/models/users.py @@ -46,6 +46,9 @@ class UserCreate(BaseModel): class UserInDB(User): password: str +class UserIDS(BaseModel): + ids: list[str] + class UserRepository(AbstractRepository[User]): class Meta: collection_name = "users" \ No newline at end of file diff --git a/app/routers/users.py b/app/routers/users.py index afd8d89..515c710 100644 --- a/app/routers/users.py +++ b/app/routers/users.py @@ -104,22 +104,22 @@ async def delete_users_me(current_user: Annotated[users.User, Depends(users_toke return current_user @router.delete("/users/groups",tags=["users"]) -async def delete_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], remove: bool = False, userids: list[str] = []): - if len(userids) == 0: +async def delete_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], remove: bool = False, userids: users.UserIDS | None = None): + if len(userids.ids) == 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 disabled"} - for i in userids: + content = {"message": "users are disabled"} + for i in userids.ids: user = user_repository.find_one_by_id(ObjectId(i)) user.status = 0 if remove is True: user.status = -1 - content = {"roles":user.roles,"message": "users are deleted "} - user_repository.save(current_user) + content = {"message": "users are deleted "} + user_repository.save(user) response = JSONResponse(content=content) @@ -172,19 +172,19 @@ async def update_users_id(authorize: Annotated[bool, Depends(permissions_checker @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: +async def patch_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userids: users.UserIDS | None = None): + if len(userids.ids) == 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: + content = {"message": "users are enabled"} + for i in userids.ids: user = user_repository.find_one_by_id(ObjectId(i)) user.status = 1 - user_repository.save(current_user) + user_repository.save(user) response = JSONResponse(content=content)