From d1e7c082b3dc11feec0119eef29122f5a2ffcfaa Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Wed, 28 Aug 2024 16:39:03 +0200 Subject: [PATCH] activity: Add header area to user activity view. --- corporate/lib/activity.py | 11 +++++++++-- corporate/views/realm_activity.py | 2 +- corporate/views/user_activity.py | 18 +++++++++++++++--- .../corporate/activity/activity_table.html | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/corporate/lib/activity.py b/corporate/lib/activity.py index 01cd25e940..b84c508779 100644 --- a/corporate/lib/activity.py +++ b/corporate/lib/activity.py @@ -55,7 +55,7 @@ def make_table( *, header: list[ActivityHeaderEntry] | None = None, totals: Any | None = None, - stats_link: Markup | None = None, + title_link: Markup | None = None, has_row_class: bool = False, ) -> str: if not has_row_class: @@ -66,7 +66,7 @@ def make_table( rows = list(map(fix_row, rows)) data = dict( - title=title, cols=cols, rows=rows, header=header, totals=totals, stats_link=stats_link + title=title, cols=cols, rows=rows, header=header, totals=totals, title_link=title_link ) content = loader.render_to_string( @@ -142,6 +142,13 @@ def realm_stats_link(realm_str: str) -> Markup: return Markup('').format(url=url) +def user_support_link(email: str) -> Markup: + support_url = reverse("support") + query = urlencode({"q": email}) + url = append_url_query_string(support_url, query) + return Markup('').format(url=url) + + def realm_support_link(realm_str: str) -> Markup: support_url = reverse("support") query = urlencode({"q": realm_str}) diff --git a/corporate/views/realm_activity.py b/corporate/views/realm_activity.py index f3896ad140..1efcf1ecdf 100644 --- a/corporate/views/realm_activity.py +++ b/corporate/views/realm_activity.py @@ -146,7 +146,7 @@ def realm_user_summary_table( return row["cells"][4] rows = sorted(rows, key=by_last_heard_from, reverse=True) - content = make_table(title, cols, rows, stats_link=stats_link, has_row_class=True) + content = make_table(title, cols, rows, title_link=stats_link, has_row_class=True) return content diff --git a/corporate/views/user_activity.py b/corporate/views/user_activity.py index c89fc49d4b..94a25f4377 100644 --- a/corporate/views/user_activity.py +++ b/corporate/views/user_activity.py @@ -4,7 +4,12 @@ from django.db.models import QuerySet from django.http import HttpRequest, HttpResponse from django.shortcuts import render -from corporate.lib.activity import format_optional_datetime, make_table +from corporate.lib.activity import ( + ActivityHeaderEntry, + format_optional_datetime, + make_table, + user_support_link, +) from zerver.decorator import require_server_admin from zerver.models import UserActivity, UserProfile from zerver.models.users import get_user_profile_by_id @@ -36,6 +41,7 @@ def get_user_activity(request: HttpRequest, user_profile_id: int) -> HttpRespons user_profile = get_user_profile_by_id(user_profile_id) records = get_user_activity_records(user_profile) + title = f"{user_profile.full_name}" cols = [ "Query", "Client", @@ -52,8 +58,14 @@ def get_user_activity(request: HttpRequest, user_profile_id: int) -> HttpRespons ] rows = list(map(row, records)) - title = f"{user_profile.delivery_email} ({user_profile.realm.name})" - content = make_table(title, cols, rows) + + header_entries = [] + header_entries.append(ActivityHeaderEntry(name="Email", value=user_profile.delivery_email)) + header_entries.append(ActivityHeaderEntry(name="Realm", value=user_profile.realm.name)) + + user_support = user_support_link(user_profile.delivery_email) + + content = make_table(title, cols, rows, header=header_entries, title_link=user_support) return render( request, diff --git a/templates/corporate/activity/activity_table.html b/templates/corporate/activity/activity_table.html index 2fba6b71f1..bd3cc033ea 100644 --- a/templates/corporate/activity/activity_table.html +++ b/templates/corporate/activity/activity_table.html @@ -1,4 +1,4 @@ -

{{ data.title }} {% if data.stats_link %}{{ data.stats_link }}{% endif %}

+

{{ data.title }} {% if data.title_link %}{{ data.title_link }}{% endif %}

{% if data.title == "Remote servers" %} {% include "corporate/activity/remote_activity_key.html" %}