From 5c52d3c362414c0bec4d631077aeefac9a5512f3 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Wed, 8 Jul 2020 11:39:04 +0100 Subject: [PATCH] Redirect from normal dashboard to broadcast dashboard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are lots of places where we redirect people to the dashboard, for example after logging in. Rather than add logic to all these places to check for the broadcast permission, let’s just redirect from the normal dashboard to the broadcast dashboard. Other places like the main navigation can still link directly to the broadcast dashboard, where we do care about speed and not going through multiple redirect jumps. --- app/main/views/dashboard.py | 3 +++ tests/app/main/views/test_broadcast.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index 2bca2afd8..095582b29 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -52,6 +52,9 @@ def service_dashboard(service_id): session.pop('invited_user', None) session['service_id'] = service_id + if current_service.has_permission('broadcast'): + return redirect(url_for('main.broadcast_dashboard', service_id=service_id)) + if not current_user.has_permissions('view_activity'): return redirect(url_for('main.choose_template', service_id=service_id)) diff --git a/tests/app/main/views/test_broadcast.py b/tests/app/main/views/test_broadcast.py index 4deca0eaa..372d45dd9 100644 --- a/tests/app/main/views/test_broadcast.py +++ b/tests/app/main/views/test_broadcast.py @@ -26,6 +26,22 @@ def test_broadcast_pages_403_without_permission( ) +def test_dashboard_redirects_to_broadcast_dashboard( + client_request, + service_one, +): + service_one['permissions'] += ['broadcast'] + client_request.get( + '.service_dashboard', + service_id=SERVICE_ONE_ID, + _expected_redirect=url_for( + '.broadcast_dashboard', + service_id=SERVICE_ONE_ID, + _external=True, + ), + ), + + def test_broadcast_dashboard( client_request, service_one,