From 8cdf60de4de920bb8b85ffb94d66e965fe5c45fa Mon Sep 17 00:00:00 2001 From: eelcovdw Date: Tue, 21 May 2024 11:03:43 +0200 Subject: [PATCH 1/2] 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) From 4ee91e99c239d4a86698085a48e90ee01fb52603 Mon Sep 17 00:00:00 2001 From: Aziz Berkay Yesilyurt Date: Tue, 21 May 2024 14:44:06 +0200 Subject: [PATCH 2/2] Update request message to indicate function name Closes https://github.com/OpenMined/Heartbeat/issues/1343 --- packages/syft/src/syft/service/request/request.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/syft/src/syft/service/request/request.py b/packages/syft/src/syft/service/request/request.py index 889491278e8..88f035de0bb 100644 --- a/packages/syft/src/syft/service/request/request.py +++ b/packages/syft/src/syft/service/request/request.py @@ -570,11 +570,14 @@ def approve( ) if message and metadata and metadata.show_warnings and not disable_warnings: prompt_warning_message(message=message, confirm=True) + msg = ( + "Approving request ", + f"on change {self.code.service_func_name} " if is_code_request else "", + f"for domain {api.node_name}", + ) - print(f"Approving request for domain {api.node_name}") + print("".join(msg)) res = api.services.request.apply(self.id, **kwargs) - # if isinstance(res, SyftSuccess): - return res def deny(self, reason: str) -> SyftSuccess | SyftError: