Add page to change SMS allowance

There may be exceptions to the rule, so we should have a way of
overriding this manually.
This commit is contained in:
Chris Hill-Scott
2017-10-05 13:49:43 +01:00
parent d438109630
commit d9104ba59f
6 changed files with 105 additions and 7 deletions

View File

@@ -246,6 +246,15 @@ class OrganisationTypeForm(Form):
organisation_type = organisation_type()
class FreeSMSAllowance(Form):
free_sms_allowance = IntegerField(
'Numbers of text message fragments per year',
validators=[
DataRequired(message='Cant be empty')
]
)
class ConfirmPasswordForm(Form):
def __init__(self, validate_password_func, *args, **kwargs):
self.validate_password_func = validate_password_func

View File

@@ -35,6 +35,7 @@ from app.main.forms import (
ServiceInboundApiForm,
InternationalSMSForm,
OrganisationTypeForm,
FreeSMSAllowance,
)
from app import user_api_client, current_service, organisations_client, inbound_number_client
from notifications_utils.formatters import formatted_list
@@ -589,14 +590,32 @@ def set_organisation_type(service_id):
)
return redirect(url_for('.service_settings', service_id=service_id))
form.organisation_type.data = current_service.get('organisation_type')
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)

View File

@@ -104,7 +104,9 @@ class ServiceAPIClient(NotifyAdminAPIClient):
'organisation',
'letter_contact_block',
'dvla_organisation',
'permissions'
'permissions',
'organisation_type',
'free_sms_fragment_limit',
}
if disallowed_attributes:
raise TypeError('Not allowed to update service attributes: {}'.format(

View File

@@ -198,7 +198,7 @@
{% call row() %}
{{ text_field('Free text message allowance')}}
{{ text_field('{:,}'.format(current_service.free_sms_fragment_limit)) }}
{{ text_field() }}
{{ edit_field('Change', url_for('.set_free_sms_allowance', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Email branding' )}}

View File

@@ -0,0 +1,21 @@
{% extends "withnav_template.html" %}
{% from "components/textbox.html" import textbox %}
{% from "components/page-footer.html" import page_footer %}
{% block service_page_title %}
Emails
{% endblock %}
{% block maincolumn_content %}
<form method="post">
<h1 class="heading-large">Free text message allowance</h1>
{{ textbox(form.free_sms_allowance) }}
{{ page_footer(
'Save',
back_link=url_for('.service_settings', service_id=current_service.id),
back_link_text='Back to settings'
) }}
</form>
{% endblock %}