Skip to content

Commit

Permalink
fix endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
eelcovdw committed May 21, 2024
1 parent fc10f66 commit 8cdf60d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/syft/src/syft/service/code/user_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 18 additions & 1 deletion packages/syft/src/syft/service/user/user_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8cdf60d

Please sign in to comment.