Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

remote-support: Add ability to search by billing user email.

Lauryn Menard1914b881d92b
diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py
index 50091a0ea13..5ed42942247 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="[email protected]", user_uuid=uuid.uuid4()
+ )
+ RemoteServerBillingUser.objects.create(
+ remote_server=remote_realm.server, email="[email protected]"
+ )
+
def test_search(self) -> None:
def assert_server_details_in_response(
html_response: "TestHttpResponse", hostname: str
@@ -168,6 +179,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
'<span class="label">remote server</span>',
f"<h3>{hostname} <a",
f"<b>Contact email</b>: admin@{hostname}",
+ "<b>Billing users</b>:",
"<b>Date created</b>:",
"<b>UUID</b>:",
"<b>Zulip version</b>:",
@@ -278,6 +290,15 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
result,
)
+ def check_for_billing_users_emails(result: "TestHttpResponse") -> None:
+ self.assert_in_success_response(
+ [
+ "<b>Billing users</b>: [email protected]",
+ "<b>Billing users</b>: [email protected]",
+ ],
+ 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": "[email protected]"})
+ 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": "[email protected]"})
+ 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 0acb144b1d0..c55bbd350bf 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))