Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
remote_billing: Extract RemoteBillingUserDict sub-dict.
Mateusz Manderaea9e2ece49fe
diff --git a/corporate/lib/remote_billing_util.py b/corporate/lib/remote_billing_util.pyindex 5627a68a558..38054e18cbb 100644--- a/corporate/lib/remote_billing_util.py+++ b/corporate/lib/remote_billing_util.py@@ -10,10 +10,14 @@ from zilencer.models import RemoteRealm, RemoteZulipServerbilling_logger = logging.getLogger("corporate.stripe")-class RemoteBillingIdentityDict(TypedDict):+class RemoteBillingUserDict(TypedDict):user_uuid: struser_email: struser_full_name: str+++class RemoteBillingIdentityDict(TypedDict):+ user: RemoteBillingUserDictremote_server_uuid: strremote_realm_uuid: strdiff --git a/corporate/tests/test_remote_billing.py b/corporate/tests/test_remote_billing.pyindex 67e5cbb909f..80e95b5a98d 100644--- a/corporate/tests/test_remote_billing.py+++ b/corporate/tests/test_remote_billing.py@@ -4,7 +4,7 @@ from unittest import mockimport responsesfrom django.test import override_settings-from corporate.lib.remote_billing_util import RemoteBillingIdentityDict+from corporate.lib.remote_billing_util import RemoteBillingIdentityDict, RemoteBillingUserDictfrom zerver.lib.remote_server import send_realms_only_to_push_bouncerfrom zerver.lib.test_classes import BouncerTestCasefrom zerver.models import UserProfile@@ -34,9 +34,11 @@ class RemoteBillingAuthenticationTest(BouncerTestCase):# Verify the authed data that should have been stored in the session.identity_dict = RemoteBillingIdentityDict(- user_email=user.delivery_email,- user_uuid=str(user.uuid),- user_full_name=user.full_name,+ user=RemoteBillingUserDict(+ user_email=user.delivery_email,+ user_uuid=str(user.uuid),+ user_full_name=user.full_name,+ ),remote_server_uuid=str(self.server.uuid),remote_realm_uuid=str(user.realm.uuid),next_page=next_page,diff --git a/corporate/views/remote_billing_page.py b/corporate/views/remote_billing_page.pyindex b5b5fe9fd7c..fdbdd437a5e 100644--- a/corporate/views/remote_billing_page.py+++ b/corporate/views/remote_billing_page.py@@ -15,6 +15,7 @@ from corporate.lib.decorator import self_hosting_management_endpointfrom corporate.lib.remote_billing_util import (LegacyServerIdentityDict,RemoteBillingIdentityDict,+ RemoteBillingUserDict,get_identity_dict_from_session,)from zerver.lib.exceptions import JsonableError, MissingRemoteRealmError@@ -51,9 +52,9 @@ def remote_server_billing_entry(raise MissingRemoteRealmErroridentity_dict = RemoteBillingIdentityDict(- user_email=user.email,- user_uuid=str(user.uuid),- user_full_name=user.full_name,+ user=RemoteBillingUserDict(+ user_email=user.email, user_uuid=str(user.uuid), user_full_name=user.full_name+ ),remote_server_uuid=str(remote_server.uuid),remote_realm_uuid=str(remote_realm.uuid),next_page=next_page,@@ -118,10 +119,17 @@ def render_tmp_remote_billing_page(# This key should be set in both RemoteRealm and legacy server# login flows.remote_server_uuid = identity_dict["remote_server_uuid"]- user_email = identity_dict.get("user_email")- user_full_name = identity_dict.get("user_full_name")+remote_realm_uuid = identity_dict.get("remote_realm_uuid")+ user_dict = identity_dict.get("user", {})+ # Mypy recognizes user_dict as "object" otherwise.+ # If not empty, this is actually a RemoteBillingUserDict.+ assert isinstance(user_dict, dict)++ user_email = user_dict.get("user_email")+ user_full_name = user_dict.get("user_full_name")+try:remote_server = RemoteZulipServer.objects.get(uuid=remote_server_uuid)except RemoteZulipServer.DoesNotExist: