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

This commit is contained in:
Lauryn Menard 2024-02-23 20:55:17 +01:00 committed by Tim Abbott
parent 1f72ab5133
commit 1914b881d9
2 changed files with 51 additions and 2 deletions

View File

@ -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):
'<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>: realm-admin@example.com",
"<b>Billing users</b>: 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"})

View File

@ -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))