Files
notifications-admin/app/templates/views/service-settings.html
Alexey Bezhan 000d6c3a48 Replace platform admin service setting buttons with forms
Most of the existing platform admin buttons on the service settings
page used to issue GET requests to switch service settings. This
means they weren't protected by CSRF. On top of that as our number
of service permissions increases over time a lot of buttons on the
page made it hard to work with.

To fix these issues we replace most of the buttons with rows in the
platform admin settings table. Each setting has a 'Change' link that
leads to a page with an On/Off switch form.

This removes "research mode" switch completely since we're planning
to deprecate it in the future and we don't expect to switch any new
services into research mode at the moment.

Most service permissions are now handled by a shared endpoint that
is parameterized with the permission name. Some permissions that
require some additional logic before they can be toggled (like document
upload, which requires setting a contact address) have separate
initial endpoints that redirect to `set_service_permission`.

"Archive", "Suspend" and "Resume" actions are kept as buttons since
they display a confirmation banner (which is a CSRF-protected form)
and they're not easily represented as an On/Off switch.
2019-02-20 16:45:12 +00:00

367 lines
13 KiB
HTML

{% extends "withnav_template.html" %}
{% from "components/banner.html" import banner_wrapper %}
{% from "components/table.html" import mapping_table, row, settings_row, text_field, optional_text_field, edit_field, field, boolean_field with context %}
{% block service_page_title %}
Settings
{% endblock %}
{% block maincolumn_content %}
<h1 class="heading-large">Settings</h1>
<div class="bottom-gutter-3-2 dashboard-table body-copy-table">
{% call mapping_table(
caption='General',
field_headings=['Label', 'Value', 'Action'],
field_headings_visible=False,
caption_visible=False
) %}
{% call row() %}
{{ text_field('Service name') }}
{{ text_field(current_service.name) }}
{{ edit_field(
'Change',
url_for('.service_name_change', service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% call row() %}
{{ text_field('Sign-in method') }}
{{ text_field(
'Email link or text message code'
if 'email_auth' in current_service.permissions
else 'Text message code'
) }}
{{ edit_field(
'Change',
url_for('.service_set_auth_type',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='upload_document') %}
{{ text_field('Contact details') }}
{{ text_field(current_service.contact_link, truncate=true) }}
{{ edit_field(
'Change',
url_for('.service_set_contact_link',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% endcall %}
{% call mapping_table(
caption='Email',
field_headings=['Label', 'Value', 'Action'],
field_headings_visible=False,
caption_visible=True
) %}
{% call row() %}
{{ text_field('Send emails') }}
{{ boolean_field('email' in current_service.permissions) }}
{{ edit_field(
'Change',
url_for(
'.service_set_channel',
channel='email',
service_id=current_service.id
),
permissions=['manage_service']
)}}
{% endcall %}
{% call settings_row(if_has_permission='email') %}
{{ text_field('Email reply-to addresses') }}
{% call field(status='default' if current_service.count_email_reply_to_addresses == 0 else '') %}
{{ current_service.default_email_reply_to_address or 'Not set' }}
{% if current_service.count_email_reply_to_addresses > 1 %}
<div class="hint">
{{ '…and %d more' | format(current_service.count_email_reply_to_addresses - 1) }}
</div>
{% endif %}
{% endcall %}
{{ edit_field(
'Manage' if current_service.count_email_reply_to_addresses else 'Change',
url_for('.service_email_reply_to',
service_id=current_service.id),
permissions=['manage_service','manage_api_keys']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='email') %}
{{ text_field('Email branding') }}
{{ text_field('Your branding' if current_service.email_branding else 'GOV.UK') }}
{{ edit_field(
'Change',
url_for('.branding_request', service_id=current_service.id),
permissions=['manage_service'],
)}}
{% endcall %}
{% endcall %}
{% call mapping_table(
caption='Text messages',
field_headings=['Label', 'Value', 'Action'],
field_headings_visible=False,
caption_visible=True
) %}
{% call row() %}
{{ text_field('Send text messages') }}
{{ boolean_field('sms' in current_service.permissions) }}
{{ edit_field(
'Change',
url_for(
'.service_set_channel',
service_id=current_service.id,
channel='sms'
),
permissions=['manage_service']
)}}
{% endcall %}
{% call settings_row(if_has_permission='sms') %}
{{ text_field('Text message sender') }}
{% call field(status='default' if current_service.default_sms_sender == "None" else '') %}
{{ current_service.default_sms_sender | string | nl2br | safe if current_service.default_sms_sender else 'None'}}
{% if current_service.count_sms_senders > 1 %}
<div class="hint">
{{ '…and %d more' | format(current_service.count_sms_senders - 1) }}
</div>
{% endif %}
{% endcall %}
{{ edit_field(
'Manage' if current_service.count_sms_senders > 1 else 'Change',
url_for('.service_sms_senders',
service_id=current_service.id),
permissions=['manage_service','manage_api_keys']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='sms') %}
{{ text_field('Text messages start with service name') }}
{{ boolean_field(current_service.prefix_sms) }}
{{ edit_field(
'Change',
url_for('.service_set_sms_prefix',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='sms') %}
{{ text_field('International text messages') }}
{{ boolean_field('international_sms' in current_service.permissions) }}
{{ edit_field(
'Change',
url_for('.service_set_international_sms',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='sms') %}
{{ text_field('Receive text messages') }}
{{ boolean_field('inbound_sms' in current_service.permissions) }}
{{ edit_field(
'Change',
url_for('.service_set_inbound_sms',
service_id=current_service.id),
permissions=['manage_service']
)
}}
{% endcall %}
{% endcall %}
{% call mapping_table(
caption='Letters',
field_headings=['Label', 'Value', 'Action'],
field_headings_visible=False,
caption_visible=True
) %}
{% call row() %}
{{ text_field('Send letters') }}
{{ boolean_field('letter' in current_service.permissions) }}
{{ edit_field(
'Change',
url_for(
'.service_set_channel',
channel='letter',
service_id=current_service.id
),
permissions=['manage_service']
)}}
{% endcall %}
{% call settings_row(if_has_permission='letter') %}
{{ text_field('Sender addresses') }}
{% call field(status='default' if current_service.default_letter_contact_block == None else '') %}
{{ current_service.default_letter_contact_block | string | nl2br | safe if current_service.default_letter_contact_block else 'Not set'}}
{% if current_service.count_letter_contact_details > 1 %}
<div class="hint">
{{ '…and %d more' | format(current_service.count_letter_contact_details - 1) }}
</div>
{% endif %}
{% endcall %}
{{ edit_field(
'Manage' if current_service.count_letter_contact_details else 'Change',
url_for('.service_letter_contact_details',
service_id=current_service.id),
permissions=['manage_service','manage_api_keys']
)
}}
{% endcall %}
{% call settings_row(if_has_permission='letter') %}
{{ text_field('Letter branding') }}
{{ optional_text_field(current_service.letter_branding.name) }}
{{ edit_field(
'Change',
url_for('.request_letter_branding', service_id=current_service.id),
permissions=['manage_service']
)}}
{% endcall %}
{% endcall %}
</div>
{% if current_service.trial_mode %}
<h2 class="heading-medium">Your service is in trial mode</h2>
<ul class='list list-bullet'>
<li>you can only send messages to yourself</li>
<li>you can add people to your team, then you can send messages to them too</li>
<li>you can only send {{ current_service.message_limit }} messages per day</li>
</ul>
<p>
{% if current_user.has_permissions('manage_service') %}
To remove these restrictions
<a href="{{ url_for('.request_to_go_live', service_id=current_service.id) }}">request to go live</a>.
{% else %}
Your service manager can ask to have these restrictions removed.
{% endif %}
</p>
{% else %}
<h2 class="heading-medium">Your service is live</h2>
<p>
You can send up to
{{ "{:,}".format(current_service.message_limit) }} messages
per day.
</p>
<p>
Problems or comments?
<a href="{{ url_for('main.support') }}">Give feedback</a>.
</p>
{% endif %}
{% if current_user.platform_admin %}
<h2 class="heading-medium">Platform admin settings</h2>
{% call mapping_table(
caption='Settings',
field_headings=['Label', 'Value', 'Action'],
field_headings_visible=False,
caption_visible=False
) %}
{% call row() %}
{{ text_field('Live')}}
{{ boolean_field(not current_service.trial_mode) }}
{{ edit_field('Change', url_for('.service_switch_live', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Organisation')}}
{{ optional_text_field(current_service.organisation_name) }}
{{ edit_field('Change', url_for('.link_service_to_organisation', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Organisation type')}}
{{ optional_text_field(
(current_service.organisation_type or '')|title
) }}
{{ edit_field('Change', url_for('.set_organisation_type', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Free text message allowance')}}
{{ text_field('{:,}'.format(current_service.free_sms_fragment_limit)) }}
{{ edit_field('Change', url_for('.set_free_sms_allowance', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Email branding' )}}
{{ text_field(current_service.email_branding.name or 'GOV.UK') }}
{{ edit_field('Change', url_for('.service_set_email_branding', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Letter branding')}}
{{ optional_text_field(current_service.letter_branding.name) }}
{{ edit_field('Change', url_for('.service_set_letter_branding', service_id=current_service.id)) }}
{% endcall %}
{% call row() %}
{{ text_field('Data retention')}}
{% call field() %}
{{ current_service.data_retention | join(', ', attribute='notification_type') }}
{% endcall %}
{{ edit_field('Change', url_for('.data_retention', service_id=current_service.id)) }}
{% endcall %}
{% for permission in service_permissions %}
{% if not service_permissions[permission].requires or current_service.has_permission(service_permissions[permission].requires) %}
{% call row() %}
{{ text_field(service_permissions[permission].title)}}
{{ boolean_field(current_service.has_permission(permission)) }}
{{ edit_field('Change', url_for(service_permissions[permission].endpoint or '.service_set_permission', service_id=current_service.id, permission=permission if not service_permissions[permission].endpoint else None)) }}
{% endcall %}
{% endif %}
{% endfor %}
{% endcall %}
<ul>
{% if current_service.active %}
<li class="bottom-gutter">
<a href="{{ url_for('.archive_service', service_id=current_service.id) }}" class="button">
Archive service
</a>
</li>
<li class="bottom-gutter">
<a href="{{ url_for('.suspend_service', service_id=current_service.id) }}" class="button">
Suspend service
</a>
</li>
{% else %}
<li class="bottom-gutter">
<a href="{{ url_for('.resume_service', service_id=current_service.id) }}" class="button">
Resume service
</a>
</li>
{% endif %}
</ul>
{% endif %}
{% endblock %}
}