From b2a8640a2ad695f35f09d6cb823e30a4689cf405 Mon Sep 17 00:00:00 2001 From: Aurelia Date: Mon, 4 Nov 2024 18:04:04 +0100 Subject: [PATCH] Add user info rpc cmds --- .../schema/authenticated_cmds/user_info.json5 | 55 +++++++++++++++++++ .../authenticated_cmds/v4/__init__.pyi | 3 + .../authenticated_cmds/v4/user_info.pyi | 44 +++++++++++++++ server/parsec/components/user.py | 6 ++ server/tests/common/rpc.py | 5 ++ 5 files changed, 113 insertions(+) create mode 100644 libparsec/crates/protocol/schema/authenticated_cmds/user_info.json5 create mode 100644 server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/user_info.pyi diff --git a/libparsec/crates/protocol/schema/authenticated_cmds/user_info.json5 b/libparsec/crates/protocol/schema/authenticated_cmds/user_info.json5 new file mode 100644 index 00000000000..5e6f69d4df7 --- /dev/null +++ b/libparsec/crates/protocol/schema/authenticated_cmds/user_info.json5 @@ -0,0 +1,55 @@ +[ + { + "major_versions": [ + 4 + ], + "req": { + "cmd": "user_info", + "fields": [ + { + "name": "user_ids", + "type": "List" + } + ] + }, + "reps": [ + { + "status": "ok", + "fields": [ + { + "name": "user_info", + "type": "List" + } + ] + }, + { + "status": "user_not_found", + "fields": [ + { + "name": "not_found_user", + "type": "List" + } + ] + } + ], + "nested_types": [ + { + "name": "UserInfo", + "fields": [ + { + "name": "user_id", + "type": "UserID" + }, + { + "name": "human_handle", + "type": "InvitationToken" + }, + { + "name": "frozen", + "type": "Boolean" + } + ] + } + ] + } +] \ No newline at end of file diff --git a/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/__init__.pyi b/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/__init__.pyi index 366a8e649a8..259789f77b7 100644 --- a/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/__init__.pyi +++ b/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/__init__.pyi @@ -30,6 +30,7 @@ from . import ( realm_unshare, shamir_recovery_setup, user_create, + user_info, user_revoke, user_update, vlob_create, @@ -69,6 +70,7 @@ class AnyCmdReq: | realm_unshare.Req | shamir_recovery_setup.Req | user_create.Req + | user_info.Req | user_revoke.Req | user_update.Req | vlob_create.Req @@ -105,6 +107,7 @@ __all__ = [ "realm_unshare", "shamir_recovery_setup", "user_create", + "user_info", "user_revoke", "user_update", "vlob_create", diff --git a/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/user_info.pyi b/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/user_info.pyi new file mode 100644 index 00000000000..c433f8bc62c --- /dev/null +++ b/server/parsec/_parsec_pyi/protocol/authenticated_cmds/v4/user_info.pyi @@ -0,0 +1,44 @@ +# Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS + +# /!\ Autogenerated by misc/gen_protocol_typings.py, any modification will be lost ! + +from __future__ import annotations + +from parsec._parsec import InvitationToken, UserID + +class UserInfo: + def __init__(self, user_id: UserID, human_handle: InvitationToken, frozen: bool) -> None: ... + @property + def frozen(self) -> bool: ... + @property + def human_handle(self) -> InvitationToken: ... + @property + def user_id(self) -> UserID: ... + +class Req: + def __init__(self, user_ids: list[UserID]) -> None: ... + def dump(self) -> bytes: ... + @property + def user_ids(self) -> list[UserID]: ... + +class Rep: + @staticmethod + def load(raw: bytes) -> Rep: ... + def dump(self) -> bytes: ... + +class RepUnknownStatus(Rep): + def __init__(self, status: str, reason: str | None) -> None: ... + @property + def status(self) -> str: ... + @property + def reason(self) -> str | None: ... + +class RepOk(Rep): + def __init__(self, user_info: list[UserInfo]) -> None: ... + @property + def user_info(self) -> list[UserInfo]: ... + +class RepUserNotFound(Rep): + def __init__(self, not_found_user: list[UserID]) -> None: ... + @property + def not_found_user(self) -> list[UserID]: ... diff --git a/server/parsec/components/user.py b/server/parsec/components/user.py index 907a253fd4b..95b6d0d1a03 100644 --- a/server/parsec/components/user.py +++ b/server/parsec/components/user.py @@ -698,3 +698,9 @@ async def api_tos_accept( return tos_cmds.latest.tos_accept.RepNoTos() case UserAcceptTosBadOutcome.TOS_MISMATCH: return tos_cmds.latest.tos_accept.RepTosMismatch() + + @api + async def api_get_user_info( + self, client_ctx: AuthenticatedClientContext, req: authenticated_cmds.latest.user_info.Req + ) -> authenticated_cmds.latest.user_info.Rep: + pass diff --git a/server/tests/common/rpc.py b/server/tests/common/rpc.py index 019f5145807..dde4018600d 100644 --- a/server/tests/common/rpc.py +++ b/server/tests/common/rpc.py @@ -324,6 +324,11 @@ async def user_create( raw_rep = await self._do_request(req.dump(), "authenticated") return authenticated_cmds.latest.user_create.Rep.load(raw_rep) + async def user_info(self, user_ids: list[UserID]) -> authenticated_cmds.latest.user_info.Rep: + req = authenticated_cmds.latest.user_info.Req(user_ids=user_ids) + raw_rep = await self._do_request(req.dump(), "authenticated") + return authenticated_cmds.latest.user_info.Rep.load(raw_rep) + async def user_revoke( self, revoked_user_certificate: bytes ) -> authenticated_cmds.latest.user_revoke.Rep: