add enable and remove groups
This commit is contained in:
parent
a279439e72
commit
753f4ee087
@ -46,6 +46,9 @@ class UserCreate(BaseModel):
|
|||||||
class UserInDB(User):
|
class UserInDB(User):
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
class UserIDS(BaseModel):
|
||||||
|
ids: list[str]
|
||||||
|
|
||||||
class UserRepository(AbstractRepository[User]):
|
class UserRepository(AbstractRepository[User]):
|
||||||
class Meta:
|
class Meta:
|
||||||
collection_name = "users"
|
collection_name = "users"
|
@ -104,22 +104,22 @@ async def delete_users_me(current_user: Annotated[users.User, Depends(users_toke
|
|||||||
return current_user
|
return current_user
|
||||||
|
|
||||||
@router.delete("/users/groups",tags=["users"])
|
@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] = []):
|
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) == 0:
|
if len(userids.ids) == 0:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail="userids should be greater than 0"
|
detail="userids should be greater than 0"
|
||||||
)
|
)
|
||||||
|
|
||||||
user_repository = users.UserRepository(database=database.database)
|
user_repository = users.UserRepository(database=database.database)
|
||||||
content = {"roles":user.roles,"message": "users are disabled"}
|
content = {"message": "users are disabled"}
|
||||||
for i in userids:
|
for i in userids.ids:
|
||||||
user = user_repository.find_one_by_id(ObjectId(i))
|
user = user_repository.find_one_by_id(ObjectId(i))
|
||||||
user.status = 0
|
user.status = 0
|
||||||
if remove is True:
|
if remove is True:
|
||||||
user.status = -1
|
user.status = -1
|
||||||
content = {"roles":user.roles,"message": "users are deleted "}
|
content = {"message": "users are deleted "}
|
||||||
user_repository.save(current_user)
|
user_repository.save(user)
|
||||||
|
|
||||||
|
|
||||||
response = JSONResponse(content=content)
|
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"])
|
@router.patch("/users/groups",tags=["users"])
|
||||||
async def patch_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userids: list[str] = []):
|
async def patch_users_groups(authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))], userids: users.UserIDS | None = None):
|
||||||
if len(userids) == 0:
|
if len(userids.ids) == 0:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_400_BAD_REQUEST,
|
status_code=status.HTTP_400_BAD_REQUEST,
|
||||||
detail="userids should be greater than 0"
|
detail="userids should be greater than 0"
|
||||||
)
|
)
|
||||||
|
|
||||||
user_repository = users.UserRepository(database=database.database)
|
user_repository = users.UserRepository(database=database.database)
|
||||||
content = {"roles":user.roles,"message": "users are enabled"}
|
content = {"message": "users are enabled"}
|
||||||
for i in userids:
|
for i in userids.ids:
|
||||||
user = user_repository.find_one_by_id(ObjectId(i))
|
user = user_repository.find_one_by_id(ObjectId(i))
|
||||||
user.status = 1
|
user.status = 1
|
||||||
user_repository.save(current_user)
|
user_repository.save(user)
|
||||||
|
|
||||||
|
|
||||||
response = JSONResponse(content=content)
|
response = JSONResponse(content=content)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user