mirror of https://github.com/zulip/zulip.git
remote-support: Add search results for remote server/realm uuid.
This commit is contained in:
parent
1eca9b3f6e
commit
907c209296
|
@ -289,7 +289,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
|
|||
result = self.client_get("/activity/remote/support")
|
||||
self.assert_in_success_response(
|
||||
[
|
||||
'input type="text" name="q" class="input-xxlarge search-query" placeholder="hostname or contact email"'
|
||||
'input type="text" name="q" class="input-xxlarge search-query" placeholder="hostname, UUID or contact email"'
|
||||
],
|
||||
result,
|
||||
)
|
||||
|
@ -355,6 +355,32 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
|
|||
check_no_sponsorship_request(result)
|
||||
check_legacy_plan_without_upgrade(result)
|
||||
|
||||
# search for UUIDs
|
||||
remote_server = RemoteZulipServer.objects.get(hostname=f"zulip-{server}.example.com")
|
||||
result = self.client_get("/activity/remote/support", {"q": f"{remote_server.uuid}"})
|
||||
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}")
|
||||
|
||||
remote_realm = RemoteRealm.objects.get(host=f"realm-host-{server}")
|
||||
result = self.client_get("/activity/remote/support", {"q": f"{remote_realm.uuid}"})
|
||||
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}")
|
||||
|
||||
server = 0
|
||||
remote_server = RemoteZulipServer.objects.get(hostname=f"zulip-{server}.example.com")
|
||||
result = self.client_get("/activity/remote/support", {"q": f"{remote_server.uuid}"})
|
||||
self.assert_not_in_success_response(
|
||||
['<span class="label">remote server</span>', '<span class="label">remote realm</span>'],
|
||||
result,
|
||||
)
|
||||
|
||||
unknown_uuid = uuid.uuid4()
|
||||
result = self.client_get("/activity/remote/support", {"q": f"{unknown_uuid}"})
|
||||
self.assert_not_in_success_response(
|
||||
['<span class="label">remote server</span>', '<span class="label">remote realm</span>'],
|
||||
result,
|
||||
)
|
||||
|
||||
def test_extend_current_plan_end_date(self) -> None:
|
||||
remote_realm = RemoteRealm.objects.get(name="realm-name-5")
|
||||
customer = Customer.objects.get(remote_realm=remote_realm)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import uuid
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
|
@ -464,13 +465,24 @@ def support(
|
|||
|
||||
|
||||
def get_remote_servers_for_support(
|
||||
email_to_search: Optional[str], hostname_to_search: Optional[str]
|
||||
email_to_search: Optional[str], uuid_to_search: Optional[str], hostname_to_search: Optional[str]
|
||||
) -> List["RemoteZulipServer"]:
|
||||
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))
|
||||
|
||||
if uuid_to_search:
|
||||
remote_servers_set = set(remote_servers_query.filter(uuid__iexact=uuid_to_search))
|
||||
remote_realm_matches = (
|
||||
RemoteRealm.objects.filter(uuid__iexact=uuid_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)
|
||||
|
||||
if hostname_to_search:
|
||||
remote_servers_set = set(
|
||||
remote_servers_query.filter(hostname__icontains=hostname_to_search)
|
||||
|
@ -602,16 +614,23 @@ def remote_servers_support(
|
|||
context["error_message"] = error.msg
|
||||
|
||||
email_to_search = None
|
||||
uuid_to_search = None
|
||||
hostname_to_search = None
|
||||
if query:
|
||||
search_text = query.strip()
|
||||
if "@" in search_text:
|
||||
email_to_search = search_text
|
||||
else:
|
||||
hostname_to_search = search_text
|
||||
try:
|
||||
uuid.UUID(search_text, version=4)
|
||||
uuid_to_search = search_text
|
||||
except ValueError:
|
||||
hostname_to_search = search_text
|
||||
|
||||
remote_servers = get_remote_servers_for_support(
|
||||
email_to_search=email_to_search, hostname_to_search=hostname_to_search
|
||||
email_to_search=email_to_search,
|
||||
uuid_to_search=uuid_to_search,
|
||||
hostname_to_search=hostname_to_search,
|
||||
)
|
||||
remote_server_to_max_monthly_messages: Dict[int, Union[int, str]] = dict()
|
||||
server_support_data: Dict[int, SupportData] = {}
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<div class="container">
|
||||
<form class="support-search-form">
|
||||
<center>
|
||||
<input type="text" name="q" class="input-xxlarge search-query" placeholder="hostname or contact email" value="{{ request.GET.get('q', '') }}" autofocus />
|
||||
<input type="text" name="q" class="input-xxlarge search-query" placeholder="hostname, UUID or contact email" value="{{ request.GET.get('q', '') }}" autofocus />
|
||||
<button type="submit" class="support-search-button">Search</button>
|
||||
</center>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue