add method group method
This commit is contained in:
parent
af4af31e26
commit
6cc12e0535
@ -103,6 +103,26 @@ async def delete_users_me(current_user: Annotated[users.User, Depends(users_toke
|
||||
user_repository.save(current_user)
|
||||
return current_user
|
||||
|
||||
@router.delete("/users/groups",tags=["users"])
|
||||
async def delete_users_groups(current_user: Annotated[users.User, Depends(users_token.get_current_active_user)], authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin", "User"]))], remove: bool = False, 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)
|
||||
for i in userids:
|
||||
user = user_repository.find_one_by_id(ObjectId(i))
|
||||
user.status = 0
|
||||
if remove is True:
|
||||
user.status = -1
|
||||
user_repository.save(current_user)
|
||||
|
||||
content = {"roles":user.roles,"message": "Access token generated"}
|
||||
response = JSONResponse(content=content)
|
||||
return response
|
||||
|
||||
@router.delete("/users/{item_id}", tags=["users"], response_model=users.User)
|
||||
async def delete_users_id(item_id : str, authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], remove : bool = False):
|
||||
user_repository = users.UserRepository(database=database.database)
|
||||
|
Loading…
x
Reference in New Issue
Block a user