mirror of https://github.com/zulip/zulip.git
remote-support: Add ability to search by billing user email.
This commit is contained in:
parent
1f72ab5133
commit
1914b881d9
|
@ -40,6 +40,8 @@ import uuid
|
||||||
from zilencer.models import (
|
from zilencer.models import (
|
||||||
RemoteRealm,
|
RemoteRealm,
|
||||||
RemoteRealmAuditLog,
|
RemoteRealmAuditLog,
|
||||||
|
RemoteRealmBillingUser,
|
||||||
|
RemoteServerBillingUser,
|
||||||
RemoteZulipServer,
|
RemoteZulipServer,
|
||||||
RemoteZulipServerAuditLog,
|
RemoteZulipServerAuditLog,
|
||||||
)
|
)
|
||||||
|
@ -159,6 +161,15 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
|
||||||
# without upgrade scheduled
|
# without upgrade scheduled
|
||||||
add_legacy_plan(name="realm-name-5", upgrade=False)
|
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 test_search(self) -> None:
|
||||||
def assert_server_details_in_response(
|
def assert_server_details_in_response(
|
||||||
html_response: "TestHttpResponse", hostname: str
|
html_response: "TestHttpResponse", hostname: str
|
||||||
|
@ -168,6 +179,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
|
||||||
'<span class="label">remote server</span>',
|
'<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>Billing users</b>:",
|
||||||
"<b>Date created</b>:",
|
"<b>Date created</b>:",
|
||||||
"<b>UUID</b>:",
|
"<b>UUID</b>:",
|
||||||
"<b>Zulip version</b>:",
|
"<b>Zulip version</b>:",
|
||||||
|
@ -278,6 +290,15 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
|
||||||
result,
|
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")
|
self.login("cordelia")
|
||||||
|
|
||||||
result = self.client_get("/activity/remote/support")
|
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_server_details_in_response(result, f"zulip-{server}.example.com")
|
||||||
assert_realm_details_in_response(result, f"realm-name-{server}", f"realm-host-{server}")
|
assert_realm_details_in_response(result, f"realm-name-{server}", f"realm-host-{server}")
|
||||||
check_sponsorship_request_with_website(result)
|
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
|
server = 4
|
||||||
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"})
|
||||||
|
|
|
@ -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.models.users import get_user_profile_by_id
|
||||||
from zerver.views.invite import get_invitee_emails_set
|
from zerver.views.invite import get_invitee_emails_set
|
||||||
from zilencer.lib.remote_counts import MissingDataError, compute_max_monthly_messages
|
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):
|
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)
|
remote_servers_query = RemoteZulipServer.objects.order_by("id").exclude(deactivated=True)
|
||||||
|
|
||||||
if email_to_search:
|
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:
|
if uuid_to_search:
|
||||||
remote_servers_set = set(remote_servers_query.filter(uuid__iexact=uuid_to_search))
|
remote_servers_set = set(remote_servers_query.filter(uuid__iexact=uuid_to_search))
|
||||||
|
|
Loading…
Reference in New Issue