diff --git a/corporate/lib/support.py b/corporate/lib/support.py index 4078c87d00..15f0f962a6 100644 --- a/corporate/lib/support.py +++ b/corporate/lib/support.py @@ -12,6 +12,7 @@ from django.utils.timezone import now as timezone_now from corporate.lib.stripe import ( BillingSession, PushNotificationsEnabledStatus, + RealmBillingSession, RemoteRealmBillingSession, RemoteServerBillingSession, get_configured_fixed_price_plan_offer, @@ -95,7 +96,7 @@ class MobilePushData: @dataclass -class SupportData: +class RemoteSupportData: date_created: datetime plan_data: PlanData sponsorship_data: SponsorshipData @@ -103,6 +104,12 @@ class SupportData: mobile_push_data: MobilePushData +@dataclass +class CloudSupportData: + plan_data: PlanData + sponsorship_data: SponsorshipData + + def get_realm_support_url(realm: Realm) -> str: support_realm_uri = get_realm(settings.STAFF_SUBDOMAIN).uri support_url = urljoin( @@ -112,14 +119,6 @@ def get_realm_support_url(realm: Realm) -> str: return support_url -def get_customer_discount_for_support_view( - customer: Optional[Customer] = None, -) -> Optional[Decimal]: - if customer is None: - return None - return customer.default_discount - - def get_customer_sponsorship_data(customer: Customer) -> SponsorshipData: pending = customer.sponsorship_pending discount = customer.default_discount @@ -353,7 +352,7 @@ def get_mobile_push_data(remote_entity: Union[RemoteZulipServer, RemoteRealm]) - ) -def get_data_for_support_view(billing_session: BillingSession) -> SupportData: +def get_data_for_remote_support_view(billing_session: BillingSession) -> RemoteSupportData: if isinstance(billing_session, RemoteServerBillingSession): user_data = get_remote_server_guest_and_non_guest_count(billing_session.remote_server.id) stale_audit_log_data = has_stale_audit_log(billing_session.remote_server) @@ -375,10 +374,24 @@ def get_data_for_support_view(billing_session: BillingSession) -> SupportData: else: sponsorship_data = SponsorshipData() - return SupportData( + return RemoteSupportData( date_created=date_created, plan_data=plan_data, sponsorship_data=sponsorship_data, user_data=user_data, mobile_push_data=mobile_data, ) + + +def get_data_for_cloud_support_view(billing_session: BillingSession) -> CloudSupportData: + assert isinstance(billing_session, RealmBillingSession) + plan_data = get_plan_data_for_support_view(billing_session) + if plan_data.customer is not None: + sponsorship_data = get_customer_sponsorship_data(plan_data.customer) + else: + sponsorship_data = SponsorshipData() + + return CloudSupportData( + plan_data=plan_data, + sponsorship_data=sponsorship_data, + ) diff --git a/corporate/views/support.py b/corporate/views/support.py index f07cccd7d3..c49e8de2a6 100644 --- a/corporate/views/support.py +++ b/corporate/views/support.py @@ -36,11 +36,10 @@ from corporate.lib.stripe import ( format_discount_percentage, ) from corporate.lib.support import ( - PlanData, - SupportData, - get_customer_discount_for_support_view, - get_data_for_support_view, - get_plan_data_for_support_view, + CloudSupportData, + RemoteSupportData, + get_data_for_cloud_support_view, + get_data_for_remote_support_view, get_realm_support_url, ) from corporate.models import CustomerPlan @@ -454,12 +453,12 @@ def support( ] + [user.realm for user in users] ) - plan_data: Dict[int, PlanData] = {} + realm_support_data: Dict[int, CloudSupportData] = {} for realm in all_realms: billing_session = RealmBillingSession(user=None, realm=realm) - realm_plan_data = get_plan_data_for_support_view(billing_session) - plan_data[realm.id] = realm_plan_data - context["plan_data"] = plan_data + realm_data = get_data_for_cloud_support_view(billing_session) + realm_support_data[realm.id] = realm_data + context["realm_support_data"] = realm_support_data def get_realm_owner_emails_as_string(realm: Realm) -> str: return ", ".join( @@ -477,7 +476,6 @@ def support( context["get_realm_owner_emails_as_string"] = get_realm_owner_emails_as_string context["get_realm_admin_emails_as_string"] = get_realm_admin_emails_as_string - context["get_discount"] = get_customer_discount_for_support_view context["format_discount"] = format_discount_percentage context["dollar_amount"] = cents_to_dollar_string context["realm_icon_url"] = realm_icon_url @@ -691,8 +689,8 @@ def remote_servers_support( hostname_to_search=hostname_to_search, ) remote_server_to_max_monthly_messages: Dict[int, Union[int, str]] = dict() - server_support_data: Dict[int, SupportData] = {} - realm_support_data: Dict[int, SupportData] = {} + server_support_data: Dict[int, RemoteSupportData] = {} + realm_support_data: Dict[int, RemoteSupportData] = {} remote_realms: Dict[int, List[RemoteRealm]] = {} for remote_server in remote_servers: # Get remote realms attached to remote server @@ -703,11 +701,11 @@ def remote_servers_support( # Get plan data for remote realms for remote_realm in remote_realms_for_server: realm_billing_session = RemoteRealmBillingSession(remote_realm=remote_realm) - remote_realm_data = get_data_for_support_view(realm_billing_session) + remote_realm_data = get_data_for_remote_support_view(realm_billing_session) realm_support_data[remote_realm.id] = remote_realm_data # Get plan data for remote server server_billing_session = RemoteServerBillingSession(remote_server=remote_server) - remote_server_data = get_data_for_support_view(server_billing_session) + remote_server_data = get_data_for_remote_support_view(server_billing_session) server_support_data[remote_server.id] = remote_server_data # Get max monthly messages try: diff --git a/templates/corporate/support/realm_details.html b/templates/corporate/support/realm_details.html index c2c1104e8d..538c615213 100644 --- a/templates/corporate/support/realm_details.html +++ b/templates/corporate/support/realm_details.html @@ -85,13 +85,13 @@ {{ csrf_input }} - {% if plan_data[realm.id].customer and plan_data[realm.id].customer.sponsorship_pending %} + {% if realm_support_data[realm.id].sponsorship_data.sponsorship_pending %}
+ + {% if realm_support_data[realm.id].sponsorship_data.sponsorship_pending %} + {% with %} + {% set latest_sponsorship_request = realm_support_data[realm.id].sponsorship_data.latest_sponsorship_request %} + {% include 'corporate/support/sponsorship_request_details.html' %} + {% endwith %} + {% endif %} - {% if plan_data[realm.id].current_plan %} + {% if realm_support_data[realm.id].plan_data.current_plan %}