Don’t ask for organisation type when we know it

Every time someone adds a new service we ask them what kind of
organisation they work for.

We can look this up based on the user’s email address now. So we should
only ask the question if:
- we don’t know about the organisation
- or we haven’t set what type of organisation it is (this shouldn’t be
  possible on productions because we’ve populated the column for all
  existing organisations and it’s impossible to add a new one without
  setting it
This commit is contained in:
Chris Hill-Scott
2019-04-18 12:44:18 +01:00
parent 156ae9931f
commit 08e9b35d7a
6 changed files with 71 additions and 15 deletions

View File

@@ -1,5 +1,5 @@
from flask import current_app, redirect, render_template, session, url_for
from flask_login import login_required
from flask_login import current_user, login_required
from notifications_python_client.errors import HTTPError
from app import billing_api_client, service_api_client
@@ -47,14 +47,21 @@ def _create_example_template(service_id):
@login_required
@user_is_gov_user
def add_service():
form = CreateServiceForm()
form = CreateServiceForm(
organisation_type=current_user.default_organisation.organisation_type
)
heading = 'About your service'
if form.validate_on_submit():
email_from = email_safe(form.name.data)
service_name = form.name.data
service_id, error = _create_service(service_name, form.organisation_type.data, email_from, form)
service_id, error = _create_service(
service_name,
current_user.default_organisation.organisation_type or form.organisation_type.data,
email_from,
form,
)
if error:
return render_template('views/add-service.html', form=form, heading=heading)
if len(service_api_client.get_active_services({'user_id': session['user_id']}).get('data', [])) > 1: