From 1eca9b3f6e3030e8634964cc3aef43faa50eea34 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 21 Feb 2024 16:19:21 +0100 Subject: [PATCH] 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. --- corporate/tests/test_support_views.py | 9 +++++++++ corporate/views/support.py | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/corporate/tests/test_support_views.py b/corporate/tests/test_support_views.py index 0edb953ca8..23c126de5b 100644 --- a/corporate/tests/test_support_views.py +++ b/corporate/tests/test_support_views.py @@ -165,6 +165,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): ) -> None: self.assert_in_success_response( [ + 'remote server', f"

{hostname} Contact email: admin@{hostname}", "Date created:", @@ -183,6 +184,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): ) -> None: self.assert_in_success_response( [ + 'remote realm', f"

{name}

", f"Remote realm host: {host}
", "Date created: 01 December 2023", @@ -303,6 +305,13 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase): result = self.client_get("/activity/remote/support", {"q": f"zulip-{server}.example.com"}) 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 with mock.patch("corporate.views.support.compute_max_monthly_messages", return_value=1000): result = self.client_get( diff --git a/corporate/views/support.py b/corporate/views/support.py index 1e5cdab147..a31aed2a11 100644 --- a/corporate/views/support.py +++ b/corporate/views/support.py @@ -472,7 +472,17 @@ def get_remote_servers_for_support( return list(remote_servers_query.filter(contact_email__iexact=email_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 []