Skip to content

Commit

Permalink
server fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
vxgmichel committed Jan 21, 2025
1 parent 9359f21 commit 67d1d70
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
"discriminant_field": "type",
"variants": [
{
"name": "OrganizationAdministrator",
"discriminant_value": "ORGANIZATION_ADMINISTRATOR",
"name": "User",
"discriminant_value": "USER",
"fields": [
{
"name": "user_id",
Expand Down
18 changes: 15 additions & 3 deletions server/parsec/components/memory/invite.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
InviteGreeterCancelGreetingAttemptBadOutcome,
InviteGreeterStartGreetingAttemptBadOutcome,
InviteGreeterStepBadOutcome,
InviteInfoAdministrator,
InviteListBadOutcome,
InviteNewForDeviceBadOutcome,
InviteNewForShamirRecoveryBadOutcome,
Expand Down Expand Up @@ -133,6 +134,17 @@ def _get_shamir_recovery_invitation(
shamir_recovery_deleted_on=shamir_recovery.deleted_on,
)

def _get_administrators(self, org: MemoryOrganization) -> list[InviteInfoAdministrator]:
return [
InviteInfoAdministrator(
user_id=user_id,
human_handle=user.cooked.human_handle,
online_status=UserOnlineStatus.UNKNOWN,
)
for user_id, user in org.users.items()
if user.current_profile == UserProfile.ADMIN
]

@override
async def new_for_user(
self,
Expand Down Expand Up @@ -493,7 +505,7 @@ async def list(
for invitation in org.invitations.values():
match invitation.type:
case InvitationType.USER:
if author_user.current_profile == UserProfile.ADMIN:
if author_user.current_profile != UserProfile.ADMIN:
continue
assert invitation.claimer_email is not None
status = self._get_invitation_status(organization_id, invitation)
Expand All @@ -502,7 +514,7 @@ async def list(
token=invitation.token,
created_on=invitation.created_on,
created_by=invitation.created_by,
administrators=[], # TODO
administrators=self._get_administrators(org),
status=status,
)
case InvitationType.DEVICE:
Expand Down Expand Up @@ -566,7 +578,7 @@ async def info_as_invited(
status=self._get_invitation_status(organization_id, invitation),
created_by=invitation.created_by,
token=invitation.token,
administrators=[], # TODO
administrators=self._get_administrators(org),
)
case InvitationType.DEVICE:
assert invitation.claimer_user_id is not None
Expand Down
18 changes: 11 additions & 7 deletions server/tests/api_v5/authenticated/test_invite_new_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from parsec._parsec import DateTime, InvitationStatus, authenticated_cmds
from parsec.components.invite import DeviceInvitation, SendEmailBadOutcome
from parsec.components.invite import DeviceInvitation, InvitationCreatedByUser, SendEmailBadOutcome
from parsec.events import EventInvitation
from tests.common import Backend, CoolorgRpcClients, HttpCommonErrorsTester, MinimalorgRpcClients

Expand Down Expand Up @@ -42,9 +42,11 @@ async def test_authenticated_invite_new_device_ok_new(
DeviceInvitation(
token=invitation_token,
created_on=ANY,
created_by_device_id=minimalorg.alice.device_id,
created_by_user_id=minimalorg.alice.user_id,
created_by_human_handle=minimalorg.alice.human_handle,
created_by=InvitationCreatedByUser(
user_id=minimalorg.alice.user_id, human_handle=minimalorg.alice.human_handle
),
claimer_user_id=minimalorg.alice.user_id,
claimer_human_handle=minimalorg.alice.human_handle,
status=InvitationStatus.IDLE,
)
]
Expand Down Expand Up @@ -154,9 +156,11 @@ async def _mocked_send_email(*args, **kwargs):
DeviceInvitation(
token=invitation_token,
created_on=ANY,
created_by_device_id=minimalorg.alice.device_id,
created_by_user_id=minimalorg.alice.user_id,
created_by_human_handle=minimalorg.alice.human_handle,
created_by=InvitationCreatedByUser(
user_id=minimalorg.alice.user_id, human_handle=minimalorg.alice.human_handle
),
claimer_user_id=minimalorg.alice.user_id,
claimer_human_handle=minimalorg.alice.human_handle,
status=InvitationStatus.IDLE,
)
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
authenticated_cmds,
)
from parsec.components.invite import (
InvitationCreatedByUser,
SendEmailBadOutcome,
ShamirRecoveryInvitation,
ShamirRecoveryRecipient,
Expand Down Expand Up @@ -52,9 +53,9 @@ async def test_authenticated_invite_new_shamir_recovery_ok_new(
ShamirRecoveryInvitation(
token=invitation_token,
created_on=ANY,
created_by_device_id=shamirorg.mike.device_id,
created_by_user_id=shamirorg.mike.user_id,
created_by_human_handle=shamirorg.mike.human_handle,
created_by=InvitationCreatedByUser(
user_id=shamirorg.mike.user_id, human_handle=shamirorg.mike.human_handle
),
status=InvitationStatus.IDLE,
threshold=1,
claimer_user_id=shamirorg.mallory.user_id,
Expand Down Expand Up @@ -186,9 +187,9 @@ async def _mocked_send_email(*args, **kwargs):
ShamirRecoveryInvitation(
token=invitation_token,
created_on=ANY,
created_by_device_id=shamirorg.mike.device_id,
created_by_user_id=shamirorg.mike.user_id,
created_by_human_handle=shamirorg.mike.human_handle,
created_by=InvitationCreatedByUser(
user_id=shamirorg.mike.user_id, human_handle=shamirorg.mike.human_handle
),
status=InvitationStatus.IDLE,
threshold=1,
claimer_user_id=shamirorg.mallory.user_id,
Expand Down
16 changes: 9 additions & 7 deletions server/tests/api_v5/authenticated/test_invite_new_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from parsec._parsec import DateTime, InvitationStatus, UserProfile, authenticated_cmds
from parsec.components.invite import SendEmailBadOutcome, UserInvitation
from parsec.components.invite import InvitationCreatedByUser, SendEmailBadOutcome, UserInvitation
from parsec.events import EventInvitation
from tests.common import (
Backend,
Expand Down Expand Up @@ -47,9 +47,10 @@ async def test_authenticated_invite_new_user_ok_new(
token=invitation_token,
created_on=ANY,
claimer_email="[email protected]",
created_by_device_id=minimalorg.alice.device_id,
created_by_user_id=minimalorg.alice.user_id,
created_by_human_handle=minimalorg.alice.human_handle,
created_by=InvitationCreatedByUser(
user_id=minimalorg.alice.user_id, human_handle=minimalorg.alice.human_handle
),
administrators=[],
status=InvitationStatus.IDLE,
)
]
Expand Down Expand Up @@ -197,9 +198,10 @@ async def _mocked_send_email(*args, **kwargs):
token=invitation_token,
created_on=ANY,
claimer_email="[email protected]",
created_by_device_id=minimalorg.alice.device_id,
created_by_user_id=minimalorg.alice.user_id,
created_by_human_handle=minimalorg.alice.human_handle,
created_by=InvitationCreatedByUser(
user_id=minimalorg.alice.user_id, human_handle=minimalorg.alice.human_handle
),
administrators=[],
status=InvitationStatus.IDLE,
)
]
Expand Down

0 comments on commit 67d1d70

Please sign in to comment.