diff --git a/freenit/api/role.py b/freenit/api/role.py index ff3b650..698e52c 100644 --- a/freenit/api/role.py +++ b/freenit/api/role.py @@ -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") diff --git a/freenit/api/user.py b/freenit/api/user.py index df5782a..7ec3b9e 100644 --- a/freenit/api/user.py +++ b/freenit/api/user.py @@ -118,7 +118,8 @@ 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 @@ -126,8 +127,16 @@ async def get(user: User = Depends(profile_perms)) -> UserSafe: 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") diff --git a/freenit/models/ldap/user.py b/freenit/models/ldap/user.py index 9c260f0..38463ee 100644 --- a/freenit/models/ldap/user.py +++ b/freenit/models/ldap/user.py @@ -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], @@ -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 @@ -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