remote-activity: Update column data for remote realms.

Combines the IDs for the remote realm and remote server in the
first column.

Moves the Realm name to the second column.

For the host/hostname column, displays the remote realm host if
it is a remote realm row. Otherwise, the remote server hostname
is displayed.
This commit is contained in:
Lauryn Menard 2024-01-22 18:00:04 +01:00 committed by Tim Abbott
parent fca9ff1ae7
commit 1249b5929e
1 changed files with 54 additions and 29 deletions

View File

@ -51,7 +51,8 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
server_id,
id as realm_id,
name as realm_name,
org_type as realm_type
org_type as realm_type,
host as realm_host
from zilencer_remoterealm
where
is_system_bot_realm = False
@ -60,14 +61,15 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
)
select
rserver.id,
realm_id,
realm_name,
rserver.hostname,
realm_host,
rserver.contact_email,
rserver.last_version,
rserver.last_audit_log_update,
push_user_count,
push_forwarded_count,
realm_id,
realm_name,
realm_type
from zilencer_remotezulipserver rserver
left join mobile_push_forwarded_count on mobile_push_forwarded_count.server_id = rserver.id
@ -79,15 +81,14 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
)
cols = [
"Server ID",
"Server hostname",
"IDs",
"Realm name",
"Realm host or server hostname",
"Server contact email",
"Server Zulip version",
"Server last audit log update",
"Server mobile users",
"Server mobile pushes",
"Realm ID",
"Realm name",
"Realm organization type",
"Plan name",
"Plan status",
@ -97,17 +98,17 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
"Links",
]
# If the column order above changes, update the constants below
SERVER_ID = 0
SERVER_HOSTNAME = 1
LAST_AUDIT_LOG_DATE = 4
MOBILE_USER_COUNT = 5
MOBILE_PUSH_COUNT = 6
REALM_ID = 7
ORG_TYPE = 9
ARR = 12
TOTAL_USER_COUNT = 13
GUEST_COUNT = 14
# If the query or column order above changes, update the constants below
SERVER_AND_REALM_IDS = 0
SERVER_HOST = 2
REALM_HOST = 3
LAST_AUDIT_LOG_DATE = 5
MOBILE_USER_COUNT = 6
MOBILE_PUSH_COUNT = 7
ORG_TYPE = 8
ARR = 11
TOTAL_USER_COUNT = 12
GUEST_COUNT = 13
rows = get_query_data(query)
plan_data_by_remote_server = get_plan_data_by_remote_server()
@ -122,30 +123,51 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
total_pushes = 0
for row in rows:
# Create combined IDs column with server and realm IDs
server_id = row.pop(SERVER_AND_REALM_IDS)
realm_id = row.pop(SERVER_AND_REALM_IDS)
if realm_id is not None:
ids_string = f"{server_id}/{realm_id}"
else:
ids_string = f"{server_id}"
row.insert(SERVER_AND_REALM_IDS, ids_string)
# Get server_host for support link
# For remote realm row, remove server hostname value;
# for remote server row, remove None realm host value
if realm_id is not None:
server_host = row.pop(SERVER_HOST)
else:
row.pop(REALM_HOST)
server_host = row[SERVER_HOST]
# Count mobile users and pushes forwarded, once per server
if row[SERVER_ID] not in remote_server_mobile_data_counted:
if server_id not in remote_server_mobile_data_counted:
if row[MOBILE_USER_COUNT] is not None:
total_mobile_users += row[MOBILE_USER_COUNT] # nocoverage
if row[MOBILE_PUSH_COUNT] is not None:
total_pushes += row[MOBILE_PUSH_COUNT] # nocoverage
remote_server_mobile_data_counted.add(row[SERVER_ID])
if row[REALM_ID] is None:
plan_data = plan_data_by_remote_server.get(row[SERVER_ID])
audit_log_list = audit_logs_by_remote_server.get(row[SERVER_ID])
remote_server_mobile_data_counted.add(server_id)
# Get plan, revenue and user count data for row
if realm_id is None:
plan_data = plan_data_by_remote_server.get(server_id)
audit_log_list = audit_logs_by_remote_server.get(server_id)
if audit_log_list is None:
user_counts = None # nocoverage
else:
user_counts = get_remote_customer_user_count(audit_log_list)
else:
server_remote_realms_data = plan_data_by_remote_server_and_realm.get(row[SERVER_ID])
server_remote_realms_data = plan_data_by_remote_server_and_realm.get(server_id)
if server_remote_realms_data is not None:
plan_data = server_remote_realms_data.get(row[REALM_ID])
plan_data = server_remote_realms_data.get(realm_id)
else:
plan_data = None # nocoverage
user_counts = remote_realm_user_counts.get(row[REALM_ID])
user_counts = remote_realm_user_counts.get(realm_id)
# Format organization type for realm
org_type = row[ORG_TYPE]
row[ORG_TYPE] = get_org_type_display_name(org_type)
# Add estimated annual revenue and plan data
if plan_data is None:
row.append("---")
@ -157,6 +179,7 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
row.append(plan_data.current_plan_name)
row.append(plan_data.current_status)
row.append(f"${revenue}")
# Add user counts
if user_counts is None:
row.append(0)
@ -165,18 +188,20 @@ def get_remote_server_activity(request: HttpRequest) -> HttpResponse:
total_users = user_counts.non_guest_user_count + user_counts.guest_user_count
row.append(total_users)
row.append(user_counts.guest_user_count)
# Add server links
stats = remote_installation_stats_link(row[SERVER_ID])
support = remote_installation_support_link(row[SERVER_HOSTNAME])
stats = remote_installation_stats_link(server_id)
support = remote_installation_support_link(server_host)
links = stats + " " + support
row.append(links)
# Format column data and add total row
for i, col in enumerate(cols):
if i == LAST_AUDIT_LOG_DATE:
fix_rows(rows, i, format_date_for_activity_reports)
if i in [MOBILE_USER_COUNT, MOBILE_PUSH_COUNT]:
fix_rows(rows, i, format_none_as_zero)
if i == SERVER_ID:
if i == SERVER_AND_REALM_IDS:
total_row.append("Total")
elif i == MOBILE_USER_COUNT:
total_row.append(str(total_mobile_users))