remote-support: Return server results for realms with host match.

Checks for remote realm hosts that match the search query. Adds a
database query to getting the initial search results.
This commit is contained in:
Lauryn Menard 2024-02-21 16:19:21 +01:00 committed by Tim Abbott
parent aec02d18af
commit 1eca9b3f6e
2 changed files with 20 additions and 1 deletions

View File

@ -165,6 +165,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
) -> None: ) -> None:
self.assert_in_success_response( self.assert_in_success_response(
[ [
'<span class="label">remote server</span>',
f"<h3>{hostname} <a", f"<h3>{hostname} <a",
f"<b>Contact email</b>: admin@{hostname}", f"<b>Contact email</b>: admin@{hostname}",
"<b>Date created</b>:", "<b>Date created</b>:",
@ -183,6 +184,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
) -> None: ) -> None:
self.assert_in_success_response( self.assert_in_success_response(
[ [
'<span class="label">remote realm</span>',
f"<h3>{name}</h3>", f"<h3>{name}</h3>",
f"<b>Remote realm host:</b> {host}<br />", f"<b>Remote realm host:</b> {host}<br />",
"<b>Date created</b>: 01 December 2023", "<b>Date created</b>: 01 December 2023",
@ -303,6 +305,13 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
result = self.client_get("/activity/remote/support", {"q": f"zulip-{server}.example.com"}) result = self.client_get("/activity/remote/support", {"q": f"zulip-{server}.example.com"})
check_remote_server_with_no_realms(result) check_remote_server_with_no_realms(result)
# RemoteRealm host matches appear in search results
result = self.client_get("/activity/remote/support", {"q": "realm-host-"})
for i in range(6):
if i > server:
assert_server_details_in_response(result, f"zulip-{i}.example.com")
assert_realm_details_in_response(result, f"realm-name-{i}", f"realm-host-{i}")
server = 2 server = 2
with mock.patch("corporate.views.support.compute_max_monthly_messages", return_value=1000): with mock.patch("corporate.views.support.compute_max_monthly_messages", return_value=1000):
result = self.client_get( result = self.client_get(

View File

@ -472,7 +472,17 @@ def get_remote_servers_for_support(
return list(remote_servers_query.filter(contact_email__iexact=email_to_search)) return list(remote_servers_query.filter(contact_email__iexact=email_to_search))
if hostname_to_search: if hostname_to_search:
return list(remote_servers_query.filter(hostname__icontains=hostname_to_search)) remote_servers_set = set(
remote_servers_query.filter(hostname__icontains=hostname_to_search)
)
remote_realm_matches = (
RemoteRealm.objects.filter(host__icontains=hostname_to_search).exclude(
realm_deactivated=True
)
).select_related("server")
for remote_realm in remote_realm_matches:
remote_servers_set.add(remote_realm.server)
return list(remote_servers_set)
return [] return []