Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix user endpoint for usercode #8846

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading