From fb528f03a8e3ef934ed26f608abd09d399651122 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Thu, 16 Oct 2025 14:39:01 -0700 Subject: [PATCH] Add organization message usage and service counts to dashboard - Fetch organization message allowance from API endpoint - Display messages sent, remaining, and total limit on dashboard - Add service count statistics (total, live, trial, suspended) - Pass message usage data to template for chart visualization --- app/main/views/organizations.py | 28 +++++++++++++++++-- app/notify_client/service_api_client.py | 5 ++++ .../organizations/organization/index.html | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/app/main/views/organizations.py b/app/main/views/organizations.py index a1fa0d9f1..f067a94be 100644 --- a/app/main/views/organizations.py +++ b/app/main/views/organizations.py @@ -5,7 +5,12 @@ from functools import partial from flask import current_app, flash, redirect, render_template, request, url_for from flask_login import current_user -from app import current_organization, org_invite_api_client, organizations_client +from app import ( + current_organization, + org_invite_api_client, + organizations_client, + service_api_client, +) from app.main import main from app.main.forms import ( AdminBillingDetailsForm, @@ -92,10 +97,29 @@ def organization_dashboard(org_id): year = requested_and_current_financial_year(request)[0] - # TODO: total message allowance + try: + message_usage = service_api_client.get_organization_message_usage(org_id) + except Exception as e: + current_app.logger.error(f"Error fetching organization message usage: {e}") + message_usage = {} + + messages_sent = message_usage.get("messages_sent", 0) + messages_remaining = message_usage.get("messages_remaining", 0) + total_message_limit = message_usage.get("total_message_limit", 0) + + services = current_organization.services + service_counts = get_service_counts_by_status(services) + return render_template( "views/organizations/organization/index.html", selected_year=year, + messages_sent=messages_sent, + messages_remaining=messages_remaining, + total_message_limit=total_message_limit, + total_services=service_counts["total"], + live_services=service_counts["live"], + trial_services=service_counts["trial"], + suspended_services=service_counts["suspended"], ) diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index 97d94cae4..3b238acbf 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -561,6 +561,11 @@ class ServiceAPIClient(NotifyAdminAPIClient): url="service/get-service-message-ratio?service_id={0}".format(service_id), ) + def get_organization_message_usage(self, org_id): + return self.get( + url="/organizations/{0}/message-allowance".format(org_id), + ) + service_api_client = ServiceAPIClient() diff --git a/app/templates/views/organizations/organization/index.html b/app/templates/views/organizations/organization/index.html index 33051839e..e054421a4 100644 --- a/app/templates/views/organizations/organization/index.html +++ b/app/templates/views/organizations/organization/index.html @@ -9,7 +9,7 @@ {{ page_header('Organization Dashboard', size='large') }} -
+

Overall {{ selected_year }} Total Message Allowance