From 8a453890e668ea80e4aea6f2036f03cc88530032 Mon Sep 17 00:00:00 2001 From: Katie Smith Date: Fri, 9 Aug 2019 08:44:11 +0100 Subject: [PATCH] Add 'Uploads' hub and navigation The uploads hub is just a page with text for now - there are no actions available on the page. It is linked to from a new 'Uploads' menu item on the left of the page which is only visible if your service has the `letter` and `upload_letters` permissions and if the current user has permissions to send messages. --- app/main/__init__.py | 1 + app/main/views/uploads.py | 10 ++++++++++ app/navigation.py | 6 ++++++ app/templates/main_nav.html | 3 +++ app/templates/views/uploads/index.html | 16 +++++++++++++++ tests/app/main/views/test_dashboard.py | 27 ++++++++++++++++++++++++++ tests/app/main/views/test_uploads.py | 5 +++++ 7 files changed, 68 insertions(+) create mode 100644 app/main/views/uploads.py create mode 100644 app/templates/views/uploads/index.html create mode 100644 tests/app/main/views/test_uploads.py diff --git a/app/main/__init__.py b/app/main/__init__.py index ef20f66e6..b15fcf945 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -33,6 +33,7 @@ from app.main.views import ( # noqa isort:skip styleguide, templates, two_factor, + uploads, user_profile, verify, ) diff --git a/app/main/views/uploads.py b/app/main/views/uploads.py new file mode 100644 index 000000000..4fe8efc36 --- /dev/null +++ b/app/main/views/uploads.py @@ -0,0 +1,10 @@ +from flask import render_template + +from app.main import main +from app.utils import user_has_permissions + + +@main.route("/services//uploads") +@user_has_permissions('send_messages') +def uploads(service_id): + return render_template('views/uploads/index.html') diff --git a/app/navigation.py b/app/navigation.py index d643f4c6a..cfcff353d 100644 --- a/app/navigation.py +++ b/app/navigation.py @@ -300,6 +300,7 @@ class HeaderNavigation(Navigation): 'template_history', 'template_usage', 'trial_mode', + 'uploads', 'usage', 'view_job', 'view_job_csv', @@ -359,6 +360,9 @@ class MainNavigation(Navigation): 'view_template_version', 'view_template_versions', }, + 'uploads': { + 'uploads', + }, 'team-members': { 'confirm_edit_user_email', 'confirm_edit_user_mobile_number', @@ -844,6 +848,7 @@ class CaseworkNavigation(Navigation): 'two_factor_email_sent', 'update_email_branding', 'update_letter_branding', + 'uploads', 'usage', 'user_information', 'user_profile', @@ -1118,6 +1123,7 @@ class OrgNavigation(Navigation): 'two_factor_email_sent', 'update_email_branding', 'update_letter_branding', + 'uploads', 'usage', 'user_information', 'user_profile', diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index 8037b77ff..7f6a1fa55 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -14,6 +14,9 @@
  • Uploaded files
  • {% endif %} {% endif %} + {% endif %} + {% if current_user.has_permissions('send_messages') and current_service.has_permission('letter') and current_service.has_permission('upload_letters') %} +
  • Uploads
  • {% endif %}
  • Team members
  • {% if current_user.has_permissions('manage_service', allow_org_user=True) %} diff --git a/app/templates/views/uploads/index.html b/app/templates/views/uploads/index.html new file mode 100644 index 000000000..9e5ff2bd7 --- /dev/null +++ b/app/templates/views/uploads/index.html @@ -0,0 +1,16 @@ +{% extends "withnav_template.html" %} +{% from "components/page-header.html" import page_header %} + +{% block service_page_title %} + Uploads +{% endblock %} + +{% block maincolumn_content %} +
    +
    + {{ page_header('Uploads') }} + +

    Upload a letter and Notify will print, pack and post it for you.

    +
    +
    +{% endblock %} diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index b639c8b80..2bd6a68dc 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -960,6 +960,8 @@ def test_menu_send_messages( mock_get_inbound_sms_summary, mock_get_free_sms_fragment_limit, ): + service_one['permissions'] = ['email', 'sms', 'letter', 'upload_letters'] + with app_.test_request_context(): resp = _test_dashboard_menu( mocker, @@ -972,6 +974,7 @@ def test_menu_send_messages( 'main.choose_template', service_id=service_one['id'], ) in page + assert url_for('main.uploads', service_id=service_one['id']) in page assert url_for('main.manage_users', service_id=service_one['id']) in page assert url_for('main.service_settings', service_id=service_one['id']) not in page @@ -979,6 +982,30 @@ def test_menu_send_messages( assert url_for('main.view_providers') not in page +def test_menu_send_messages_when_service_does_not_have_upload_letters_permission( + mocker, + app_, + api_user_active, + service_one, + mock_get_service_templates, + mock_get_jobs, + mock_get_template_statistics, + mock_get_service_statistics, + mock_get_usage, + mock_get_inbound_sms_summary, + mock_get_free_sms_fragment_limit, +): + with app_.test_request_context(): + resp = _test_dashboard_menu( + mocker, + app_, + api_user_active, + service_one, + ['view_activity', 'send_messages']) + page = resp.get_data(as_text=True) + assert url_for('main.uploads', service_id=service_one['id']) not in page + + def test_menu_manage_service( mocker, app_, diff --git a/tests/app/main/views/test_uploads.py b/tests/app/main/views/test_uploads.py new file mode 100644 index 000000000..e33965eea --- /dev/null +++ b/tests/app/main/views/test_uploads.py @@ -0,0 +1,5 @@ +from tests.conftest import SERVICE_ONE_ID + + +def test_get_upload_hub_page(client_request): + client_request.get('main.uploads', service_id=SERVICE_ONE_ID)