mirror of https://github.com/zulip/zulip.git
corporate: Implement support_url for all BillingSession child classes.
Adds a helper since there are only a few different parameters for all BillingSession child clases, `build_support_url`. Also, renames `get_support_url` to more explicitly note that it is for realms: `get_realm_support_url`.
This commit is contained in:
parent
46dab1beb9
commit
906e667a70
|
@ -9,6 +9,7 @@ from decimal import Decimal
|
|||
from enum import Enum
|
||||
from functools import wraps
|
||||
from typing import Any, Callable, Dict, Generator, Optional, Tuple, TypedDict, TypeVar, Union
|
||||
from urllib.parse import urlencode, urljoin
|
||||
|
||||
import stripe
|
||||
from django import forms
|
||||
|
@ -44,12 +45,14 @@ from zerver.lib.send_email import (
|
|||
send_email_to_billing_admins_and_realm_owners,
|
||||
)
|
||||
from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
|
||||
from zerver.lib.url_encoding import append_url_query_string
|
||||
from zerver.lib.utils import assert_is_not_none
|
||||
from zerver.models import (
|
||||
Realm,
|
||||
RealmAuditLog,
|
||||
UserProfile,
|
||||
get_org_type_display_name,
|
||||
get_realm,
|
||||
get_system_bot,
|
||||
)
|
||||
from zilencer.models import (
|
||||
|
@ -374,6 +377,14 @@ def payment_method_string(stripe_customer: stripe.Customer) -> str:
|
|||
) # nocoverage
|
||||
|
||||
|
||||
def build_support_url(support_view: str, query_text: str) -> str:
|
||||
support_realm_url = get_realm(settings.STAFF_SUBDOMAIN).uri
|
||||
support_url = urljoin(support_realm_url, reverse(support_view))
|
||||
query = urlencode({"q": query_text})
|
||||
support_url = append_url_query_string(support_url, query)
|
||||
return support_url
|
||||
|
||||
|
||||
class BillingError(JsonableError):
|
||||
data_fields = ["error_description"]
|
||||
# error messages
|
||||
|
@ -2408,10 +2419,7 @@ class RealmBillingSession(BillingSession):
|
|||
|
||||
@override
|
||||
def support_url(self) -> str:
|
||||
# TODO: Refactor to not create an import cycle.
|
||||
from corporate.lib.support import get_support_url
|
||||
|
||||
return get_support_url(self.realm)
|
||||
return build_support_url("support", self.realm.string_id)
|
||||
|
||||
@override
|
||||
def get_customer(self) -> Optional[Customer]:
|
||||
|
@ -2706,7 +2714,7 @@ class RemoteRealmBillingSession(BillingSession): # nocoverage
|
|||
|
||||
@override
|
||||
def support_url(self) -> str:
|
||||
return "TODO:not-implemented"
|
||||
return build_support_url("remote_servers_support", self.remote_realm.server.hostname)
|
||||
|
||||
@override
|
||||
def get_customer(self) -> Optional[Customer]:
|
||||
|
@ -2998,7 +3006,7 @@ class RemoteServerBillingSession(BillingSession): # nocoverage
|
|||
|
||||
@override
|
||||
def support_url(self) -> str:
|
||||
return "TODO:not-implemented"
|
||||
return build_support_url("remote_servers_support", self.remote_server.hostname)
|
||||
|
||||
@override
|
||||
def get_customer(self) -> Optional[Customer]:
|
||||
|
|
|
@ -23,7 +23,7 @@ class PlanData:
|
|||
warning: Optional[str] = None
|
||||
|
||||
|
||||
def get_support_url(realm: Realm) -> str:
|
||||
def get_realm_support_url(realm: Realm) -> str:
|
||||
support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri
|
||||
support_url = urljoin(
|
||||
support_realm_uri,
|
||||
|
|
|
@ -2,7 +2,7 @@ from django import forms
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
from corporate.lib.support import get_support_url
|
||||
from corporate.lib.support import get_realm_support_url
|
||||
from zerver.decorator import zulip_login_required
|
||||
from zerver.lib.request import has_request_variables
|
||||
from zerver.lib.send_email import FromAddress, send_email
|
||||
|
@ -38,7 +38,7 @@ def support_request(request: HttpRequest) -> HttpResponse:
|
|||
"realm_string_id": user.realm.string_id,
|
||||
"request_subject": form.cleaned_data["request_subject"],
|
||||
"request_message": form.cleaned_data["request_message"],
|
||||
"support_url": get_support_url(user.realm),
|
||||
"support_url": get_realm_support_url(user.realm),
|
||||
"user_role": user.get_role_name(),
|
||||
}
|
||||
# Sent to the server's support team, so this email is not user-facing.
|
||||
|
|
|
@ -38,7 +38,7 @@ from zerver.models import (
|
|||
from zproject.backends import all_implemented_backend_names
|
||||
|
||||
if settings.CORPORATE_ENABLED:
|
||||
from corporate.lib.support import get_support_url
|
||||
from corporate.lib.support import get_realm_support_url
|
||||
|
||||
|
||||
def do_change_realm_subdomain(
|
||||
|
@ -310,7 +310,7 @@ def do_create_realm(
|
|||
admin_realm = get_realm(settings.SYSTEM_BOT_REALM)
|
||||
sender = get_system_bot(settings.NOTIFICATION_BOT, admin_realm.id)
|
||||
|
||||
support_url = get_support_url(realm)
|
||||
support_url = get_realm_support_url(realm)
|
||||
organization_type = get_org_type_display_name(realm.org_type)
|
||||
|
||||
message = "[{name}]({support_link}) ([{subdomain}]({realm_link})). Organization type: {type}".format(
|
||||
|
|
Loading…
Reference in New Issue