diff --git a/analytics/management/commands/populate_analytics_db.py b/analytics/management/commands/populate_analytics_db.py index 47d4cdeadd..bbe82b5c7f 100644 --- a/analytics/management/commands/populate_analytics_db.py +++ b/analytics/management/commands/populate_analytics_db.py @@ -92,6 +92,16 @@ class Command(BaseCommand): ) do_change_user_role(shylock, UserProfile.ROLE_REALM_OWNER, acting_user=None) + # Create guest user for set_guest_users_statistic. + create_user( + "bassanio@analytics.ds", + "Bassanio", + realm, + full_name="Bassanio", + role=UserProfile.ROLE_GUEST, + force_date_joined=installation_time, + ) + administrators_user_group = UserGroup.objects.get( name=UserGroup.ADMINISTRATORS_GROUP_NAME, realm=realm, is_system_group=True ) diff --git a/analytics/views/stats.py b/analytics/views/stats.py index d2f9ebd4cf..4e2c61310e 100644 --- a/analytics/views/stats.py +++ b/analytics/views/stats.py @@ -55,11 +55,18 @@ def render_stats( analytics_ready: bool = True, ) -> HttpResponse: assert request.user.is_authenticated + + # Same query to get guest user count as in get_seat_count in corporate/lib/stripe.py. + guest_users = UserProfile.objects.filter( + realm=request.user.realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST + ).count() + page_params = dict( data_url_suffix=data_url_suffix, for_installation=for_installation, remote=remote, upload_space_used=request.user.realm.currently_used_upload_space_bytes(), + guest_users=guest_users, ) request_language = get_and_set_request_language( diff --git a/corporate/lib/stripe.py b/corporate/lib/stripe.py index 878ce85feb..eb32515c45 100644 --- a/corporate/lib/stripe.py +++ b/corporate/lib/stripe.py @@ -69,6 +69,8 @@ def get_seat_count( .exclude(role=UserProfile.ROLE_GUEST) .count() ) + extra_non_guests_count + + # This guest count calculation should match the similar query in render_stats(). guests = ( UserProfile.objects.filter( realm=realm, is_active=True, is_bot=False, role=UserProfile.ROLE_GUEST diff --git a/static/js/stats/stats.js b/static/js/stats/stats.js index 059192f316..3bf81fbda1 100644 --- a/static/js/stats/stats.js +++ b/static/js/stats/stats.js @@ -194,6 +194,13 @@ function set_storage_space_used_statistic(upload_space_used) { $("#id_storage_space_used").closest("summary-stats").show(); } +function set_guest_users_statistic(guest_users) { + const guest_users_string = guest_users.toLocaleString(); + + $("#id_guest_users_count").text(guest_users_string); + $("#id_guest_users_count").closest("summary-stats").show(); +} + // PLOTLY CHARTS function populate_messages_sent_over_time(data) { if (data.end_times.length === 0) { @@ -1116,3 +1123,4 @@ get_chart_data( ); set_storage_space_used_statistic(page_params.upload_space_used); +set_guest_users_statistic(page_params.guest_users); diff --git a/templates/analytics/stats.html b/templates/analytics/stats.html index 4c30fe1200..e4b87b0495 100644 --- a/templates/analytics/stats.html +++ b/templates/analytics/stats.html @@ -26,6 +26,7 @@