From 22ebc2ece5b882499df640285eae668e675058b0 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Apr 2016 11:23:45 +0100 Subject: [PATCH 1/3] Make permissions for AJAX dashboard backend match MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If you don’t have permission to see the HTML dashboard, you shouldn’t be able to see the JSON one. --- app/main/views/dashboard.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 380d54852..d3f725761 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -57,6 +57,7 @@ def service_dashboard(service_id): @main.route("/services//dashboard.json") @login_required +@user_has_permissions('view_activity', admin_override=True) def service_dashboard_updates(service_id): return jsonify(**{ 'today': render_template( From 0cc499bce412038e1cab2426ebb02eb549fa6c30 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Apr 2016 11:30:09 +0100 Subject: [PATCH 2/3] Make sure the stats client passes params through This was the cause of the dashboard showing statistics from all time. --- app/notify_client/statistics_api_client.py | 1 + .../main/notify_client/test_statistics_client.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/notify_client/statistics_api_client.py b/app/notify_client/statistics_api_client.py index 3d4292c36..3492d7e91 100644 --- a/app/notify_client/statistics_api_client.py +++ b/app/notify_client/statistics_api_client.py @@ -18,4 +18,5 @@ class StatisticsApiClient(BaseAPIClient): params['limit_days'] = limit_days return self.get( url='/service/{}/notifications-statistics'.format(service_id), + params=params ) diff --git a/tests/app/main/notify_client/test_statistics_client.py b/tests/app/main/notify_client/test_statistics_client.py index a4bcba8ce..70a83f795 100644 --- a/tests/app/main/notify_client/test_statistics_client.py +++ b/tests/app/main/notify_client/test_statistics_client.py @@ -14,4 +14,18 @@ def test_notifications_statistics_client_calls_correct_api_endpoint(mocker, api_ client.get_statistics_for_service(some_service_id) - mock_get.assert_called_once_with(url=expected_url) + mock_get.assert_called_once_with(url=expected_url, params={}) + + +def test_notifications_statistics_client_calls_correct_api_endpoint_with_params(mocker, api_user_active): + + some_service_id = uuid.uuid4() + expected_url = '/service/{}/notifications-statistics'.format(some_service_id) + + client = StatisticsApiClient() + + mock_get = mocker.patch('app.notify_client.statistics_api_client.StatisticsApiClient.get') + + client.get_statistics_for_service(some_service_id, limit_days=99) + + mock_get.assert_called_once_with(url=expected_url, params={'limit_days': 99}) From 683baa0003dbc20f3708fe59760bc0de51be7e77 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 25 Apr 2016 11:33:40 +0100 Subject: [PATCH 3/3] Separate thousands with comma for big numbers Makes it easier to see just how big the numbers are. --- app/templates/components/big-number.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/templates/components/big-number.html b/app/templates/components/big-number.html index 1b608e7e9..6127c0564 100644 --- a/app/templates/components/big-number.html +++ b/app/templates/components/big-number.html @@ -1,6 +1,10 @@ {% macro big_number(number, label) %} -
- {{ number }} +
+ {% if number is number %} + {{ "{:,}".format(number) }} + {% else %} + {{ number }} + {% endif %} {{ label }}
{% endmacro %} @@ -13,10 +17,10 @@ {% if failures %} {% if failure_link %} - {{ failures }} failed – {{ failure_percentage }}% + {{ "{:,}".format(failures) }} failed – {{ failure_percentage }}% {% else %} - {{ failures }} failed – {{ failure_percentage }}% + {{ "{:,}".format(failures) }} failed – {{ failure_percentage }}% {% endif %} {% else %} No failures