From 8cdf60de4de920bb8b85ffb94d66e965fe5c45fa Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Tue, 21 May 2024 11:03:43 +0200 Subject: [PATCH] fix endpoint --- .../syft/src/syft/service/code/user_code.py | 4 ++-- .../src/syft/service/user/user_service.py | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/code/user_code.py b/packages/syft/src/syft/service/code/user_code.py index c779037a6c9..604e21611f4 100644 --- a/packages/syft/src/syft/service/code/user_code.py +++ b/packages/syft/src/syft/service/code/user_code.py @@ -353,13 +353,13 @@ def _coll_repr_(self) -> dict[str, Any]: def user(self) -> UserView | SyftError: api = APIRegistry.api_for( node_uid=self.syft_node_location, - user_verify_key=self.user_verify_key, + user_verify_key=self.syft_client_verify_key, ) if api is None: return SyftError( message=f"Can't access Syft API. You must login to {self.syft_node_location}" ) - return api.services.user.get_current_user() + return api.services.user.get_by_verify_key(self.user_verify_key) @property def status(self) -> UserCodeStatusCollection | SyftError: diff --git a/packages/syft/src/syft/service/user/user_service.py b/packages/syft/src/syft/service/user/user_service.py index 6da986426c3..63425f90103 100644 --- a/packages/syft/src/syft/service/user/user_service.py +++ b/packages/syft/src/syft/service/user/user_service.py @@ -37,6 +37,7 @@ from .user import UserViewPage from .user import check_pwd from .user import salt_and_hash_password +from .user_roles import ADMIN_ROLE_LEVEL from .user_roles import DATA_OWNER_ROLE_LEVEL from .user_roles import DATA_SCIENTIST_ROLE_LEVEL from .user_roles import GUEST_ROLE_LEVEL @@ -220,7 +221,23 @@ def get_current_user(self, context: AuthedServiceContext) -> UserView | SyftErro credentials=context.credentials, verify_key=context.credentials ) if result.is_ok(): - # this seems weird that we get back None as Ok(None) + user = result.ok() + if user: + return user.to(UserView) + else: + SyftError(message="User not found!") + return SyftError(message=str(result.err())) + + @service_method( + path="user.get_by_verify_key", name="get_by_verify_key", roles=ADMIN_ROLE_LEVEL + ) + def get_by_verify_key_endpoint( + self, context: AuthedServiceContext, verify_key: SyftVerifyKey + ) -> UserView | SyftError: + result = self.stash.get_by_verify_key( + credentials=context.credentials, verify_key=verify_key + ) + if result.is_ok(): user = result.ok() if user: return user.to(UserView)