mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
support: Add active plan information to remote server activity.
Adds three columns to the remote server activity chart and updates the chart key for the third of those columns. The first is the plan name. If there are multiple plans with a status under the live threshhold, then we send "See support view". The second is the plan status. If there are multiple plans, then we send "Multiple plans". The third is the estimated annual revenue for the plan. Note that for free trials, this will be calculated as if the plan was paid for 12 months (so a full year). If there is no plan for the server under the live threshold or at all then "---" is inserted into the table row. Note that 100% sponsored servers/realms would fall into this category.
This commit is contained in:
committed by
Tim Abbott
parent
484c0df076
commit
a897d68d93
@@ -1,11 +1,18 @@
|
||||
import uuid
|
||||
from datetime import timedelta
|
||||
from unittest import mock
|
||||
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from corporate.lib.stripe import add_months
|
||||
from corporate.models import Customer, CustomerPlan, LicenseLedger
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.models import Client, UserActivity, UserProfile
|
||||
from zilencer.models import RemoteRealmAuditLog, get_remote_server_guest_and_non_guest_count
|
||||
from zilencer.models import (
|
||||
RemoteRealmAuditLog,
|
||||
RemoteZulipServer,
|
||||
get_remote_server_guest_and_non_guest_count,
|
||||
)
|
||||
|
||||
event_time = timezone_now() - timedelta(days=3)
|
||||
data_list = [
|
||||
@@ -99,8 +106,32 @@ class ActivityTest(ZulipTestCase):
|
||||
result = self.client_get("/activity")
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
# Add data for remote activity page
|
||||
RemoteRealmAuditLog.objects.bulk_create([RemoteRealmAuditLog(**data) for data in data_list])
|
||||
with self.assert_database_query_count(6):
|
||||
remote_server = RemoteZulipServer.objects.get(id=1)
|
||||
customer = Customer.objects.create(remote_server=remote_server)
|
||||
plan = CustomerPlan.objects.create(
|
||||
customer=customer,
|
||||
billing_cycle_anchor=timezone_now(),
|
||||
billing_schedule=CustomerPlan.BILLING_SCHEDULE_ANNUAL,
|
||||
tier=CustomerPlan.TIER_SELF_HOSTED_BUSINESS,
|
||||
price_per_license=8000,
|
||||
next_invoice_date=add_months(timezone_now(), 12),
|
||||
)
|
||||
LicenseLedger.objects.create(
|
||||
licenses=10,
|
||||
licenses_at_next_renewal=10,
|
||||
event_time=timezone_now(),
|
||||
is_renewal=True,
|
||||
plan=plan,
|
||||
)
|
||||
RemoteZulipServer.objects.create(
|
||||
uuid=str(uuid.uuid4()),
|
||||
api_key="magic_secret_api_key",
|
||||
hostname="demo.example.com",
|
||||
contact_email="email@example.com",
|
||||
)
|
||||
with self.assert_database_query_count(10):
|
||||
result = self.client_get("/activity/remote")
|
||||
self.assertEqual(result.status_code, 200)
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ from analytics.views.activity_common import (
|
||||
remote_installation_stats_link,
|
||||
remote_installation_support_link,
|
||||
)
|
||||
from corporate.lib.analytics import get_plan_data_by_remote_server
|
||||
from zerver.decorator import require_server_admin
|
||||
from zilencer.models import get_remote_server_guest_and_non_guest_count
|
||||
|
||||
@@ -83,6 +84,9 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
|
||||
"Mobile users",
|
||||
"Last update time",
|
||||
"Mobile pushes forwarded",
|
||||
"Plan name",
|
||||
"Plan status",
|
||||
"ARR",
|
||||
"Non guest users",
|
||||
"Guest users",
|
||||
"Links",
|
||||
@@ -91,13 +95,27 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
|
||||
rows = get_query_data(query)
|
||||
total_row = []
|
||||
totals_columns = [4, 5]
|
||||
plan_data_by_remote_server = get_plan_data_by_remote_server()
|
||||
|
||||
for row in rows:
|
||||
stats = remote_installation_stats_link(row[0])
|
||||
support = remote_installation_support_link(row[1])
|
||||
links = stats + " " + support
|
||||
# Add estimated revenue for server
|
||||
server_plan_data = plan_data_by_remote_server.get(row[0])
|
||||
if server_plan_data is None:
|
||||
row.append("---")
|
||||
row.append("---")
|
||||
row.append("---")
|
||||
else:
|
||||
row.append(server_plan_data.current_plan_name)
|
||||
row.append(server_plan_data.current_status)
|
||||
row.append(server_plan_data.annual_revenue)
|
||||
# Add user counts
|
||||
remote_server_counts = get_remote_server_guest_and_non_guest_count(row[0])
|
||||
row.append(remote_server_counts.non_guest_user_count)
|
||||
row.append(remote_server_counts.guest_user_count)
|
||||
# Add links
|
||||
stats = remote_installation_stats_link(row[0])
|
||||
support = remote_installation_support_link(row[1])
|
||||
links = stats + " " + support
|
||||
row.append(links)
|
||||
for i, col in enumerate(cols):
|
||||
if col == "Last update time":
|
||||
|
||||
Reference in New Issue
Block a user