Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
installation-activity: Add export version of chart.
Lauryn Menard55d7ec843e65
diff --git a/corporate/views/installation_activity.py b/corporate/views/installation_activity.pyindex d4ed71d703e..72a6a27c938 100644--- a/corporate/views/installation_activity.py+++ b/corporate/views/installation_activity.py@@ -1,4 +1,5 @@from collections import defaultdict+from typing import Anyfrom django.conf import settingsfrom django.db import connection@@ -8,6 +9,7 @@ from django.template import loaderfrom django.utils.timezone import now as timezone_nowfrom markupsafe import Markupfrom psycopg2.sql import SQL+from pydantic import Jsonfrom analytics.lib.counts import COUNT_STATSfrom corporate.lib.activity import (@@ -26,10 +28,11 @@ from corporate.lib.activity import (from corporate.lib.stripe import cents_to_dollar_stringfrom corporate.views.support import get_plan_type_stringfrom zerver.decorator import require_server_admin-from zerver.lib.typed_endpoint import typed_endpoint_without_parameters+from zerver.lib.typed_endpoint import typed_endpointfrom zerver.models import Realmfrom zerver.models.realm_audit_logs import AuditLogEventTypefrom zerver.models.realms import get_org_type_display_name+from zerver.models.users import UserProfiledef get_realm_day_counts() -> dict[str, dict[str, Markup]]:@@ -88,7 +91,7 @@ def get_realm_day_counts() -> dict[str, dict[str, Markup]]:return result-def realm_summary_table() -> str:+def realm_summary_table(export: bool) -> str:now = timezone_now()query = SQL(@@ -103,7 +106,8 @@ def realm_summary_table() -> str:coalesce(user_count_table.value, 0) user_profile_count,coalesce(bot_count_table.value, 0) bot_count,coalesce(realm_audit_log_table.how_realm_creator_found_zulip, '') how_realm_creator_found_zulip,- coalesce(realm_audit_log_table.how_realm_creator_found_zulip_extra_context, '') how_realm_creator_found_zulip_extra_context+ coalesce(realm_audit_log_table.how_realm_creator_found_zulip_extra_context, '') how_realm_creator_found_zulip_extra_context,+ realm_admin_user.delivery_email admin_emailFROMzerver_realm as realmLEFT OUTER JOIN (@@ -168,6 +172,17 @@ def realm_summary_table() -> str:WHEREevent_type = %(realm_creation_event_type)s) as realm_audit_log_table ON realm.id = realm_audit_log_table.realm_id+ LEFT OUTER JOIN (+ SELECT+ delivery_email,+ realm_id+ from+ zerver_userprofile+ WHERE+ is_bot=False+ AND is_active=True+ AND role IN %(admin_roles)s+ ) as realm_admin_user ON realm.id = realm_admin_user.realm_idWHERE_14day_active_humans IS NOT NULLor realm.plan_type = 3@@ -190,11 +205,25 @@ def realm_summary_table() -> str:"active_users_audit:is_bot:day"].last_successful_fill(),"realm_creation_event_type": AuditLogEventType.REALM_CREATED,+ "admin_roles": (UserProfile.ROLE_REALM_ADMINISTRATOR, UserProfile.ROLE_REALM_OWNER),},)- rows = dictfetchall(cursor)+ raw_rows = dictfetchall(cursor)cursor.close()+ rows: list[dict[str, Any]] = []+ admin_emails: dict[str, str] = {}+ # Process duplicate realm rows due to multiple admin users,+ # and collect all admin user emails into one string.+ for row in raw_rows:+ realm_string_id = row["string_id"]+ admin_email = row.pop("admin_email")+ if realm_string_id in admin_emails:+ admin_emails[realm_string_id] = admin_emails[realm_string_id] + ", " + admin_email+ else:+ admin_emails[realm_string_id] = admin_email+ rows.append(row)+realm_messages_per_day_counts = get_realm_day_counts()total_arr = 0num_active_sites = 0@@ -253,6 +282,10 @@ def realm_summary_table() -> str:total_bot_count += int(row["bot_count"])total_wau_count += int(row["wau_count"])+ # Add admin users email string+ if export:+ row["admin_emails"] = admin_emails[realm_string_id]+total_row = ["Total","",@@ -277,6 +310,9 @@ def realm_summary_table() -> str:"",]+ if export:+ total_row.pop(1)+content = loader.render_to_string("corporate/activity/installation_activity_table.html",dict(@@ -285,15 +321,16 @@ def realm_summary_table() -> str:num_active_sites=num_active_sites,utctime=now.strftime("%Y-%m-%d %H:%M %Z"),billing_enabled=settings.BILLING_ENABLED,+ export=export,),)return content@require_server_admin-@typed_endpoint_without_parameters-def get_installation_activity(request: HttpRequest) -> HttpResponse:- content: str = realm_summary_table()+@typed_endpoint+def get_installation_activity(request: HttpRequest, *, export: Json[bool] = False) -> HttpResponse:+ content: str = realm_summary_table(export)title = "Installation activity"return render(diff --git a/templates/corporate/activity/installation_activity_table.html b/templates/corporate/activity/installation_activity_table.htmlindex c20243939df..7f5bad81e1f 100644--- a/templates/corporate/activity/installation_activity_table.html+++ b/templates/corporate/activity/installation_activity_table.html@@ -2,11 +2,16 @@<p class="installation-activity-header">{{ utctime }}</p>-<h4>Installation information:</h4>+<h4>Other views:</h4><ul><li><a href="/stats/installation">Server total /stats style graphs</a></li><li><a href="/activity/remote">Remote servers</a></li><li><a href="/activity/integrations">Integrations by client</a></li>+ {% if not export %}+ <li><a href="/activity?export=true">Export installation chart</a></li>+ {% else %}+ <li><a href="/activity">Non-export installation chart</a></li>+ {% endif %}</ul><h4>Counts chart key:</h4>@@ -33,7 +38,9 @@<thead class="activity-head"><tr>+ {% if not export %}<th>Links</th>+ {% endif %}<th>Realm</th><th>Created (green if ≤12wk)</th>{% if billing_enabled %}@@ -47,21 +54,26 @@<th>WAU</th><th>Total users</th><th>Bots</th>+ {% if not export %}<th></th>+ {% endif %}<th colspan=8>Human messages sent, last 8 UTC days (today-so-far first)</th>+ {% if export %}+ <th>Admin emails</th>+ {% endif %}</tr></thead><tbody>{% for row in rows %}<tr>-+ {% if not export %}<td>{{ row.realm_url }}{{ row.stats_link }}{{ row.support_link }}</td>-+ {% endif %}<td>{{ row.activity_link }}</td>@@ -113,14 +125,20 @@<td class="number">{{ row.bot_count }}</td>-+ {% if not export %}<td> </td>-+ {% endif %}{% if row.history %}{{ row.history|safe }}{% else %}<td colspan=8></td>{% endif %}++ {% if export %}+ <td>+ {{ row.admin_emails }}+ </td>+ {% endif %}</tr>{% endfor %}</tbody>