mirror of https://github.com/zulip/zulip.git
remote_billing: Extract RemoteBillingUserDict sub-dict.
This commit is contained in:
parent
5a198c639e
commit
ea9e2ece49
|
@ -10,10 +10,14 @@ from zilencer.models import RemoteRealm, RemoteZulipServer
|
|||
billing_logger = logging.getLogger("corporate.stripe")
|
||||
|
||||
|
||||
class RemoteBillingIdentityDict(TypedDict):
|
||||
class RemoteBillingUserDict(TypedDict):
|
||||
user_uuid: str
|
||||
user_email: str
|
||||
user_full_name: str
|
||||
|
||||
|
||||
class RemoteBillingIdentityDict(TypedDict):
|
||||
user: RemoteBillingUserDict
|
||||
remote_server_uuid: str
|
||||
remote_realm_uuid: str
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from unittest import mock
|
|||
import responses
|
||||
from django.test import override_settings
|
||||
|
||||
from corporate.lib.remote_billing_util import RemoteBillingIdentityDict
|
||||
from corporate.lib.remote_billing_util import RemoteBillingIdentityDict, RemoteBillingUserDict
|
||||
from zerver.lib.remote_server import send_realms_only_to_push_bouncer
|
||||
from zerver.lib.test_classes import BouncerTestCase
|
||||
from 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,
|
||||
|
|
|
@ -15,6 +15,7 @@ from corporate.lib.decorator import self_hosting_management_endpoint
|
|||
from 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 MissingRemoteRealmError
|
||||
|
||||
identity_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:
|
||||
|
|
Loading…
Reference in New Issue