Skip to content

Commit

Permalink
Replace UserOrDevice with InvitationType
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Nov 25, 2024
1 parent 9a5a348 commit 5840cd7
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions docs/rfcs/1000-shamir-based-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ Authenticated API for creating the invitation:
],
"req": {
"cmd": "invite_new",
"unit": "UserOrDeviceOrShamirRecovery"
"unit": "InvitationType"
},
"reps": [
{
Expand Down Expand Up @@ -435,7 +435,7 @@ Authenticated API for creating the invitation:
],
"nested_types": [
{
"name": "UserOrDeviceOrShamirRecovery",
"name": "InvitationType",
"discriminant_field": "type",
"variants": [
{
Expand Down Expand Up @@ -535,12 +535,12 @@ Invited API, we reuse the `invite_info` command:
"reps": [
{
"status": "ok",
"unit": "UserOrDeviceOrShamirRecovery"
"unit": "InvitationType"
}
],
"nested_types": [
{
"name": "UserOrDeviceOrShamirRecovery",
"name": "InvitationType",
"discriminant_field": "type",
"variants": [
// <-------------- User variant omitted --------->
Expand Down
8 changes: 4 additions & 4 deletions libparsec/crates/client/src/invite/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ pub async fn claimer_retrieve_info(
addr: ParsecInvitationAddr,
time_provider: Option<TimeProvider>,
) -> Result<UserOrDeviceClaimInitialCtx, ClaimerRetrieveInfoError> {
use invited_cmds::latest::invite_info::{Rep, Req, UserOrDevice};
use invited_cmds::latest::invite_info::{InvitationType, Rep, Req};
let time_provider = time_provider.unwrap_or_default();

let cmds = Arc::new(
Expand All @@ -234,7 +234,7 @@ pub async fn claimer_retrieve_info(

match rep {
Rep::Ok(claimer) => match claimer {
UserOrDevice::User {
InvitationType::User {
claimer_email,
greeter_user_id,
greeter_human_handle,
Expand All @@ -246,7 +246,7 @@ pub async fn claimer_retrieve_info(
greeter_human_handle,
time_provider,
))),
UserOrDevice::Device {
InvitationType::Device {
greeter_user_id,
greeter_human_handle,
} => Ok(UserOrDeviceClaimInitialCtx::Device(
Expand All @@ -258,7 +258,7 @@ pub async fn claimer_retrieve_info(
time_provider,
),
)),
UserOrDevice::ShamirRecovery {
InvitationType::ShamirRecovery {
claimer_user_id,
claimer_human_handle,
recipients,
Expand Down
2 changes: 1 addition & 1 deletion libparsec/crates/client/tests/unit/invite/claimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async fn claimer(tmp_path: TmpPath, env: &TestbedEnv) {
let alice = alice.clone();
move |_req: protocol::invited_cmds::latest::invite_info::Req| {
protocol::invited_cmds::latest::invite_info::Rep::Ok(
protocol::invited_cmds::latest::invite_info::UserOrDevice::User {
protocol::invited_cmds::latest::invite_info::InvitationType::User {
claimer_email: "[email protected]".to_owned(),
greeter_human_handle: alice.human_handle.clone(),
greeter_user_id: alice.user_id.to_owned(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"reps": [
{
"status": "ok",
"unit": "UserOrDevice"
"unit": "InvitationType"
}
],
"nested_types": [
{
"name": "UserOrDevice",
"name": "InvitationType",
"discriminant_field": "type",
"variants": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn rep_ok() {
"6f624064657631a3626f62af677265657465725f757365725f6964d802109b68ba5cdf"
"428ea0017fc6bcc04d4a"
)[..],
invited_cmds::invite_info::Rep::Ok(invited_cmds::invite_info::UserOrDevice::User {
invited_cmds::invite_info::Rep::Ok(invited_cmds::invite_info::InvitationType::User {
claimer_email: "alice@dev1".to_owned(),
greeter_user_id: UserID::from_hex("109b68ba5cdf428ea0017fc6bcc04d4a").unwrap(),
greeter_human_handle: HumanHandle::new("bob@dev1", "bob").unwrap(),
Expand All @@ -76,7 +76,7 @@ pub fn rep_ok() {
"616e5f68616e646c6592a8626f624064657631a3626f62af677265657465725f757365"
"725f6964d802109b68ba5cdf428ea0017fc6bcc04d4a"
)[..],
invited_cmds::invite_info::Rep::Ok(invited_cmds::invite_info::UserOrDevice::Device {
invited_cmds::invite_info::Rep::Ok(invited_cmds::invite_info::InvitationType::Device {
greeter_user_id: UserID::from_hex("109b68ba5cdf428ea0017fc6bcc04d4a").unwrap(),
greeter_human_handle: HumanHandle::new("bob@dev1", "bob").unwrap(),
}),
Expand All @@ -101,7 +101,7 @@ pub fn rep_ok() {
"64d802109b68ba5cdf428ea0017fc6bcc04d4ba97468726573686f6c6402"
)[..],
invited_cmds::invite_info::Rep::Ok(
invited_cmds::invite_info::UserOrDevice::ShamirRecovery {
invited_cmds::invite_info::InvitationType::ShamirRecovery {
claimer_user_id: UserID::from_hex("109b68ba5cdf428ea0017fc6bcc04d4c").unwrap(),
claimer_human_handle: HumanHandle::new("[email protected]", "carl").unwrap(),
recipients: vec![
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ from __future__ import annotations

from parsec._parsec import HumanHandle, UserID

class UserOrDevice:
class InvitationType:
pass

class UserOrDeviceUser(UserOrDevice):
class InvitationTypeUser(InvitationType):
def __init__(
self, claimer_email: str, greeter_user_id: UserID, greeter_human_handle: HumanHandle
) -> None: ...
Expand All @@ -20,14 +20,14 @@ class UserOrDeviceUser(UserOrDevice):
@property
def greeter_user_id(self) -> UserID: ...

class UserOrDeviceDevice(UserOrDevice):
class InvitationTypeDevice(InvitationType):
def __init__(self, greeter_user_id: UserID, greeter_human_handle: HumanHandle) -> None: ...
@property
def greeter_human_handle(self) -> HumanHandle: ...
@property
def greeter_user_id(self) -> UserID: ...

class UserOrDeviceShamirRecovery(UserOrDevice):
class InvitationTypeShamirRecovery(InvitationType):
def __init__(
self,
claimer_user_id: UserID,
Expand Down Expand Up @@ -72,6 +72,6 @@ class RepUnknownStatus(Rep):
def reason(self) -> str | None: ...

class RepOk(Rep):
def __init__(self, unit: UserOrDevice) -> None: ...
def __init__(self, unit: InvitationType) -> None: ...
@property
def unit(self) -> UserOrDevice: ...
def unit(self) -> InvitationType: ...
6 changes: 3 additions & 3 deletions server/parsec/components/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,22 +945,22 @@ async def api_invite_info(
match outcome:
case UserInvitation() as invitation:
return invited_cmds.latest.invite_info.RepOk(
invited_cmds.latest.invite_info.UserOrDeviceUser(
invited_cmds.latest.invite_info.InvitationTypeUser(
claimer_email=invitation.claimer_email,
greeter_user_id=invitation.created_by_user_id,
greeter_human_handle=invitation.created_by_human_handle,
)
)
case DeviceInvitation() as invitation:
return invited_cmds.latest.invite_info.RepOk(
invited_cmds.latest.invite_info.UserOrDeviceDevice(
invited_cmds.latest.invite_info.InvitationTypeDevice(
greeter_user_id=invitation.created_by_user_id,
greeter_human_handle=invitation.created_by_human_handle,
)
)
case ShamirRecoveryInvitation() as invitation:
return invited_cmds.latest.invite_info.RepOk(
invited_cmds.latest.invite_info.UserOrDeviceShamirRecovery(
invited_cmds.latest.invite_info.InvitationTypeShamirRecovery(
claimer_user_id=invitation.claimer_user_id,
claimer_human_handle=invitation.claimer_human_handle,
threshold=invitation.threshold,
Expand Down
6 changes: 3 additions & 3 deletions server/tests/api_v4/invited/test_invite_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async def test_invited_invite_info_ok(user_or_device: str, coolorg: CoolorgRpcCl
case "user":
rep = await coolorg.invited_zack.invite_info()
assert rep == invited_cmds.v4.invite_info.RepOk(
invited_cmds.v4.invite_info.UserOrDeviceUser(
invited_cmds.v4.invite_info.InvitationTypeUser(
claimer_email=coolorg.invited_zack.claimer_email,
greeter_user_id=coolorg.alice.user_id,
greeter_human_handle=coolorg.alice.human_handle,
Expand All @@ -22,7 +22,7 @@ async def test_invited_invite_info_ok(user_or_device: str, coolorg: CoolorgRpcCl
case "device":
rep = await coolorg.invited_alice_dev3.invite_info()
assert rep == invited_cmds.v4.invite_info.RepOk(
invited_cmds.v4.invite_info.UserOrDeviceDevice(
invited_cmds.v4.invite_info.InvitationTypeDevice(
greeter_user_id=coolorg.alice.user_id,
greeter_human_handle=coolorg.alice.human_handle,
)
Expand All @@ -35,7 +35,7 @@ async def test_invited_invite_info_ok(user_or_device: str, coolorg: CoolorgRpcCl
async def test_invited_invite_info_ok_with_shamir(shamirorg: ShamirOrgRpcClients) -> None:
rep = await shamirorg.shamir_invited_alice.invite_info()
assert rep == invited_cmds.v4.invite_info.RepOk(
invited_cmds.v4.invite_info.UserOrDeviceShamirRecovery(
invited_cmds.v4.invite_info.InvitationTypeShamirRecovery(
claimer_user_id=shamirorg.alice.user_id,
claimer_human_handle=shamirorg.alice.human_handle,
threshold=2,
Expand Down

0 comments on commit 5840cd7

Please sign in to comment.