mirror of https://github.com/zulip/zulip.git
remote_billing_page: Extract method to get RemoteBillingIdentityDict.
This will likely be used in other files.
This commit is contained in:
parent
f006be0cdf
commit
ace14e5a7d
|
@ -0,0 +1,30 @@
|
|||
import logging
|
||||
from typing import Optional, TypedDict
|
||||
|
||||
from django.http import HttpRequest
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
billing_logger = logging.getLogger("corporate.stripe")
|
||||
|
||||
|
||||
class RemoteBillingIdentityDict(TypedDict):
|
||||
user_uuid: str
|
||||
user_email: str
|
||||
user_full_name: str
|
||||
remote_server_uuid: str
|
||||
remote_realm_uuid: str
|
||||
|
||||
|
||||
def get_identity_dict_from_session(
|
||||
request: HttpRequest,
|
||||
realm_uuid: Optional[str],
|
||||
server_uuid: Optional[str],
|
||||
) -> Optional[RemoteBillingIdentityDict]:
|
||||
authed_uuid = realm_uuid or server_uuid
|
||||
assert authed_uuid is not None
|
||||
|
||||
identity_dicts = request.session.get("remote_billing_identities")
|
||||
if identity_dicts is not None:
|
||||
return identity_dicts.get(authed_uuid)
|
||||
|
||||
return None
|
|
@ -1,5 +1,5 @@
|
|||
import logging
|
||||
from typing import Optional, TypedDict
|
||||
from typing import Optional
|
||||
|
||||
from django.conf import settings
|
||||
from django.core import signing
|
||||
|
@ -10,6 +10,10 @@ from django.utils.translation import gettext as _
|
|||
from django.views.decorators.csrf import csrf_exempt
|
||||
from pydantic import Json
|
||||
|
||||
from corporate.lib.remote_billing_util import (
|
||||
RemoteBillingIdentityDict,
|
||||
get_identity_dict_from_session,
|
||||
)
|
||||
from zerver.decorator import self_hosting_management_endpoint
|
||||
from zerver.lib.exceptions import JsonableError, MissingRemoteRealmError
|
||||
from zerver.lib.remote_server import RealmDataForAnalytics, UserDataForRemoteBilling
|
||||
|
@ -20,14 +24,6 @@ from zilencer.models import RemoteRealm, RemoteZulipServer
|
|||
billing_logger = logging.getLogger("corporate.stripe")
|
||||
|
||||
|
||||
class RemoteBillingIdentityDict(TypedDict):
|
||||
user_uuid: str
|
||||
user_email: str
|
||||
user_full_name: str
|
||||
remote_server_uuid: str
|
||||
remote_realm_uuid: str
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
@typed_endpoint
|
||||
def remote_server_billing_entry(
|
||||
|
@ -93,14 +89,9 @@ def remote_server_billing_finalize_login(
|
|||
def render_tmp_remote_billing_page(
|
||||
request: HttpRequest, realm_uuid: Optional[str], server_uuid: Optional[str]
|
||||
) -> HttpResponse:
|
||||
authed_uuid = realm_uuid or server_uuid
|
||||
assert authed_uuid is not None
|
||||
|
||||
identity_dict = None
|
||||
|
||||
identity_dicts = request.session.get("remote_billing_identities")
|
||||
if identity_dicts is not None:
|
||||
identity_dict = identity_dicts.get(authed_uuid)
|
||||
identity_dict = get_identity_dict_from_session(
|
||||
request, realm_uuid=realm_uuid, server_uuid=server_uuid
|
||||
)
|
||||
|
||||
if identity_dict is None:
|
||||
raise JsonableError(_("User not authenticated"))
|
||||
|
|
Loading…
Reference in New Issue