Skip to content

Commit

Permalink
Make front/back integration better
Browse files Browse the repository at this point in the history
  • Loading branch information
mekanix committed Apr 15, 2024
1 parent 4a626d8 commit 86a481b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion freenit/api/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def get(id, _: User = Depends(role_perms)) -> RoleSafe:
await role.load_all(follow=True)
return role
elif Role.dbtype() == "bonsai":
role = Role.get(id)
role = await Role.get(id)
return role
raise HTTPException(status_code=409, detail="Unknown role type")

Expand Down
21 changes: 15 additions & 6 deletions freenit/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,25 @@ class ProfileDetailAPI:
@staticmethod
@description("Get my profile")
async def get(user: User = Depends(profile_perms)) -> UserSafe:
await user.load_all()
if User.dbtype() == "ormar":
await user.load_all()
return user

@staticmethod
@description("Edit my profile")
async def patch(
data: UserOptional, user: User = Depends(profile_perms)
) -> UserSafe:
if data.password:
data.password = encrypt(data.password)
await user.patch(data)
await user.load_all()
return user
if User.dbtype() == "ormar":
if data.password:
data.password = encrypt(data.password)
await user.patch(data)
await user.load_all()
return user
elif User.dbtype() == "bonsai":
update = {
field: getattr(data, field) for field in data.__fields__ if getattr(data, field) != ''
}
await user.update(active=user.userClass, **update)
return user
raise HTTPException(status_code=409, detail="Unknown user type")
7 changes: 5 additions & 2 deletions freenit/models/ldap/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ async def get(cls, dn):
raise HTTPException(status_code=404, detail="No such user")
if len(res) > 1:
raise HTTPException(status_code=409, detail="Multiple users found")
print(res)
data = res[0]
user = cls(
email=data["mail"][0],
Expand All @@ -47,7 +46,7 @@ async def get(cls, dn):
dn=str(data["dn"]),
uid=data["uid"][0],
userClass=data["userClass"][0],
roles=data["memberOf"],
roles=data.get("memberOf", []),
)
return user

Expand Down Expand Up @@ -107,7 +106,11 @@ async def get_all(cls):
dn=str(udata["dn"]),
uid=udata["uid"][0],
userClass=udata["userClass"][0],
<<<<<<< HEAD
roles=data["memberOf"],
=======
roles=udata.get("memberOf", []),
>>>>>>> 1243228 (Make front/back integration better)
)
data.append(user)
return data
Expand Down

0 comments on commit 86a481b

Please sign in to comment.