def _on_list_success(self, job): assert job.is_finished() assert job.status == "ok" total, users, invitations = job.ret if total == 0 and self._page > 1: self._page -= 1 self.reset() self._flush_users_list() current_user = self.client.device.user_id for invitation in reversed(invitations): addr = BackendInvitationAddr.build( backend_addr=self.client.device.organization_addr, organization_id=self.client.device.organization_id, invitation_type=InvitationType.USER, token=invitation["token"], ) self.add_user_invitation(invitation["claimer_email"], addr) for user_info in users: self.add_user(user_info=user_info, is_current_user=current_user == user_info.user_id) self.spinner.spinner_movie.stop() self.spinner.hide() self.pagination(total=total)
def _to_http_redirection_url(client_ctx, invitation): return BackendInvitationAddr.build( backend_addr=self._config.backend_addr, organization_id=client_ctx.organization_id, invitation_type=invitation.TYPE, token=invitation.token, ).to_http_redirection_url()
async def invitation_addr(backend, alice): invitation = await backend.invite.new_for_device( organization_id=alice.organization_id, greeter_user_id=alice.user_id) return BackendInvitationAddr.build( backend_addr=alice.organization_addr, organization_id=alice.organization_id, invitation_type=InvitationType.DEVICE, token=invitation.token, )
async def bootstrap(self): author = logged_gui.test_get_central_widget().client.device claimer_email = self.requested_human_handle.email # Create new invitation invitation = await backend.invite.new_for_user( organization_id=author.organization_id, greeter_user_id=author.user_id, claimer_email=claimer_email, ) invitation_addr = BackendInvitationAddr.build( backend_addr=author.organization_addr, organization_id=author.organization_id, invitation_type=InvitationType.USER, token=invitation.token, ) # Switch to users page users_widget = await logged_gui.test_switch_to_users_widget() assert users_widget.layout_users.count() == 4 invitation_widget = users_widget.layout_users.itemAt(0).widget() assert isinstance(invitation_widget, UserInvitationButton) assert invitation_widget.email == claimer_email # Click on the invitation button await aqtbot.mouse_click(invitation_widget.button_greet, QtCore.Qt.LeftButton) greet_user_widget = await catch_greet_user_widget() assert isinstance(greet_user_widget, GreetUserWidget) greet_user_information_widget = await catch_greet_user_widget() assert isinstance(greet_user_information_widget, GreetUserInstructionsWidget) def _greet_user_displayed(): # assert greet_user_widget.dialog.isVisible() assert greet_user_widget.isVisible() # assert greet_user_widget.dialog.label_title.text() == "Greet a new user" assert greet_user_information_widget.isVisible() await aqtbot.wait_until(_greet_user_displayed) self.author = author self.users_widget = users_widget self.invitation_widget = invitation_widget self.invitation_addr = invitation_addr self.greet_user_widget = greet_user_widget self.greet_user_information_widget = greet_user_information_widget self.assert_initial_state() # Sanity check
async def test_handshake_unknown_organization(running_backend, coolorg): invitation_addr = BackendInvitationAddr.build( backend_addr=running_backend.addr, organization_id=coolorg.organization_id, invitation_type=InvitationType.DEVICE, token=uuid4(), ) with pytest.raises(BackendConnectionRefused) as exc: async with backend_invited_cmds_factory(invitation_addr) as cmds: await cmds.ping() assert str(exc.value) == "Invalid handshake information"
async def test_handshake_organization_expired(running_backend, expiredorg, expiredorgalice): invitation = await running_backend.backend.invite.new_for_device( organization_id=expiredorgalice.organization_id, greeter_user_id=expiredorgalice.user_id) invitation_addr = BackendInvitationAddr.build( backend_addr=running_backend.addr, organization_id=expiredorgalice.organization_id, invitation_type=InvitationType.DEVICE, token=invitation.token, ) with pytest.raises(BackendConnectionRefused) as exc: async with backend_invited_cmds_factory(invitation_addr) as cmds: await cmds.ping() assert str(exc.value) == "Trial organization has expired"
async def test_invited_cmd_keepalive(mock_clock, monkeypatch, backend, running_backend, backend_addr, alice): invitation = await backend.invite.new_for_device( organization_id=alice.organization_id, greeter_user_id=alice.user_id) invitation_addr = BackendInvitationAddr.build( backend_addr=alice.organization_addr, organization_id=alice.organization_id, invitation_type=InvitationType.DEVICE, token=invitation.token, ) def _cmds_factory(keepalive): return backend_invited_cmds_factory(invitation_addr, keepalive=keepalive) await _test_keepalive(mock_clock, monkeypatch, _cmds_factory)
async def new_device_invitation(self, send_email: bool) -> BackendInvitationAddr: """ Raises: BackendConnectionError """ rep = await self._backend_conn.cmds.invite_new( type=InvitationType.DEVICE, send_email=send_email) if rep["status"] != "ok": raise BackendConnectionError(f"Backend error: {rep}") return BackendInvitationAddr.build( backend_addr=self.device.organization_addr, organization_id=self.device.organization_id, invitation_type=InvitationType.DEVICE, token=rep["token"], )
async def bootstrap(self): author = logged_gui.test_get_central_widget().client.device # Create new invitation invitation = await backend.invite.new_for_device( organization_id=author.organization_id, greeter_user_id=author.user_id ) invitation_addr = BackendInvitationAddr.build( backend_addr=author.organization_addr, organization_id=author.organization_id, invitation_type=InvitationType.DEVICE, token=invitation.token, ) # Switch to devices page devices_widget = await logged_gui.test_switch_to_devices_widget() assert devices_widget.layout_devices.count() == 2 # Click on the invitation button await aqtbot.mouse_click(devices_widget.button_add_device, QtCore.Qt.LeftButton) greet_device_widget = await catch_greet_device_widget() assert isinstance(greet_device_widget, GreetDeviceWidget) greet_device_information_widget = await catch_greet_device_widget() assert isinstance(greet_device_information_widget, GreetDeviceInstructionsWidget) def _greet_device_displayed(): # assert greet_device_widget.dialog.isVisible() assert greet_device_widget.isVisible() # assert greet_device_widget.dialog.label_title.text() == "Greet a new device" assert greet_device_information_widget.isVisible() await aqtbot.wait_until(_greet_device_displayed) self.author = author self.devices_widget = devices_widget self.invitation_addr = invitation_addr self.greet_device_widget = greet_device_widget self.greet_device_information_widget = greet_device_information_widget self.assert_initial_state() # Sanity check
async def _invite_device(config, device): async with spinner("Creating device invitation"): async with backend_authenticated_cmds_factory( addr=device.organization_addr, device_id=device.device_id, signing_key=device.signing_key, keepalive=config.backend_connection_keepalive, ) as cmds: rep = await cmds.invite_new(type=InvitationType.DEVICE) if rep["status"] != "ok": raise RuntimeError( f"Backend refused to create device invitation: {rep}") action_addr = BackendInvitationAddr.build( backend_addr=device.organization_addr, organization_id=device.organization_id, invitation_type=InvitationType.DEVICE, token=rep["token"], ) action_addr_display = click.style(action_addr.to_url(), fg="yellow") click.echo(f"url: {action_addr_display}")
async def new_user_invitation(self, email: str, send_email: bool) -> BackendInvitationAddr: """ Raises: InviteAlreadyMemberError BackendConnectionError """ rep = await self._backend_conn.cmds.invite_new( type=InvitationType.USER, claimer_email=email, send_email=send_email) if rep["status"] == "already_member": raise InviteAlreadyMemberError() elif rep["status"] != "ok": raise BackendConnectionError(f"Backend error: {rep}") return BackendInvitationAddr.build( backend_addr=self.device.organization_addr, organization_id=self.device.organization_id, invitation_type=InvitationType.USER, token=rep["token"], )
async def bootstrap(self): claimer_email = self.requested_human_handle.email # Create new invitation invitation = await backend.invite.new_for_user( organization_id=self.author.organization_id, greeter_user_id=self.author.user_id, claimer_email=claimer_email, ) invitation_addr = BackendInvitationAddr.build( backend_addr=self.author.organization_addr, organization_id=self.author.organization_id, invitation_type=InvitationType.USER, token=invitation.token, ) # Switch to users claim page await aqtbot.run(gui.add_instance, invitation_addr.to_url()) cu_w = await catch_claim_user_widget() assert isinstance(cu_w, ClaimUserWidget) cui_w = await catch_claim_user_widget() assert isinstance(cui_w, ClaimUserInstructionsWidget) def _register_user_displayed(): tab = gui.test_get_tab() assert tab and tab.isVisible() assert cu_w.isVisible() # assert cu_w.dialog.label_title.text() == "Register a user" assert cui_w.isVisible() await aqtbot.wait_until(_register_user_displayed) self.invitation_addr = invitation_addr self.claim_user_widget = cu_w self.claim_user_instructions_widget = cui_w self.assert_initial_state() # Sanity check
async def bootstrap(self): # Create new invitation invitation = await backend.invite.new_for_device( organization_id=self.author.organization_id, greeter_user_id=self.author.user_id) invitation_addr = BackendInvitationAddr.build( backend_addr=self.author.organization_addr, organization_id=self.author.organization_id, invitation_type=InvitationType.DEVICE, token=invitation.token, ) # Switch to device claim page await aqtbot.run(gui.add_instance, invitation_addr.to_url()) cd_w = await catch_claim_device_widget() assert isinstance(cd_w, ClaimDeviceWidget) cdi_w = await catch_claim_device_widget() assert isinstance(cdi_w, ClaimDeviceInstructionsWidget) def _register_device_displayed(): tab = gui.test_get_tab() assert tab and tab.isVisible() # assert cd_w.isVisible() # assert cd_w.dialog.label_title.text() == "Register a device" # assert cdi_w.isVisible() await aqtbot.wait_until(_register_device_displayed) self.invitation_addr = invitation_addr self.claim_device_widget = cd_w self.claim_device_instructions_widget = cdi_w self.assert_initial_state() # Sanity check