Have permissions decorators check user signed in

Rather than force us to write the decorators in a specific order let’s
just have one decorator call the other. This should make fewer lines of
code, and fewer annoying test failures. It also means that the same way
of raising a `401` (through the `current_app` method) is used
everywhere.
This commit is contained in:
Chris Hill-Scott
2019-07-01 15:22:08 +01:00
parent 3da9e84ece
commit b620b677d3
24 changed files with 117 additions and 267 deletions

View File

@@ -1,7 +1,7 @@
from collections import OrderedDict
from flask import flash, redirect, render_template, request, session, url_for
from flask_login import current_user, login_required
from flask_login import current_user
from notifications_python_client.errors import HTTPError
from werkzeug.exceptions import abort
@@ -38,7 +38,6 @@ from app.utils import user_has_permissions, user_is_platform_admin
@main.route("/organisations", methods=['GET'])
@user_is_platform_admin
@login_required
def organisations():
return render_template(
'views/organisations/index.html',
@@ -49,7 +48,6 @@ def organisations():
@main.route("/organisations/add", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def add_organisation():
form = CreateOrUpdateOrganisation()
@@ -68,7 +66,6 @@ def add_organisation():
@main.route("/organisations/<org_id>", methods=['GET'])
@user_has_permissions()
@login_required
def organisation_dashboard(org_id):
return render_template(
'views/organisations/organisation/index.html',
@@ -77,7 +74,6 @@ def organisation_dashboard(org_id):
@main.route("/organisations/<org_id>/trial-services", methods=['GET'])
@user_is_platform_admin
@login_required
def organisation_trial_mode_services(org_id):
return render_template(
'views/organisations/organisation/trial-mode-services.html',
@@ -87,7 +83,6 @@ def organisation_trial_mode_services(org_id):
@main.route("/organisations/<org_id>/users", methods=['GET'])
@user_has_permissions()
@login_required
def manage_org_users(org_id):
return render_template(
'views/organisations/organisation/users/index.html',
@@ -99,7 +94,6 @@ def manage_org_users(org_id):
@main.route("/organisations/<org_id>/users/invite", methods=['GET', 'POST'])
@user_has_permissions()
@login_required
def invite_org_user(org_id):
form = InviteOrgUserForm(
invalid_email_address=current_user.email_address
@@ -123,7 +117,6 @@ def invite_org_user(org_id):
@main.route("/organisations/<org_id>/users/<user_id>", methods=['GET', 'POST'])
@user_has_permissions()
@login_required
def edit_user_org_permissions(org_id, user_id):
return render_template(
'views/organisations/organisation/users/user/index.html',
@@ -133,7 +126,6 @@ def edit_user_org_permissions(org_id, user_id):
@main.route("/organisations/<org_id>/users/<user_id>/delete", methods=['GET', 'POST'])
@user_has_permissions()
@login_required
def remove_user_from_organisation(org_id, user_id):
user = User.from_id(user_id)
if request.method == 'POST':
@@ -163,7 +155,6 @@ def remove_user_from_organisation(org_id, user_id):
@main.route("/organisations/<org_id>/cancel-invited-user/<invited_user_id>", methods=['GET'])
@user_has_permissions()
@login_required
def cancel_invited_org_user(org_id, invited_user_id):
org_invite_api_client.cancel_invited_user(org_id=org_id, invited_user_id=invited_user_id)
@@ -172,7 +163,6 @@ def cancel_invited_org_user(org_id, invited_user_id):
@main.route("/organisations/<org_id>/settings/", methods=['GET'])
@user_is_platform_admin
@login_required
def organisation_settings(org_id):
email_branding = 'GOV.UK'
@@ -198,7 +188,6 @@ def organisation_settings(org_id):
@main.route("/organisations/<org_id>/settings/edit-name", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_name(org_id):
form = RenameOrganisationForm()
@@ -221,7 +210,6 @@ def edit_organisation_name(org_id):
@main.route("/organisations/<org_id>/settings/edit-type", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_type(org_id):
form = OrganisationOrganisationTypeForm(
@@ -243,7 +231,6 @@ def edit_organisation_type(org_id):
@main.route("/organisations/<org_id>/settings/edit-crown-status", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_crown_status(org_id):
form = OrganisationCrownStatusForm(
@@ -273,7 +260,6 @@ def edit_organisation_crown_status(org_id):
@main.route("/organisations/<org_id>/settings/edit-agreement", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_agreement(org_id):
form = OrganisationAgreementSignedForm(
@@ -303,7 +289,6 @@ def edit_organisation_agreement(org_id):
@main.route("/organisations/<org_id>/settings/set-email-branding", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_email_branding(org_id):
email_branding = email_branding_client.get_all_email_branding()
@@ -329,7 +314,6 @@ def edit_organisation_email_branding(org_id):
@main.route("/organisations/<org_id>/settings/preview-email-branding", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def organisation_preview_email_branding(org_id):
branding_style = request.args.get('branding_style', None)
@@ -352,7 +336,6 @@ def organisation_preview_email_branding(org_id):
@main.route("/organisations/<org_id>/settings/set-letter-branding", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_letter_branding(org_id):
letter_branding = letter_branding_client.get_all_letter_branding()
@@ -377,7 +360,6 @@ def edit_organisation_letter_branding(org_id):
@main.route("/organisations/<org_id>/settings/preview-letter-branding", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def organisation_preview_letter_branding(org_id):
branding_style = request.args.get('branding_style')
@@ -399,7 +381,6 @@ def organisation_preview_letter_branding(org_id):
@main.route("/organisations/<org_id>/settings/edit-organisation-domains", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_domains(org_id):
form = OrganisationDomainsForm()
@@ -424,7 +405,6 @@ def edit_organisation_domains(org_id):
@main.route("/organisations/<org_id>/settings/edit-name/confirm", methods=['GET', 'POST'])
@user_has_permissions()
@login_required
def confirm_edit_organisation_name(org_id):
# Validate password for form
def _check_password(pwd):
@@ -457,7 +437,6 @@ def confirm_edit_organisation_name(org_id):
@main.route("/organisations/<org_id>/settings/edit-go-live-notes", methods=['GET', 'POST'])
@user_is_platform_admin
@login_required
def edit_organisation_go_live_notes(org_id):
form = GoLiveNotesForm()