mirror of
https://github.com/zulip/zulip.git
synced 2025-11-14 10:57:58 +00:00
remote_billing: Extract RemoteBillingUserDict sub-dict.
This commit is contained in:
committed by
Tim Abbott
parent
5a198c639e
commit
ea9e2ece49
@@ -10,10 +10,14 @@ from zilencer.models import RemoteRealm, RemoteZulipServer
|
|||||||
billing_logger = logging.getLogger("corporate.stripe")
|
billing_logger = logging.getLogger("corporate.stripe")
|
||||||
|
|
||||||
|
|
||||||
class RemoteBillingIdentityDict(TypedDict):
|
class RemoteBillingUserDict(TypedDict):
|
||||||
user_uuid: str
|
user_uuid: str
|
||||||
user_email: str
|
user_email: str
|
||||||
user_full_name: str
|
user_full_name: str
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteBillingIdentityDict(TypedDict):
|
||||||
|
user: RemoteBillingUserDict
|
||||||
remote_server_uuid: str
|
remote_server_uuid: str
|
||||||
remote_realm_uuid: str
|
remote_realm_uuid: str
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from unittest import mock
|
|||||||
import responses
|
import responses
|
||||||
from django.test import override_settings
|
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.remote_server import send_realms_only_to_push_bouncer
|
||||||
from zerver.lib.test_classes import BouncerTestCase
|
from zerver.lib.test_classes import BouncerTestCase
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile
|
||||||
@@ -34,9 +34,11 @@ class RemoteBillingAuthenticationTest(BouncerTestCase):
|
|||||||
|
|
||||||
# Verify the authed data that should have been stored in the session.
|
# Verify the authed data that should have been stored in the session.
|
||||||
identity_dict = RemoteBillingIdentityDict(
|
identity_dict = RemoteBillingIdentityDict(
|
||||||
|
user=RemoteBillingUserDict(
|
||||||
user_email=user.delivery_email,
|
user_email=user.delivery_email,
|
||||||
user_uuid=str(user.uuid),
|
user_uuid=str(user.uuid),
|
||||||
user_full_name=user.full_name,
|
user_full_name=user.full_name,
|
||||||
|
),
|
||||||
remote_server_uuid=str(self.server.uuid),
|
remote_server_uuid=str(self.server.uuid),
|
||||||
remote_realm_uuid=str(user.realm.uuid),
|
remote_realm_uuid=str(user.realm.uuid),
|
||||||
next_page=next_page,
|
next_page=next_page,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from corporate.lib.decorator import self_hosting_management_endpoint
|
|||||||
from corporate.lib.remote_billing_util import (
|
from corporate.lib.remote_billing_util import (
|
||||||
LegacyServerIdentityDict,
|
LegacyServerIdentityDict,
|
||||||
RemoteBillingIdentityDict,
|
RemoteBillingIdentityDict,
|
||||||
|
RemoteBillingUserDict,
|
||||||
get_identity_dict_from_session,
|
get_identity_dict_from_session,
|
||||||
)
|
)
|
||||||
from zerver.lib.exceptions import JsonableError, MissingRemoteRealmError
|
from zerver.lib.exceptions import JsonableError, MissingRemoteRealmError
|
||||||
@@ -51,9 +52,9 @@ def remote_server_billing_entry(
|
|||||||
raise MissingRemoteRealmError
|
raise MissingRemoteRealmError
|
||||||
|
|
||||||
identity_dict = RemoteBillingIdentityDict(
|
identity_dict = RemoteBillingIdentityDict(
|
||||||
user_email=user.email,
|
user=RemoteBillingUserDict(
|
||||||
user_uuid=str(user.uuid),
|
user_email=user.email, user_uuid=str(user.uuid), user_full_name=user.full_name
|
||||||
user_full_name=user.full_name,
|
),
|
||||||
remote_server_uuid=str(remote_server.uuid),
|
remote_server_uuid=str(remote_server.uuid),
|
||||||
remote_realm_uuid=str(remote_realm.uuid),
|
remote_realm_uuid=str(remote_realm.uuid),
|
||||||
next_page=next_page,
|
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
|
# This key should be set in both RemoteRealm and legacy server
|
||||||
# login flows.
|
# login flows.
|
||||||
remote_server_uuid = identity_dict["remote_server_uuid"]
|
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")
|
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:
|
try:
|
||||||
remote_server = RemoteZulipServer.objects.get(uuid=remote_server_uuid)
|
remote_server = RemoteZulipServer.objects.get(uuid=remote_server_uuid)
|
||||||
except RemoteZulipServer.DoesNotExist:
|
except RemoteZulipServer.DoesNotExist:
|
||||||
|
|||||||
Reference in New Issue
Block a user