support: Consolidate logic for generating support URLs.

The build_support_url is a more generic function that's used in
the BillingSession framework and will generate the same URL for
these Zulip Cloud support requests.
This commit is contained in:
Lauryn Menard 2024-11-04 21:01:04 +01:00 committed by Tim Abbott
parent 3ebc507ddb
commit 7416e9c29c
2 changed files with 3 additions and 15 deletions

View File

@ -1,11 +1,8 @@
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import Optional, TypedDict, Union
from urllib.parse import urlencode, urljoin, urlunsplit
from django.conf import settings
from django.db.models import Sum
from django.urls import reverse
from django.utils.timezone import now as timezone_now
from corporate.lib.stripe import (
@ -30,7 +27,7 @@ from corporate.models import (
)
from zerver.models import Realm
from zerver.models.realm_audit_logs import AuditLogEventType
from zerver.models.realms import get_org_type_display_name, get_realm
from zerver.models.realms import get_org_type_display_name
from zilencer.lib.remote_counts import MissingDataError
from zilencer.models import (
RemoteCustomerUserCount,
@ -130,15 +127,6 @@ def get_stripe_customer_url(stripe_id: str) -> str:
return f"https://dashboard.stripe.com/customers/{stripe_id}" # nocoverage
def get_realm_support_url(realm: Realm) -> str:
support_realm_url = get_realm(settings.STAFF_SUBDOMAIN).url
support_url = urljoin(
support_realm_url,
urlunsplit(("", "", reverse("support"), urlencode({"q": realm.string_id}), "")),
)
return support_url
def get_realm_user_data(realm: Realm) -> UserData:
non_guests = get_non_guest_user_count(realm)
guests = get_guest_user_count(realm)

View File

@ -98,7 +98,7 @@ class DemoRequestForm(forms.Form):
@zulip_login_required
@typed_endpoint_without_parameters
def support_request(request: HttpRequest) -> HttpResponse:
from corporate.lib.support import get_realm_support_url
from corporate.lib.stripe import build_support_url
user = request.user
assert user.is_authenticated
@ -119,7 +119,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_realm_support_url(user.realm),
"support_url": build_support_url("support", user.realm.string_id),
"user_role": user.get_role_name(),
}
# Sent to the server's support team, so this email is not user-facing.