Use constants for organisation type

This reduces the chances of making a typo, because doing so will raise
an exception rather than fail silently.
This commit is contained in:
Chris Hill-Scott
2019-09-12 15:03:32 +01:00
parent 077dc194c6
commit 20f857753a
5 changed files with 41 additions and 22 deletions

View File

@@ -1375,14 +1375,14 @@ class BrandingOptionsEmail(StripWhitespaceForm):
def get_available_choices(service):
if (
service.organisation_type == 'central' and
service.organisation_type == Organisation.TYPE_CENTRAL and
service.organisation.email_branding_id is None and
service.email_branding_id is not None
):
yield ('govuk', 'GOV.UK')
if (
service.organisation_type == 'central' and
service.organisation_type == Organisation.TYPE_CENTRAL and
service.organisation and
service.organisation.email_branding_id is None and
service.email_branding_name.lower() != 'GOV.UK and {}'.format(service.organisation.name).lower()
@@ -1390,15 +1390,21 @@ class BrandingOptionsEmail(StripWhitespaceForm):
yield ('govuk_and_org', 'GOV.UK and {}'.format(service.organisation.name))
if (
service.organisation_type in {'nhs_local', 'nhs_central', 'nhs_gp'} and
service.email_branding_name != 'NHS'
service.organisation_type in {
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_GP,
} and service.email_branding_name != 'NHS'
):
yield ('nhs', 'NHS')
if (
service.organisation and
service.organisation_type not in {'nhs_local', 'nhs_central', 'nhs_gp'} and
(
service.organisation_type not in {
Organisation.TYPE_NHS_LOCAL,
Organisation.TYPE_NHS_CENTRAL,
Organisation.TYPE_NHS_GP,
} and (
service.email_branding_id is None or
service.email_branding_id != service.organisation.email_branding_id
)

View File

@@ -6,6 +6,7 @@ from flask_login import current_user
from app import current_service
from app.main import main
from app.main.forms import AcceptAgreementForm
from app.models.organisation import Organisation
from app.s3_client.s3_mou_client import get_mou
from app.utils import user_has_permissions
@@ -14,11 +15,11 @@ from app.utils import user_has_permissions
@user_has_permissions('manage_service')
def service_agreement(service_id):
if not current_service.organisation:
if current_service.organisation_type == 'nhs_gp':
if current_service.organisation_type == Organisation.TYPE_NHS_GP:
return redirect(
url_for('main.add_organisation_from_gp_service', service_id=current_service.id)
)
if current_service.organisation_type == 'nhs_local':
if current_service.organisation_type == Organisation.TYPE_NHS_LOCAL:
return redirect(
url_for('main.add_organisation_from_nhs_local_service', service_id=current_service.id)
)

View File

@@ -69,7 +69,7 @@ def add_organisation():
@main.route('/services/<uuid:service_id>/add-gp-organisation', methods=['GET', 'POST'])
@user_has_permissions('manage_service')
def add_organisation_from_gp_service(service_id):
if (not current_service.organisation_type == 'nhs_gp') or current_service.organisation:
if (not current_service.organisation_type == Organisation.TYPE_NHS_GP) or current_service.organisation:
abort(403)
form = AddGPOrganisationForm(service_name=current_service.name)
@@ -97,13 +97,13 @@ def add_organisation_from_gp_service(service_id):
@main.route('/services/<uuid:service_id>/add-nhs-local-organisation', methods=['GET', 'POST'])
@user_has_permissions('manage_service')
def add_organisation_from_nhs_local_service(service_id):
if (not current_service.organisation_type == 'nhs_local') or current_service.organisation:
if (not current_service.organisation_type == Organisation.TYPE_NHS_LOCAL) or current_service.organisation:
abort(403)
form = AddNHSLocalOrganisationForm(organisation_choices=[
(organisation.id, organisation.name)
for organisation in Organisations()
if organisation.organisation_type == 'nhs_local'
if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL
])
search_form = SearchByNameForm()