Skip to content

Commit d185823

Browse files
authored
Merge pull request #8846 from OpenMined/eelco/sync-table-fixes
fix user endpoint for usercode
2 parents 8a28ad6 + 0af9838 commit d185823

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

packages/syft/src/syft/service/code/user_code.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,13 @@ def _coll_repr_(self) -> dict[str, Any]:
353353
def user(self) -> UserView | SyftError:
354354
api = APIRegistry.api_for(
355355
node_uid=self.syft_node_location,
356-
user_verify_key=self.user_verify_key,
356+
user_verify_key=self.syft_client_verify_key,
357357
)
358358
if api is None:
359359
return SyftError(
360360
message=f"Can't access Syft API. You must login to {self.syft_node_location}"
361361
)
362-
return api.services.user.get_current_user()
362+
return api.services.user.get_by_verify_key(self.user_verify_key)
363363

364364
@property
365365
def status(self) -> UserCodeStatusCollection | SyftError:

packages/syft/src/syft/service/user/user_service.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from .user import UserViewPage
3838
from .user import check_pwd
3939
from .user import salt_and_hash_password
40+
from .user_roles import ADMIN_ROLE_LEVEL
4041
from .user_roles import DATA_OWNER_ROLE_LEVEL
4142
from .user_roles import DATA_SCIENTIST_ROLE_LEVEL
4243
from .user_roles import GUEST_ROLE_LEVEL
@@ -220,7 +221,23 @@ def get_current_user(self, context: AuthedServiceContext) -> UserView | SyftErro
220221
credentials=context.credentials, verify_key=context.credentials
221222
)
222223
if result.is_ok():
223-
# this seems weird that we get back None as Ok(None)
224+
user = result.ok()
225+
if user:
226+
return user.to(UserView)
227+
else:
228+
SyftError(message="User not found!")
229+
return SyftError(message=str(result.err()))
230+
231+
@service_method(
232+
path="user.get_by_verify_key", name="get_by_verify_key", roles=ADMIN_ROLE_LEVEL
233+
)
234+
def get_by_verify_key_endpoint(
235+
self, context: AuthedServiceContext, verify_key: SyftVerifyKey
236+
) -> UserView | SyftError:
237+
result = self.stash.get_by_verify_key(
238+
credentials=context.credentials, verify_key=verify_key
239+
)
240+
if result.is_ok():
224241
user = result.ok()
225242
if user:
226243
return user.to(UserView)

0 commit comments

Comments
 (0)