support: Add date created field to remove server information.

Removes the last updated field and replaces it with the date the
remote server was created based on the audit log data.
This commit is contained in:
Lauryn Menard 2023-12-28 19:28:36 +01:00 committed by Tim Abbott
parent a03f9078e5
commit b9ca60ab9e
6 changed files with 33 additions and 7 deletions

View File

@ -32,7 +32,7 @@ if TYPE_CHECKING:
import uuid
from zilencer.models import RemoteRealm, RemoteZulipServer
from zilencer.models import RemoteRealm, RemoteZulipServer, RemoteZulipServerAuditLog
class TestRemoteServerSupportEndpoint(ZulipTestCase):
@ -97,6 +97,11 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
remote_server = RemoteZulipServer.objects.create(
hostname=hostname, contact_email=f"admin@{hostname}", uuid=uuid.uuid4()
)
RemoteZulipServerAuditLog.objects.create(
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED,
server=remote_server,
event_time=remote_server.last_updated,
)
# We want at least one RemoteZulipServer that has no RemoteRealm
# as an example of a pre-8.0 release registered remote server.
if i > 1:
@ -108,7 +113,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
uuid=realm_uuid,
host=realm_host,
name=realm_name,
realm_date_created=timezone_now(),
realm_date_created=datetime(2023, 12, 1, tzinfo=timezone.utc),
)
# Add a deactivated server, which should be excluded from search results.
@ -144,7 +149,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
[
f"<h3>{hostname}</h3>",
f"<b>Contact email</b>: admin@{hostname}",
"<b>Last updated</b>:",
"<b>Date created</b>:",
"<b>Zulip version</b>:",
"<b>Plan type</b>: Self-managed<br />",
"<b>Non-guest user count</b>: 0<br />",
@ -161,7 +166,7 @@ class TestRemoteServerSupportEndpoint(ZulipTestCase):
[
f"<h3>{name}</h3>",
f"<b>Remote realm host:</b> {host}<br />",
"<b>Date created</b>: ",
"<b>Date created</b>: 01 December 2023",
"<b>Org type</b>: Unspecified<br />",
"<b>Has remote realm(s)</b>: True<br />",
],

View File

@ -1,4 +1,5 @@
from dataclasses import dataclass
from datetime import datetime
from decimal import Decimal
from typing import Optional, TypedDict
from urllib.parse import urlencode, urljoin, urlunsplit
@ -23,6 +24,7 @@ from zerver.models.realms import get_org_type_display_name, get_realm
from zilencer.lib.remote_counts import MissingDataError
from zilencer.models import (
RemoteCustomerUserCount,
RemoteZulipServerAuditLog,
get_remote_realm_guest_and_non_guest_count,
get_remote_server_guest_and_non_guest_count,
)
@ -61,6 +63,7 @@ class PlanData:
@dataclass
class SupportData:
date_created: datetime
plan_data: PlanData
sponsorship_data: SponsorshipData
user_data: RemoteCustomerUserCount
@ -182,9 +185,14 @@ def get_current_plan_data_for_support_view(billing_session: BillingSession) -> P
def get_data_for_support_view(billing_session: BillingSession) -> SupportData:
if isinstance(billing_session, RemoteServerBillingSession):
user_data = get_remote_server_guest_and_non_guest_count(billing_session.remote_server.id)
date_created = RemoteZulipServerAuditLog.objects.get(
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED,
server__id=billing_session.remote_server.id,
).event_time
else:
assert isinstance(billing_session, RemoteRealmBillingSession)
user_data = get_remote_realm_guest_and_non_guest_count(billing_session.remote_realm)
date_created = billing_session.remote_realm.realm_date_created
plan_data = get_current_plan_data_for_support_view(billing_session)
customer = billing_session.get_customer()
if customer is not None:
@ -193,6 +201,7 @@ def get_data_for_support_view(billing_session: BillingSession) -> SupportData:
sponsorship_data = SponsorshipData()
return SupportData(
date_created=date_created,
plan_data=plan_data,
sponsorship_data=sponsorship_data,
user_data=user_data,

View File

@ -8,7 +8,7 @@
<h4>Has a discount 🟢</h4>
{% endif %}
<b>Remote realm host:</b> {{ remote_realm.host }}<br />
<b>Date created</b>: {{ remote_realm.realm_date_created.strftime('%d %B %Y') }}<br />
<b>Date created</b>: {{ support_data[remote_realm.id].date_created.strftime('%d %B %Y') }}<br />
<b>Org type</b>: {{ get_org_type_display_name(remote_realm.org_type) }}<br />
<b>Plan type</b>: {{ get_plan_type_name(remote_realm.plan_type) }}<br />
<b>Non-guest user count</b>: {{ support_data[remote_realm.id].user_data.non_guest_user_count }}<br />

View File

@ -49,7 +49,7 @@
<i class="fa fa-copy"></i>
</a>
<br />
<b>Last updated</b>: {{ remote_server.last_updated|timesince }} ago<br />
<b>Date created</b>: {{ remote_servers_support_data[remote_server.id].date_created.strftime('%d %B %Y') }}<br />
<b>Zulip version</b>: {{ remote_server.last_version }}<br />
<b>Max monthly messages</b>: {{ remote_server_to_max_monthly_messages[remote_server.id] }}<br />
<b>Plan type</b>: {{ get_plan_type_name(remote_server.plan_type) }}<br />

View File

@ -33,6 +33,7 @@ from zilencer.models import (
RemoteRealmBillingUser,
RemoteServerBillingUser,
RemoteZulipServer,
RemoteZulipServerAuditLog,
)
from zilencer.views import update_remote_realm_data_for_server
from zproject.config import get_secret
@ -421,6 +422,12 @@ def populate_remote_server(customer_profile: CustomerProfile) -> Dict[str, str]:
last_audit_log_update=timezone_now(),
)
RemoteZulipServerAuditLog.objects.create(
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED,
server=remote_server,
event_time=remote_server.last_updated,
)
billing_user = RemoteServerBillingUser.objects.create(
full_name="Server user",
remote_server=remote_server,

View File

@ -71,7 +71,7 @@ from zerver.models.realms import get_realm
from zerver.models.recipients import get_or_create_huddle
from zerver.models.streams import get_stream
from zerver.models.users import get_user, get_user_by_delivery_email, get_user_profile_by_id
from zilencer.models import RemoteRealm, RemoteZulipServer
from zilencer.models import RemoteRealm, RemoteZulipServer, RemoteZulipServerAuditLog
from zilencer.views import update_remote_realm_data_for_server
settings.USING_TORNADO = False
@ -390,6 +390,11 @@ class Command(BaseCommand):
last_updated=timezone_now(),
contact_email="remotezulipserver@zulip.com",
)
RemoteZulipServerAuditLog.objects.create(
event_type=RemoteZulipServerAuditLog.REMOTE_SERVER_CREATED,
server=server,
event_time=server.last_updated,
)
update_remote_realm_data_for_server(server, get_realms_info_for_push_bouncer())
# Create test Users (UserProfiles are automatically created,