Merge pull request #59 from GSA/stvnrlly-update-form-flow

Update services for post-sign-up tour
This commit is contained in:
Steven Reilly
2022-10-17 09:43:32 -04:00
committed by GitHub
17 changed files with 158 additions and 325 deletions

View File

@@ -1191,50 +1191,6 @@ class RenameOrganisationForm(StripWhitespaceForm):
])
class AddGPOrganisationForm(StripWhitespaceForm):
def __init__(self, *args, service_name='unknown', **kwargs):
super().__init__(*args, **kwargs)
self.same_as_service_name.label.text = 'Is your GP practice called {}?'.format(service_name)
self.service_name = service_name
def get_organisation_name(self):
if self.same_as_service_name.data:
return self.service_name
return self.name.data
same_as_service_name = OnOffField(
'Is your GP practice called the same name as your service?',
choices=(
(True, 'Yes'),
(False, 'No'),
),
)
name = GovukTextInputField(
'Whats your practice called?',
)
def validate_name(self, field):
if self.same_as_service_name.data is False:
if not field.data:
raise ValidationError('Cannot be empty')
else:
field.data = ''
class AddNHSLocalOrganisationForm(StripWhitespaceForm):
def __init__(self, *args, organisation_choices=None, **kwargs):
super().__init__(*args, **kwargs)
self.organisations.choices = organisation_choices
organisations = GovukRadiosField(
'Which NHS Trust or Clinical Commissioning Group do you work for?',
thing='an NHS Trust or Clinical Commissioning Group'
)
class OrganisationOrganisationTypeForm(StripWhitespaceForm):
organisation_type = OrganisationTypeField('What type of organisation is this?')
@@ -1298,14 +1254,7 @@ class CreateServiceForm(StripWhitespaceForm):
MustContainAlphanumericCharacters(),
Length(max=255, message='Service name must be 255 characters or fewer')
])
organisation_type = OrganisationTypeField('Who runs this service?')
class CreateNhsServiceForm(CreateServiceForm):
organisation_type = OrganisationTypeField(
'Who runs this service?',
include_only={'nhs_central', 'nhs_local', 'nhs_gp'},
)
organisation_type = OrganisationTypeField('Where is this service run?')
class AdminNewOrganisationForm(

View File

@@ -5,7 +5,7 @@ from notifications_python_client.errors import HTTPError
from app import service_api_client
from app.formatters import email_safe
from app.main import main
from app.main.forms import CreateNhsServiceForm, CreateServiceForm
from app.main.forms import CreateServiceForm
from app.utils.user import user_is_gov_user, user_is_logged_in
@@ -46,13 +46,11 @@ def _create_example_template(service_id):
@user_is_gov_user
def add_service():
default_organisation_type = current_user.default_organisation_type
if default_organisation_type == 'nhs':
form = CreateNhsServiceForm()
default_organisation_type = None
else:
form = CreateServiceForm(
organisation_type=default_organisation_type
)
form = CreateServiceForm(
# avoid setting a default for now; the US gov email addresses aren't as useful as the UK
# ones for guessing the org type
organisation_type=None
)
if form.validate_on_submit():
email_from = email_safe(form.name.data)

View File

@@ -5,11 +5,9 @@ from functools import partial
from flask import flash, redirect, render_template, request, send_file, url_for
from flask_login import current_user
from notifications_python_client.errors import HTTPError
from werkzeug.exceptions import abort
from app import (
current_organisation,
current_service,
email_branding_client,
letter_branding_client,
org_invite_api_client,
@@ -17,8 +15,6 @@ from app import (
)
from app.main import main
from app.main.forms import (
AddGPOrganisationForm,
AddNHSLocalOrganisationForm,
AdminBillingDetailsForm,
AdminNewOrganisationForm,
AdminNotesForm,
@@ -81,62 +77,6 @@ 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 == Organisation.TYPE_NHS_GP) or current_service.organisation:
abort(403)
form = AddGPOrganisationForm(service_name=current_service.name)
if form.validate_on_submit():
Organisation.create(
form.get_organisation_name(),
crown=False,
organisation_type='nhs_gp',
agreement_signed=False,
).associate_service(
service_id
)
return redirect(url_for(
'.service_agreement',
service_id=service_id,
))
return render_template(
'views/organisations/add-gp-organisation.html',
form=form
)
@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 == Organisation.TYPE_NHS_LOCAL) or current_service.organisation:
abort(403)
form = AddNHSLocalOrganisationForm(organisation_choices=[
(organisation.id, organisation.name)
for organisation in sorted(AllOrganisations())
if organisation.organisation_type == Organisation.TYPE_NHS_LOCAL
])
search_form = SearchByNameForm()
if form.validate_on_submit():
Organisation.from_id(form.organisations.data).associate_service(service_id)
return redirect(url_for(
'.service_agreement',
service_id=service_id,
))
return render_template(
'views/organisations/add-nhs-local-organisation.html',
form=form,
search_form=search_form,
)
@main.route("/organisations/<uuid:org_id>", methods=['GET'])
@user_has_permissions()
def organisation_dashboard(org_id):

View File

@@ -16,29 +16,35 @@ from app.notify_client.organisations_api_client import organisations_client
class Organisation(JSONModel, SortByNameMixin):
TYPE_CENTRAL = 'central'
TYPE_LOCAL = 'local'
TYPE_NHS_CENTRAL = 'nhs_central'
TYPE_NHS_LOCAL = 'nhs_local'
TYPE_NHS_GP = 'nhs_gp'
TYPE_EMERGENCY_SERVICE = 'emergency_service'
TYPE_SCHOOL_OR_COLLEGE = 'school_or_college'
TYPE_FEDERAL = 'federal'
TYPE_STATE = 'state'
# TYPE_CENTRAL = 'central'
# TYPE_LOCAL = 'local'
# TYPE_NHS_CENTRAL = 'nhs_central'
# TYPE_NHS_LOCAL = 'nhs_local'
# TYPE_NHS_GP = 'nhs_gp'
# TYPE_EMERGENCY_SERVICE = 'emergency_service'
# TYPE_SCHOOL_OR_COLLEGE = 'school_or_college'
TYPE_OTHER = 'other'
NHS_TYPES = (
TYPE_NHS_CENTRAL,
TYPE_NHS_LOCAL,
TYPE_NHS_GP,
)
# NHS_TYPES = (
# TYPE_NHS_CENTRAL,
# TYPE_NHS_LOCAL,
# TYPE_NHS_GP,
# )
TYPE_LABELS = OrderedDict([
(TYPE_CENTRAL, 'Central government'),
(TYPE_LOCAL, 'Local government'),
(TYPE_NHS_CENTRAL, 'NHS central government agency or public body'),
(TYPE_NHS_LOCAL, 'NHS Trust or Clinical Commissioning Group'),
(TYPE_NHS_GP, 'GP practice'),
(TYPE_EMERGENCY_SERVICE, 'Emergency service'),
(TYPE_SCHOOL_OR_COLLEGE, 'School or college'),
(TYPE_FEDERAL, 'Federal government'),
(TYPE_STATE, 'State government'),
# (TYPE_CENTRAL, 'Central government'),
# (TYPE_LOCAL, 'Local government'),
# (TYPE_NHS_CENTRAL, 'NHS central government agency or public body'),
# (TYPE_NHS_LOCAL, 'NHS Trust or Clinical Commissioning Group'),
# (TYPE_NHS_GP, 'GP practice'),
# (TYPE_EMERGENCY_SERVICE, 'Emergency service'),
# (TYPE_SCHOOL_OR_COLLEGE, 'School or college'),
(TYPE_OTHER, 'Other'),
])

View File

@@ -223,8 +223,8 @@ class MainNavigation(Navigation):
'usage',
},
'settings': {
'add_organisation_from_gp_service',
'add_organisation_from_nhs_local_service',
# 'add_organisation_from_gp_service',
# 'add_organisation_from_nhs_local_service',
'email_branding_govuk',
'email_branding_govuk_and_org',
'email_branding_nhs',

View File

@@ -7,49 +7,33 @@ def get_email_choices(service):
organisation_branding_id = service.organisation.email_branding_id if service.organisation else None
if (
service.organisation_type == Organisation.TYPE_CENTRAL
service.organisation_type == Organisation.TYPE_FEDERAL
and service.email_branding_id is not None # GOV.UK is not current branding
and organisation_branding_id is None # no default to supersede it (GOV.UK)
):
yield ('govuk', 'GOV.UK')
if (
service.organisation_type == Organisation.TYPE_CENTRAL
service.organisation_type == Organisation.TYPE_FEDERAL
and service.organisation
and organisation_branding_id is None # don't offer both if org has default
and service.email_branding_name.lower() != f'GOV.UK and {service.organisation.name}'.lower()
):
yield ('govuk_and_org', f'GOV.UK and {service.organisation.name}')
if (
service.organisation_type in Organisation.NHS_TYPES
and service.email_branding_id != NHS_EMAIL_BRANDING_ID
):
yield ('nhs', 'NHS')
if (
service.organisation
and service.organisation_type not in Organisation.NHS_TYPES
and (
service.email_branding_id is None # GOV.UK is current branding
or service.email_branding_id != organisation_branding_id
)
):
yield ('organisation', service.organisation.name)
def get_letter_choices(service):
organisation_branding_id = service.organisation.letter_branding_id if service.organisation else None
if (
service.organisation_type in Organisation.NHS_TYPES
and service.letter_branding_name != 'NHS'
):
yield ('nhs', 'NHS')
# if (
# service.organisation_type in Organisation.NHS_TYPES
# and service.letter_branding_name != 'NHS'
# ):
# yield ('nhs', 'NHS')
if (
service.organisation
and service.organisation_type not in Organisation.NHS_TYPES
# and service.organisation_type not in Organisation.NHS_TYPES
and (
service.letter_branding_id is None # GOV.UK is current branding
or service.letter_branding_id != organisation_branding_id