add method patch enable
This commit is contained in:
parent
1286f0a3f2
commit
2546763b03
@ -176,3 +176,22 @@ async def patch_users_id(item_id : str, authorize: Annotated[bool, Depends(permi
|
|||||||
user.status = 1
|
user.status = 1
|
||||||
user_repository.save(user)
|
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
|
Loading…
x
Reference in New Issue
Block a user