Add a platform admin button to service-settings page to turn the inbound_sms messaging on and off.

If clicked you will be prompted to enter a sms sender number, when setting the permission on or off.
Team members will always be able to see the number, but will only be able to change it if the inbound_sms permission is off.
This commit is contained in:
Rebecca Law
2017-06-02 16:25:24 +01:00
parent 4a251203df
commit fe24501075
6 changed files with 78 additions and 10 deletions

View File

@@ -49,6 +49,7 @@ def service_settings(service_id):
letter_branding=letter_branding_organisations.get(
current_service.get('dvla_organisation', '001')
),
can_receive_inbound=('inbound_sms' in current_service['permissions']),
letter_contact_block=Field(current_service['letter_contact_block'], html='escape')
)
@@ -267,14 +268,27 @@ def service_set_reply_to_email(service_id):
@user_has_permissions('manage_settings', admin_override=True)
def service_set_sms_sender(service_id):
form = ServiceSmsSender()
if form.validate_on_submit():
set_inbound_sms = request.args.get('set_inbound_sms', False)
if set_inbound_sms == 'True':
permissions = current_service['permissions']
if 'inbound_sms' in permissions:
permissions.remove('inbound_sms')
else:
permissions.append('inbound_sms')
service_api_client.update_service_with_properties(
current_service['id'],
{'permissions': permissions,
'sms_sender': form.sms_sender.data or None}
)
else:
service_api_client.update_service(
current_service['id'],
sms_sender=form.sms_sender.data or None
)
return redirect(url_for('.service_settings', service_id=service_id))
if request.method == 'GET':
form.sms_sender.data = current_service.get('sms_sender')
if form.validate_on_submit():
service_api_client.update_service(
current_service['id'],
sms_sender=form.sms_sender.data or None
)
return redirect(url_for('.service_settings', service_id=service_id))
return render_template(
'views/service-settings/set-sms-sender.html',
form=form)

View File

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

View File

@@ -36,8 +36,13 @@
{% call row() %}
{{ text_field('Text message sender') }}
{{ text_field(current_service.sms_sender) }}
{{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id)) }}
{{ text_field(current_service.sms_sender}}
{% if current_user.has_permissions([], admin_override=True) or not can_receive_inbound %}
{{ edit_field('Change', url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=False)) }}
{% else %}
{{ text_field('') }}
{% endif %}
{% endcall %}
{% call row() %}
@@ -162,6 +167,11 @@
</a>
</li>
{% endif %}
<li class="bottom-gutter">
<a href="{{ url_for('.service_set_sms_sender', service_id=current_service.id, set_inbound_sms=True) }}" class="button">
{{ 'Stop inbound sms' if can_receive_inbound else 'Allow inbound sms' }}
</a>
</li>
</ul>
{% endif %}