diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py index 50091a0ea1..5ed4294224 100644 --- a/corporate/tests/test_support_views.py +++ b/corporate/tests/test_support_views.py @@ -40,6 +40,8 @@ import uuid from zilencer.models import ( RemoteRealm, RemoteRealmAuditLog, + RemoteRealmBillingUser, + RemoteServerBillingUser, RemoteZulipServer, RemoteZulipServerAuditLog, ) @@ -159,6 +161,15 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): # without upgrade scheduled add_legacy_plan(name="realm-name-5", upgrade=False) + # Add billing users + remote_realm = RemoteRealm.objects.get(name="realm-name-3") + RemoteRealmBillingUser.objects.create( + remote_realm=remote_realm, email="realm-admin@example.com", user_uuid=uuid.uuid4() + ) + RemoteServerBillingUser.objects.create( + remote_server=remote_realm.server, email="server-admin@example.com" + ) + def test_search(self) -> None: def assert_server_details_in_response( html_response: "TestHttpResponse", hostname: str @@ -168,6 +179,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): 'remote server', f"

{hostname} Contact email: admin@{hostname}", + "Billing users:", "Date created:", "UUID:", "Zulip version:", @@ -278,6 +290,15 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): result, ) + def check_for_billing_users_emails(result: "TestHttpResponse") -> None: + self.assert_in_success_response( + [ + "Billing users: realm-admin@example.com", + "Billing users: server-admin@example.com", + ], + result, + ) + self.login("cordelia") result = self.client_get("/activity/remote/support") @@ -342,6 +363,18 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): assert_server_details_in_response(result, f"zulip-{server}.example.com") assert_realm_details_in_response(result, f"realm-name-{server}", f"realm-host-{server}") check_sponsorship_request_with_website(result) + check_for_billing_users_emails(result) + + # Check search with billing user emails + result = self.client_get("/activity/remote/support", {"q": "realm-admin@example.com"}) + assert_server_details_in_response(result, f"zulip-{server}.example.com") + assert_realm_details_in_response(result, f"realm-name-{server}", f"realm-host-{server}") + check_for_billing_users_emails(result) + + result = self.client_get("/activity/remote/support", {"q": "server-admin@example.com"}) + assert_server_details_in_response(result, f"zulip-{server}.example.com") + assert_realm_details_in_response(result, f"realm-name-{server}", f"realm-host-{server}") + check_for_billing_users_emails(result) server = 4 result = self.client_get("/activity/remote/support", {"q": f"zulip-{server}.example.com"}) diff --git a/corporate/views/support.py b/corporate/views/support.py index 0acb144b1d..c55bbd350b 100644 --- a/corporate/views/support.py +++ b/corporate/views/support.py @@ -76,7 +76,12 @@ from zerver.models.realms import get_org_type_display_name, get_realm from zerver.models.users import get_user_profile_by_id from zerver.views.invite import get_invitee_emails_set from zilencer.lib.remote_counts import MissingDataError, compute_max_monthly_messages -from zilencer.models import RemoteRealm, RemoteZulipServer +from zilencer.models import ( + RemoteRealm, + RemoteRealmBillingUser, + RemoteServerBillingUser, + RemoteZulipServer, +) class SupportRequestForm(forms.Form): @@ -470,7 +475,18 @@ def get_remote_servers_for_support( remote_servers_query = RemoteZulipServer.objects.order_by("id").exclude(deactivated=True) if email_to_search: - return list(remote_servers_query.filter(contact_email__iexact=email_to_search)) + remote_servers_set = set(remote_servers_query.filter(contact_email__iexact=email_to_search)) + remote_server_billing_users = RemoteServerBillingUser.objects.filter( + email__iexact=email_to_search + ).select_related("remote_server") + for server_billing_user in remote_server_billing_users: + remote_servers_set.add(server_billing_user.remote_server) + remote_realm_billing_users = RemoteRealmBillingUser.objects.filter( + email__iexact=email_to_search + ).select_related("remote_realm__server") + for realm_billing_user in remote_realm_billing_users: + remote_servers_set.add(realm_billing_user.remote_realm.server) + return list(remote_servers_set) if uuid_to_search: remote_servers_set = set(remote_servers_query.filter(uuid__iexact=uuid_to_search))