From 7416e9c29c4da821bb4b1e3cf12f3b6f7bbbfb08 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Mon, 4 Nov 2024 21:01:04 +0100 Subject: [PATCH] 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. --- corporate/lib/support.py | 14 +------------- corporate/views/support.py | 4 ++-- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/corporate/lib/support.py b/corporate/lib/support.py index 23cc5933a8..c013bc8887 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -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) diff --git a/corporate/views/support.py b/corporate/views/support.py index bcac54854a..2b2338bafe 100644 --- a/corporate/views/support.py +++ b/corporate/views/support.py @@ -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.