mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Merge pull request #1534 from alphagov/collect-service-type
Collect organisation type when user creates a service and use it to calculate text message allowance
This commit is contained in:
@@ -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,17 @@ 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'],
|
||||
free_sms_fragment_limit=current_app.config['DEFAULT_FREE_SMS_FRAGMENT_LIMITS'].get(organisation_type),
|
||||
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 +82,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:
|
||||
|
||||
@@ -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,
|
||||
@@ -34,6 +34,8 @@ from app.main.forms import (
|
||||
LetterBranding,
|
||||
ServiceInboundApiForm,
|
||||
InternationalSMSForm,
|
||||
OrganisationTypeForm,
|
||||
FreeSMSAllowance,
|
||||
)
|
||||
from app import user_api_client, current_service, organisations_client, inbound_number_client
|
||||
from notifications_utils.formatters import formatted_list
|
||||
@@ -73,12 +75,12 @@ def service_settings(service_id):
|
||||
reply_to_email_addresses = service_api_client.get_reply_to_email_addresses(service_id)
|
||||
reply_to_email_address_count = len(reply_to_email_addresses)
|
||||
default_reply_to_email_address = next(
|
||||
(x['email_address'] for x in reply_to_email_addresses if x['is_default']), "None"
|
||||
(x['email_address'] for x in reply_to_email_addresses if x['is_default']), "Not set"
|
||||
)
|
||||
letter_contact_details = service_api_client.get_letter_contacts(service_id)
|
||||
letter_contact_details_count = len(letter_contact_details)
|
||||
default_letter_contact_block = next(
|
||||
(Field(x['contact_block'], html='escape') for x in letter_contact_details if x['is_default']), "None"
|
||||
(Field(x['contact_block'], html='escape') for x in letter_contact_details if x['is_default']), "Not set"
|
||||
)
|
||||
return render_template(
|
||||
'views/service-settings.html',
|
||||
@@ -100,7 +102,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')
|
||||
@@ -574,6 +576,46 @@ def service_set_letter_contact_block(service_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/set-organisation-type", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def set_organisation_type(service_id):
|
||||
|
||||
form = OrganisationTypeForm(organisation_type=current_service.get('organisation_type'))
|
||||
|
||||
if form.validate_on_submit():
|
||||
service_api_client.update_service(
|
||||
service_id,
|
||||
organisation_type=form.organisation_type.data,
|
||||
)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
'views/service-settings/set-organisation-type.html',
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/set-free-sms-allowance", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def set_free_sms_allowance(service_id):
|
||||
|
||||
form = FreeSMSAllowance(free_sms_allowance=current_service['free_sms_fragment_limit'])
|
||||
|
||||
if form.validate_on_submit():
|
||||
service_api_client.update_service(
|
||||
service_id,
|
||||
free_sms_fragment_limit=form.free_sms_allowance.data,
|
||||
)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
'views/service-settings/set-free-sms-allowance.html',
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/set-branding-and-org", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
|
||||
Reference in New Issue
Block a user