diff --git a/app/main/forms.py b/app/main/forms.py index e04b8d148..803698290 100644 --- a/app/main/forms.py +++ b/app/main/forms.py @@ -213,7 +213,7 @@ class TextNotReceivedForm(Form): mobile_number = international_phone_number() -class ServiceNameForm(Form): +class RenameServiceForm(Form): name = StringField( u'Service name', validators=[ @@ -221,6 +221,23 @@ class ServiceNameForm(Form): ]) +class CreateServiceForm(Form): + name = StringField( + u'What’s your service called?', + validators=[ + DataRequired(message='Can’t be empty') + ]) + organisation_type = RadioField( + 'Who runs this service?', + choices=[ + ('central', 'Central government'), + ('local', 'Local government'), + ('nhs', 'NHS'), + ], + validators=[DataRequired()], + ) + + class ConfirmPasswordForm(Form): def __init__(self, validate_password_func, *args, **kwargs): self.validate_password_func = validate_password_func diff --git a/app/main/views/add_service.py b/app/main/views/add_service.py index 9b7d5b9fd..8019199e6 100644 --- a/app/main/views/add_service.py +++ b/app/main/views/add_service.py @@ -14,7 +14,7 @@ from notifications_python_client.errors import HTTPError from werkzeug.exceptions import abort from app.main import main -from app.main.forms import ServiceNameForm +from app.main.forms import CreateServiceForm from app.notify_client.models import InvitedUser from app import ( @@ -39,13 +39,16 @@ def _add_invited_user_to_service(invited_user): return service_id -def _create_service(service_name, email_from, form): +def _create_service(service_name, organisation_type, email_from, form): try: - service_id = service_api_client.create_service(service_name=service_name, - message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], - restricted=True, - user_id=session['user_id'], - email_from=email_from) + service_id = service_api_client.create_service( + service_name=service_name, + organisation_type=organisation_type, + message_limit=current_app.config['DEFAULT_SERVICE_LIMIT'], + restricted=True, + user_id=session['user_id'], + email_from=email_from, + ) session['service_id'] = service_id return service_id, None except HTTPError as e: @@ -78,14 +81,14 @@ def add_service(): if not is_gov_user(current_user.email_address): abort(403) - form = ServiceNameForm() - heading = 'Which service do you want to set up notifications for?' + form = CreateServiceForm() + 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, email_from, form) + service_id, error = _create_service(service_name, 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: diff --git a/app/main/views/service_settings.py b/app/main/views/service_settings.py index 7356f5c53..6278b5818 100644 --- a/app/main/views/service_settings.py +++ b/app/main/views/service_settings.py @@ -25,7 +25,7 @@ from app.main import main from app.utils import user_has_permissions, email_safe, get_cdn_domain from app.main.forms import ( ConfirmPasswordForm, - ServiceNameForm, + RenameServiceForm, RequestToGoLiveForm, ServiceReplyToEmailForm, ServiceSmsSender, @@ -100,7 +100,7 @@ def service_settings(service_id): @login_required @user_has_permissions('manage_settings', admin_override=True) def service_name_change(service_id): - form = ServiceNameForm() + form = RenameServiceForm() if request.method == 'GET': form.name.data = current_service.get('name') diff --git a/app/notify_client/service_api_client.py b/app/notify_client/service_api_client.py index d8c034eaa..aa92b0e1b 100644 --- a/app/notify_client/service_api_client.py +++ b/app/notify_client/service_api_client.py @@ -16,12 +16,21 @@ class ServiceAPIClient(NotifyAdminAPIClient): self.service_id = application.config['ADMIN_CLIENT_USER_NAME'] self.api_key = application.config['ADMIN_CLIENT_SECRET'] - def create_service(self, service_name, message_limit, restricted, user_id, email_from): + def create_service( + self, + service_name, + organisation_type, + message_limit, + restricted, + user_id, + email_from, + ): """ Create a service and return the json. """ data = { "name": service_name, + "organisation_type": organisation_type, "active": True, "message_limit": message_limit, "user_id": user_id, diff --git a/app/templates/views/add-service.html b/app/templates/views/add-service.html index 75dcc3cae..a7c88d2d2 100644 --- a/app/templates/views/add-service.html +++ b/app/templates/views/add-service.html @@ -1,4 +1,5 @@ {% extends "withoutnav_template.html" %} +{% from "components/radios.html" import radios %} {% from "components/textbox.html" import textbox %} {% from "components/page-footer.html" import page_footer %} @@ -12,13 +13,15 @@