mirror of https://github.com/zulip/zulip.git
analytics: Pass the right value for realm.
This commit is contained in:
parent
51737b8905
commit
0e10ccc137
|
@ -49,23 +49,35 @@ def is_analytics_ready(realm: Realm) -> bool:
|
||||||
def render_stats(
|
def render_stats(
|
||||||
request: HttpRequest,
|
request: HttpRequest,
|
||||||
data_url_suffix: str,
|
data_url_suffix: str,
|
||||||
target_name: str,
|
realm: Optional[Realm],
|
||||||
|
*,
|
||||||
|
title: Optional[str] = None,
|
||||||
for_installation: bool = False,
|
for_installation: bool = False,
|
||||||
remote: bool = False,
|
remote: bool = False,
|
||||||
analytics_ready: bool = True,
|
analytics_ready: bool = True,
|
||||||
) -> HttpResponse:
|
) -> HttpResponse:
|
||||||
assert request.user.is_authenticated
|
assert request.user.is_authenticated
|
||||||
|
|
||||||
# Same query to get guest user count as in get_seat_count in corporate/lib/stripe.py.
|
if realm is not None:
|
||||||
guest_users = UserProfile.objects.filter(
|
# Same query to get guest user count as in get_seat_count in corporate/lib/stripe.py.
|
||||||
realm=request.user.realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST
|
guest_users = UserProfile.objects.filter(
|
||||||
).count()
|
realm=realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST
|
||||||
|
).count()
|
||||||
|
space_used = realm.currently_used_upload_space_bytes()
|
||||||
|
if title:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
title = realm.name or realm.string_id
|
||||||
|
else:
|
||||||
|
assert title
|
||||||
|
guest_users = None
|
||||||
|
space_used = None
|
||||||
|
|
||||||
page_params = dict(
|
page_params = dict(
|
||||||
data_url_suffix=data_url_suffix,
|
data_url_suffix=data_url_suffix,
|
||||||
for_installation=for_installation,
|
for_installation=for_installation,
|
||||||
remote=remote,
|
remote=remote,
|
||||||
upload_space_used=request.user.realm.currently_used_upload_space_bytes(),
|
upload_space_used=space_used,
|
||||||
guest_users=guest_users,
|
guest_users=guest_users,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,7 +93,9 @@ def render_stats(
|
||||||
request,
|
request,
|
||||||
"analytics/stats.html",
|
"analytics/stats.html",
|
||||||
context=dict(
|
context=dict(
|
||||||
target_name=target_name, page_params=page_params, analytics_ready=analytics_ready
|
target_name=title,
|
||||||
|
page_params=page_params,
|
||||||
|
analytics_ready=analytics_ready,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -94,9 +108,7 @@ def stats(request: HttpRequest) -> HttpResponse:
|
||||||
# TODO: Make @zulip_login_required pass the UserProfile so we
|
# TODO: Make @zulip_login_required pass the UserProfile so we
|
||||||
# can use @require_member_or_admin
|
# can use @require_member_or_admin
|
||||||
raise JsonableError(_("Not allowed for guest users"))
|
raise JsonableError(_("Not allowed for guest users"))
|
||||||
return render_stats(
|
return render_stats(request, "", realm, analytics_ready=is_analytics_ready(realm))
|
||||||
request, "", realm.name or realm.string_id, analytics_ready=is_analytics_ready(realm)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@require_server_admin
|
@require_server_admin
|
||||||
|
@ -110,7 +122,7 @@ def stats_for_realm(request: HttpRequest, realm_str: str) -> HttpResponse:
|
||||||
return render_stats(
|
return render_stats(
|
||||||
request,
|
request,
|
||||||
f"/realm/{realm_str}",
|
f"/realm/{realm_str}",
|
||||||
realm.name or realm.string_id,
|
realm,
|
||||||
analytics_ready=is_analytics_ready(realm),
|
analytics_ready=is_analytics_ready(realm),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -125,7 +137,8 @@ def stats_for_remote_realm(
|
||||||
return render_stats(
|
return render_stats(
|
||||||
request,
|
request,
|
||||||
f"/remote/{server.id}/realm/{remote_realm_id}",
|
f"/remote/{server.id}/realm/{remote_realm_id}",
|
||||||
f"Realm {remote_realm_id} on server {server.hostname}",
|
None,
|
||||||
|
title=f"Realm {remote_realm_id} on server {server.hostname}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -166,7 +179,8 @@ def get_chart_data_for_remote_realm(
|
||||||
|
|
||||||
@require_server_admin
|
@require_server_admin
|
||||||
def stats_for_installation(request: HttpRequest) -> HttpResponse:
|
def stats_for_installation(request: HttpRequest) -> HttpResponse:
|
||||||
return render_stats(request, "/installation", "installation", True)
|
assert request.user.is_authenticated
|
||||||
|
return render_stats(request, "/installation", None, title="installation", for_installation=True)
|
||||||
|
|
||||||
|
|
||||||
@require_server_admin
|
@require_server_admin
|
||||||
|
@ -176,9 +190,10 @@ def stats_for_remote_installation(request: HttpRequest, remote_server_id: int) -
|
||||||
return render_stats(
|
return render_stats(
|
||||||
request,
|
request,
|
||||||
f"/remote/{server.id}/installation",
|
f"/remote/{server.id}/installation",
|
||||||
f"remote installation {server.hostname}",
|
None,
|
||||||
True,
|
title=f"remote installation {server.hostname}",
|
||||||
True,
|
for_installation=True,
|
||||||
|
remote=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue