From bd54dbb40ca85dd72037ba993a4a7de564b580d7 Mon Sep 17 00:00:00 2001 From: Leo Hemsted Date: Tue, 27 Feb 2018 17:18:26 +0000 Subject: [PATCH] remove unnecessary invocations of has_permissions(..., any_=True) when added to a service, all users are given the view_activity permission. So, if that's included in the list, we don't need `any_`, and we don't need any of the other permissions. --- app/main/views/templates.py | 32 ++----------------- app/notify_client/user_api_client.py | 2 +- app/templates/main_nav.html | 6 ++-- .../views/templates/choose-reply.html | 2 +- app/templates/views/templates/choose.html | 2 +- tests/app/main/views/test_send.py | 2 +- tests/app/main/views/test_templates.py | 2 +- 7 files changed, 9 insertions(+), 39 deletions(-) diff --git a/app/main/views/templates.py b/app/main/views/templates.py index 0888b7098..08c88db63 100644 --- a/app/main/views/templates.py +++ b/app/main/views/templates.py @@ -43,11 +43,7 @@ page_headings = { @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', - admin_override=True, any_=True + admin_override=True, ) def view_template(service_id, template_id): template = service_api_client.get_service_template(service_id, str(template_id))['data'] @@ -81,11 +77,7 @@ def view_template(service_id, template_id): @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', - admin_override=True, any_=True + admin_override=True, ) def start_tour(service_id, template_id): @@ -110,12 +102,7 @@ def start_tour(service_id, template_id): @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', admin_override=True, - any_=True, ) def choose_template(service_id, template_type='all'): templates = service_api_client.get_service_templates(service_id)['data'] @@ -181,12 +168,7 @@ def _view_template_version(service_id, template_id, version, letters_as_pdf=Fals @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', admin_override=True, - any_=True ) def view_template_version(service_id, template_id, version): return render_template( @@ -199,12 +181,7 @@ def view_template_version(service_id, template_id, version): @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', admin_override=True, - any_=True ) def view_template_version_preview(service_id, template_id, version, filetype): db_template = service_api_client.get_service_template(service_id, template_id, version=version)['data'] @@ -515,12 +492,7 @@ def redact_template(service_id, template_id): @login_required @user_has_permissions( 'view_activity', - 'send_texts', - 'send_emails', - 'manage_templates', - 'manage_api_keys', admin_override=True, - any_=True ) def view_template_versions(service_id, template_id): return render_template( diff --git a/app/notify_client/user_api_client.py b/app/notify_client/user_api_client.py index 8b9e5643a..dc45a2b46 100644 --- a/app/notify_client/user_api_client.py +++ b/app/notify_client/user_api_client.py @@ -133,7 +133,7 @@ class UserApiClient(NotifyAdminAPIClient): def get_count_of_users_with_permission(self, service_id, permission): return len([ user for user in self.get_users_for_service(service_id) - if user.has_permissions(permission, any_=True) + if user.has_permissions(permission) ]) def get_users_for_organisation(self, org_id): diff --git a/app/templates/main_nav.html b/app/templates/main_nav.html index dd8c02b52..a77db2ae5 100644 --- a/app/templates/main_nav.html +++ b/app/templates/main_nav.html @@ -44,14 +44,12 @@