makefile 1.1 and permissions 1.0

This commit is contained in:
2025-10-05 02:09:28 +03:00
parent 46c6e1cd94
commit 6db14b2329
6 changed files with 119 additions and 15 deletions

View File

@@ -63,6 +63,7 @@ async def delete_user(email:str,current_user: str = Depends(JWT.current_user)):
@api.put("/user_update/{email}", response_model=pydentic.UserOut)
async def update_user(email:str, updated_row: pydentic.UserUpdate, current_user: str = Depends(JWT.current_user)):
user = await db.get_user_by_email(email)
perm = user.permissions[0]
if not user:
raise HTTPException(status_code=401, detail="The user isn't found")
changed = False
@@ -78,8 +79,14 @@ async def update_user(email:str, updated_row: pydentic.UserUpdate, current_user:
if updated_row.password is not None and updated_row.password != user.password:
user.password = updated_row.password
changed = True
if updated_row.can_edit is not None and updated_row.can_edit != perm.can_edit:
perm.can_edit = updated_row.can_edit
changed = True
if updated_row.can_delete is not None and updated_row.can_delete != perm.can_delete:
perm.can_delete = updated_row.can_delete
changed = True
if changed:
await db.update_user(user)
user = await db.update_user(user_info=user, perm_info=perm)
else:
pass
return user

View File

@@ -32,6 +32,8 @@ class UserUpdate(BaseModel):
description:Optional[str] = Field(None, description="description of the user")
activated:Optional[bool] = Field(None, description="Has the user activated their account")
password:Optional[constr(min_length=8)] = Field(None, description="Password with min 8 chars, letters and digits")
can_edit:Optional[bool] = Field(None, description="The user can edit something")
can_delete:Optional[bool] = Field(None, description="The user can delete something")
@validator('password')
def password_validator(cls, password):
return check_password_complexity(cls, password)