diff --git a/selfprivacy_api/actions/users.py b/selfprivacy_api/actions/users.py index 1d337b7..95bd92c 100644 --- a/selfprivacy_api/actions/users.py +++ b/selfprivacy_api/actions/users.py @@ -63,10 +63,10 @@ def get_users( def create_user( username: str, password: Optional[str] = None, - displayname: Optional[str] = None, - email: Optional[str] = None, directmemberof: Optional[list[str]] = None, memberof: Optional[list[str]] = None, + displayname: Optional[str] = None, + email: Optional[str] = None, ) -> None: if is_username_forbidden(username): @@ -92,10 +92,10 @@ def create_user( ACTIVE_USERS_PROVIDER.create_user( username=username, password=password, - displayname=displayname, - email=email, directmemberof=directmemberof, memberof=memberof, + displayname=displayname, + email=email, ) @@ -114,19 +114,19 @@ def delete_user(username: str) -> None: def update_user( username: str, password: Optional[str] = None, - displayname: Optional[str] = None, - email: Optional[str] = None, directmemberof: Optional[list[str]] = None, memberof: Optional[list[str]] = None, + displayname: Optional[str] = None, + email: Optional[str] = None, ) -> None: ACTIVE_USERS_PROVIDER.update_user( username=username, password=password, - displayname=displayname, - email=email, directmemberof=directmemberof, memberof=memberof, + displayname=displayname, + email=email, ) diff --git a/selfprivacy_api/graphql/common_types/user.py b/selfprivacy_api/graphql/common_types/user.py index 112d1cd..4f234d9 100644 --- a/selfprivacy_api/graphql/common_types/user.py +++ b/selfprivacy_api/graphql/common_types/user.py @@ -53,12 +53,12 @@ def get_user_by_username(username: str) -> Optional[User]: return User( username=user.username, - ssh_keys=user.ssh_keys or [], - user_type=UserType(user.user_type.value) or None, - displayname=user.displayname or None, - email=user.email or None, - directmemberof=user.directmemberof or None, - memberof=user.memberof or None, + user_type=UserType(user.user_type.value), + ssh_keys=getattr(user, "ssh_keys", []), + directmemberof=getattr(user, "directmemberof", []), + memberof=getattr(user, "memberof", []), + displayname=getattr(user, "displayname", None), + email=getattr(user, "email", None), ) @@ -68,12 +68,12 @@ def get_users() -> list[User]: return [ User( username=user.username, - ssh_keys=user.ssh_keys or [], - user_type=UserType(user.user_type.value) or None, - displayname=user.displayname or None, - email=user.email or None, - directmemberof=user.directmemberof or None, - memberof=user.memberof or None, + user_type=UserType(user.user_type.value), + ssh_keys=getattr(user, "ssh_keys", []), + directmemberof=getattr(user, "directmemberof", []), + memberof=getattr(user, "memberof", []), + displayname=getattr(user, "displayname", None), + email=getattr(user, "email", None), ) for user in users ] diff --git a/selfprivacy_api/graphql/mutations/users_mutations.py b/selfprivacy_api/graphql/mutations/users_mutations.py index 83e9eaf..6604018 100644 --- a/selfprivacy_api/graphql/mutations/users_mutations.py +++ b/selfprivacy_api/graphql/mutations/users_mutations.py @@ -88,10 +88,10 @@ class UsersMutations: create_user_action( username=user.username, password=user.password, - displayname=user.displayname, - email=user.email, directmemberof=user.directmemberof, memberof=user.memberof, + displayname=user.displayname, + email=user.email, ) except ( PasswordIsEmpty, @@ -165,10 +165,10 @@ class UsersMutations: update_user_action( username=user.username, password=user.password, - displayname=user.displayname, - email=user.email, directmemberof=user.directmemberof, memberof=user.memberof, + displayname=user.displayname, + email=user.email, ) except (PasswordIsEmpty, SelfPrivacyAppIsOutdate, KanidmDidNotReturnAdminPassword) as error: return return_failed_mutation_return( diff --git a/selfprivacy_api/repositories/users/abstract_user_repository.py b/selfprivacy_api/repositories/users/abstract_user_repository.py index e6885e4..94aa359 100644 --- a/selfprivacy_api/repositories/users/abstract_user_repository.py +++ b/selfprivacy_api/repositories/users/abstract_user_repository.py @@ -10,10 +10,10 @@ class AbstractUserRepository(ABC): def create_user( username: str, password: Optional[str] = None, - displayname: Optional[str] = None, - email: Optional[str] = None, directmemberof: Optional[list[str]] = None, memberof: Optional[list[str]] = None, + displayname: Optional[str] = None, + email: Optional[str] = None, ) -> None: """ Creates a new user. In KanidmUserRepository "password" is a legacy field, @@ -41,10 +41,10 @@ class AbstractUserRepository(ABC): def update_user( username: str, password: Optional[str] = None, - displayname: Optional[str] = None, - email: Optional[str] = None, directmemberof: Optional[list[str]] = None, memberof: Optional[list[str]] = None, + displayname: Optional[str] = None, + email: Optional[str] = None, ) -> None: """ Update user information. diff --git a/selfprivacy_api/repositories/users/kanidm_user_repository.py b/selfprivacy_api/repositories/users/kanidm_user_repository.py index 5621816..f4a7125 100644 --- a/selfprivacy_api/repositories/users/kanidm_user_repository.py +++ b/selfprivacy_api/repositories/users/kanidm_user_repository.py @@ -221,13 +221,13 @@ class KanidmUserRepository(AbstractUserRepository): continue filled_user = UserDataUser( - username=user_attrs.get("name", [None]), - displayname=user_attrs.get("displayname", [None]), - email=user_attrs.get("mail", [None]), - ssh_keys=[], # actions layer will full in this field + username=user_attrs["name"], user_type=user_type, + ssh_keys=[], # actions layer will full in this field directmemberof=user_attrs.get("directmemberof", []), memberof=user_attrs.get("memberof", []), + displayname=user_attrs.get("displayname", None), + email=user_attrs.get("mail", None), ) users.append(filled_user) @@ -242,10 +242,10 @@ class KanidmUserRepository(AbstractUserRepository): def update_user( username: str, password: Optional[str] = None, - displayname: Optional[str] = None, - email: Optional[str] = None, directmemberof: Optional[list[str]] = None, memberof: Optional[list[str]] = None, + displayname: Optional[str] = None, + email: Optional[str] = None, ) -> None: """ Update user information. @@ -288,15 +288,15 @@ class KanidmUserRepository(AbstractUserRepository): attrs = user_data["attrs"] return UserDataUser( - username=attrs.get("name", [None]), - displayname=attrs.get("displayname", [None]), - email=attrs.get("mail", [None]), - ssh_keys=[], # actions layer will full in this field + username=attrs["name"], user_type=KanidmUserRepository._check_user_origin_by_memberof( memberof=attrs.get("memberof", []) ), + ssh_keys=[], # actions layer will full in this field directmemberof=attrs.get("directmemberof", []), memberof=attrs.get("memberof", []), + displayname=attrs.get("displayname", None), + email=attrs.get("mail", None), ) @staticmethod @@ -313,7 +313,7 @@ class KanidmUserRepository(AbstractUserRepository): if not data: raise KanidmReturnEmptyResponse - token = data.get("token", [None]) + token = data.get("token", None) if not token: raise KanidmReturnEmptyResponse