From c7a56c8bdfea9234c293d387719fa26726abad16 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Mon, 16 Mar 2020 12:08:38 +0000 Subject: [PATCH] Remove jobs from the dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We’ve done this already for services with the upload letters permission. And all services can upload letters now. But we’re still returning it in the JSON response we use to AJAX-ify the page. Since the jobs response can query stats for up to 50 jobs at a time this puts some load on the API/database. Hopefully this might drop that load a bit. --- app/main/views/dashboard.py | 4 - app/templates/main_nav.html | 8 +- app/templates/views/dashboard/dashboard.html | 8 -- tests/app/main/test_permissions.py | 2 + tests/app/main/views/test_dashboard.py | 85 -------------------- tests/app/test_navigation.py | 2 +- 6 files changed, 5 insertions(+), 104 deletions(-) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index b66eedf8f..9af826f07 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -309,10 +309,6 @@ def get_dashboard_partials(service_id): [row['count'] for row in template_statistics] or [0] ), ), - 'jobs': render_template( - 'views/dashboard/_jobs.html', - jobs=current_service.immediate_jobs, - ), 'usage': render_template( 'views/dashboard/_usage.html', **calculate_usage(yearly_usage, free_sms_allowance), diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index 8bc80dbad..3e5d8b2bd 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -8,14 +8,10 @@
  • Dashboard
  • {% endif %}
  • Templates
  • - {% if current_user.has_permissions('view_activity') %} -
  • Uploads
  • - {% else %} + {% if not current_user.has_permissions('view_activity') %}
  • Sent messages
  • - {% if current_service.has_jobs or current_service.can_upload_letters %} -
  • Uploads
  • - {% endif %} {% endif %} +
  • Uploads
  • Team members
  • {% if current_user.has_permissions('manage_service', allow_org_user=True) %}
  • Usage
  • diff --git a/app/templates/views/dashboard/dashboard.html b/app/templates/views/dashboard/dashboard.html index 0eee5be5d..fa8405690 100644 --- a/app/templates/views/dashboard/dashboard.html +++ b/app/templates/views/dashboard/dashboard.html @@ -35,14 +35,6 @@ {{ ajax_block(partials, updates_url, 'template-statistics') }} - {% if current_service.immediate_jobs and not current_service.has_permission('upload_letters') %} - {{ ajax_block(partials, updates_url, 'jobs') }} - {{ show_more( - url_for('.view_jobs', service_id=current_service.id), - 'See all uploaded files' - ) }} - {% endif %} - {% if current_user.has_permissions('manage_service') %}

    This year

    {{ ajax_block(partials, updates_url, 'usage') }} diff --git a/tests/app/main/test_permissions.py b/tests/app/main/test_permissions.py index 4156001f2..7a16e5012 100644 --- a/tests/app/main/test_permissions.py +++ b/tests/app/main/test_permissions.py @@ -384,6 +384,7 @@ def test_service_navigation_for_org_user( ( 'Templates', 'Sent messages', + 'Uploads', 'Team members', ), 403, @@ -393,6 +394,7 @@ def test_service_navigation_for_org_user( ( 'Templates', 'Sent messages', + 'Uploads', 'Team members', 'Usage', ), diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index 0675d9472..208cd1e20 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -1,7 +1,6 @@ import copy import json from datetime import datetime -from unittest.mock import call import pytest from bs4 import BeautifulSoup @@ -903,56 +902,6 @@ def test_correct_font_size_for_big_numbers( ) == 3 -@freeze_time("2016-01-01 11:09:00.061258") -def test_should_show_recent_jobs_on_dashboard( - client_request, - mock_get_service_templates, - mock_get_template_statistics, - mock_get_service_statistics, - mock_get_jobs, - mock_get_usage, - mock_get_free_sms_fragment_limit, - mock_get_inbound_sms_summary, - mock_get_returned_letter_summary_with_no_returned_letters, -): - page = client_request.get( - 'main.service_dashboard', - service_id=SERVICE_ONE_ID, - ) - - third_call = mock_get_jobs.call_args_list[2] - assert third_call[0] == (SERVICE_ONE_ID,) - assert third_call[1]['limit_days'] == 7 - assert 'scheduled' not in third_call[1]['statuses'] - - table_rows = page.select_one('tbody').select('tr') - - assert len(table_rows) == 4 - - for index, filename in enumerate(( - "export 1/1/2016.xls", - "all email addresses.xlsx", - "applicants.ods", - "thisisatest.csv", - )): - assert filename in table_rows[index].find_all('th')[0].text - assert 'Sent today at 11:09' in table_rows[index].find_all('th')[0].text - assert normalize_spaces( - table_rows[index].select_one('td').text - ) == ( - '1 sending 0 delivered 0 failed' - ) - - -@pytest.mark.parametrize('extra_permissions', ( - pytest.param( - [], - marks=pytest.mark.xfail(raises=AssertionError), - ), - pytest.param( - ['upload_letters'] - ), -)) def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page( client_request, service_one, @@ -964,9 +913,7 @@ def test_should_not_show_jobs_on_dashboard_for_users_with_uploads_page( mock_get_free_sms_fragment_limit, mock_get_inbound_sms_summary, mock_get_returned_letter_summary_with_no_returned_letters, - extra_permissions, ): - service_one['permissions'] += extra_permissions page = client_request.get( 'main.service_dashboard', service_id=SERVICE_ONE_ID, @@ -1546,38 +1493,6 @@ def test_get_tuples_of_financial_years_defaults_to_2015(): ))[0] -@freeze_time("2016-01-01 11:09:00.061258") -def test_should_show_all_jobs_with_valid_statuses( - logged_in_client, - mock_get_template_statistics, - mock_get_service_statistics, - mock_get_service_templates_when_no_templates_exist, - mock_get_jobs, - mock_get_usage, - mock_get_inbound_sms_summary, - mock_get_returned_letter_summary_with_no_returned_letters, - mock_get_free_sms_fragment_limit, -): - logged_in_client.get(url_for('main.service_dashboard', service_id=SERVICE_ONE_ID)) - - first_call = mock_get_jobs.call_args_list[0] - # first call - checking for any jobs - assert first_call == call(SERVICE_ONE_ID) - second_call = mock_get_jobs.call_args_list[1] - # second call - scheduled jobs only - assert second_call == call(SERVICE_ONE_ID, statuses=['scheduled']) - # third call - everything but scheduled and cancelled - third_call = mock_get_jobs.call_args_list[2] - assert third_call == call(SERVICE_ONE_ID, limit_days=7, statuses={ - 'pending', - 'in progress', - 'finished', - 'sending limits exceeded', - 'ready to send', - 'sent to dvla' - }) - - def test_org_breadcrumbs_do_not_show_if_service_has_no_org( client_request, mock_get_template_statistics, diff --git a/tests/app/test_navigation.py b/tests/app/test_navigation.py index 55a6f8c02..14b95212c 100644 --- a/tests/app/test_navigation.py +++ b/tests/app/test_navigation.py @@ -191,7 +191,7 @@ def test_caseworkers_get_caseworking_navigation( ) page = client_request.get('main.choose_template', service_id=SERVICE_ONE_ID) assert normalize_spaces(page.select_one('header + .govuk-width-container nav').text) == ( - 'Templates Sent messages Team members' + 'Templates Sent messages Uploads Team members' )