mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-09 06:13:11 -04:00
Allow platform admins to change daily message limit
One less thing we have to go into the database to do, and remember to manually clear the cache for after.
This commit is contained in:
@@ -1174,6 +1174,15 @@ class FreeSMSAllowance(StripWhitespaceForm):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MessageLimit(StripWhitespaceForm):
|
||||||
|
message_limit = GovukIntegerField(
|
||||||
|
'Number of messages the service is allowed to send each day',
|
||||||
|
validators=[
|
||||||
|
DataRequired(message='Cannot be empty')
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ConfirmPasswordForm(StripWhitespaceForm):
|
class ConfirmPasswordForm(StripWhitespaceForm):
|
||||||
def __init__(self, validate_password_func, *args, **kwargs):
|
def __init__(self, validate_password_func, *args, **kwargs):
|
||||||
self.validate_password_func = validate_password_func
|
self.validate_password_func = validate_password_func
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ from app.main.forms import (
|
|||||||
EstimateUsageForm,
|
EstimateUsageForm,
|
||||||
FreeSMSAllowance,
|
FreeSMSAllowance,
|
||||||
LinkOrganisationsForm,
|
LinkOrganisationsForm,
|
||||||
|
MessageLimit,
|
||||||
PreviewBranding,
|
PreviewBranding,
|
||||||
RenameServiceForm,
|
RenameServiceForm,
|
||||||
SearchByNameForm,
|
SearchByNameForm,
|
||||||
@@ -938,6 +939,23 @@ def set_free_sms_allowance(service_id):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<uuid:service_id>/service-settings/set-message-limit", methods=['GET', 'POST'])
|
||||||
|
@user_is_platform_admin
|
||||||
|
def set_message_limit(service_id):
|
||||||
|
|
||||||
|
form = MessageLimit(message_limit=current_service.message_limit)
|
||||||
|
|
||||||
|
if form.validate_on_submit():
|
||||||
|
current_service.update(message_limit=form.message_limit.data)
|
||||||
|
|
||||||
|
return redirect(url_for('.service_settings', service_id=service_id))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'views/service-settings/set-message-limit.html',
|
||||||
|
form=form,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@main.route("/services/<uuid:service_id>/service-settings/set-email-branding", methods=['GET', 'POST'])
|
@main.route("/services/<uuid:service_id>/service-settings/set-email-branding", methods=['GET', 'POST'])
|
||||||
@user_is_platform_admin
|
@user_is_platform_admin
|
||||||
def service_set_email_branding(service_id):
|
def service_set_email_branding(service_id):
|
||||||
|
|||||||
@@ -316,6 +316,7 @@ class HeaderNavigation(Navigation):
|
|||||||
'service_verify_reply_to_address_updates',
|
'service_verify_reply_to_address_updates',
|
||||||
'services_or_dashboard',
|
'services_or_dashboard',
|
||||||
'set_free_sms_allowance',
|
'set_free_sms_allowance',
|
||||||
|
'set_message_limit',
|
||||||
'set_sender',
|
'set_sender',
|
||||||
'set_template_sender',
|
'set_template_sender',
|
||||||
'show_accounts_or_dashboard',
|
'show_accounts_or_dashboard',
|
||||||
@@ -503,6 +504,7 @@ class MainNavigation(Navigation):
|
|||||||
'service_settings',
|
'service_settings',
|
||||||
'service_sms_senders',
|
'service_sms_senders',
|
||||||
'set_free_sms_allowance',
|
'set_free_sms_allowance',
|
||||||
|
'set_message_limit',
|
||||||
'service_set_letter_branding',
|
'service_set_letter_branding',
|
||||||
'submit_request_to_go_live',
|
'submit_request_to_go_live',
|
||||||
},
|
},
|
||||||
@@ -969,6 +971,7 @@ class CaseworkNavigation(Navigation):
|
|||||||
'service_verify_reply_to_address_updates',
|
'service_verify_reply_to_address_updates',
|
||||||
'services_or_dashboard',
|
'services_or_dashboard',
|
||||||
'set_free_sms_allowance',
|
'set_free_sms_allowance',
|
||||||
|
'set_message_limit',
|
||||||
'service_set_letter_branding',
|
'service_set_letter_branding',
|
||||||
'set_sender',
|
'set_sender',
|
||||||
'set_template_sender',
|
'set_template_sender',
|
||||||
@@ -1281,6 +1284,7 @@ class OrgNavigation(Navigation):
|
|||||||
'service_verify_reply_to_address_updates',
|
'service_verify_reply_to_address_updates',
|
||||||
'services_or_dashboard',
|
'services_or_dashboard',
|
||||||
'set_free_sms_allowance',
|
'set_free_sms_allowance',
|
||||||
|
'set_message_limit',
|
||||||
'service_set_letter_branding',
|
'service_set_letter_branding',
|
||||||
'set_sender',
|
'set_sender',
|
||||||
'set_template_sender',
|
'set_template_sender',
|
||||||
|
|||||||
@@ -353,10 +353,14 @@
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{{ edit_field('Change', url_for('.link_service_to_organisation', service_id=current_service.id), suffix='organisation for service') }}
|
{{ edit_field('Change', url_for('.link_service_to_organisation', service_id=current_service.id), suffix='organisation for service') }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
|
{% call row() %}
|
||||||
|
{{ text_field('Message limit')}}
|
||||||
|
{{ text_field('{:,} per day'.format(current_service.message_limit)) }}
|
||||||
|
{{ edit_field('Change', url_for('.set_message_limit', service_id=current_service.id), suffix='daily message limit') }}
|
||||||
|
{% endcall %}
|
||||||
{% call row() %}
|
{% call row() %}
|
||||||
{{ text_field('Free text message allowance')}}
|
{{ text_field('Free text message allowance')}}
|
||||||
{{ text_field('{:,}'.format(current_service.free_sms_fragment_limit)) }}
|
{{ text_field('{:,} per year'.format(current_service.free_sms_fragment_limit)) }}
|
||||||
{{ edit_field('Change', url_for('.set_free_sms_allowance', service_id=current_service.id), suffix='free text message allowance') }}
|
{{ edit_field('Change', url_for('.set_free_sms_allowance', service_id=current_service.id), suffix='free text message allowance') }}
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call row() %}
|
{% call row() %}
|
||||||
|
|||||||
21
app/templates/views/service-settings/set-message-limit.html
Normal file
21
app/templates/views/service-settings/set-message-limit.html
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{% extends "withnav_template.html" %}
|
||||||
|
{% from "components/page-header.html" import page_header %}
|
||||||
|
{% from "components/page-footer.html" import page_footer %}
|
||||||
|
{% from "components/form.html" import form_wrapper %}
|
||||||
|
|
||||||
|
{% block service_page_title %}
|
||||||
|
Set daily message limit
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block maincolumn_content %}
|
||||||
|
|
||||||
|
{% call form_wrapper() %}
|
||||||
|
{{ page_header(
|
||||||
|
'Daily message limit',
|
||||||
|
back_link=url_for('.service_settings', service_id=current_service.id)
|
||||||
|
) }}
|
||||||
|
{{ form.message_limit }}
|
||||||
|
{{ page_footer('Save') }}
|
||||||
|
{% endcall %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
@@ -101,7 +101,8 @@ def mock_get_service_settings_page_common(
|
|||||||
'Live Off Change service status',
|
'Live Off Change service status',
|
||||||
'Count in list of live services Yes Change if service is counted in list of live services',
|
'Count in list of live services Yes Change if service is counted in list of live services',
|
||||||
'Organisation Test organisation Central government Change organisation for service',
|
'Organisation Test organisation Central government Change organisation for service',
|
||||||
'Free text message allowance 250,000 Change free text message allowance',
|
'Message limit 1,000 per day Change daily message limit',
|
||||||
|
'Free text message allowance 250,000 per year Change free text message allowance',
|
||||||
'Email branding GOV.UK Change email branding (admin view)',
|
'Email branding GOV.UK Change email branding (admin view)',
|
||||||
'Letter branding Not set Change letter branding (admin view)',
|
'Letter branding Not set Change letter branding (admin view)',
|
||||||
'Data retention email Change data retention',
|
'Data retention email Change data retention',
|
||||||
@@ -3577,6 +3578,7 @@ def test_should_set_branding_and_organisations(
|
|||||||
@pytest.mark.parametrize('method', ['get', 'post'])
|
@pytest.mark.parametrize('method', ['get', 'post'])
|
||||||
@pytest.mark.parametrize('endpoint', [
|
@pytest.mark.parametrize('endpoint', [
|
||||||
'main.set_free_sms_allowance',
|
'main.set_free_sms_allowance',
|
||||||
|
'main.set_message_limit',
|
||||||
])
|
])
|
||||||
def test_organisation_type_pages_are_platform_admin_only(
|
def test_organisation_type_pages_are_platform_admin_only(
|
||||||
client_request,
|
client_request,
|
||||||
@@ -3638,6 +3640,54 @@ def test_should_set_sms_allowance(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_page_to_set_message_limit(
|
||||||
|
platform_admin_client,
|
||||||
|
):
|
||||||
|
response = platform_admin_client.get(url_for(
|
||||||
|
'main.set_message_limit',
|
||||||
|
service_id=SERVICE_ONE_ID
|
||||||
|
))
|
||||||
|
assert response.status_code == 200
|
||||||
|
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||||
|
|
||||||
|
assert normalize_spaces(page.select_one('label').text) == (
|
||||||
|
'Number of messages the service is allowed to send each day'
|
||||||
|
)
|
||||||
|
assert normalize_spaces(page.select_one('input[type=text]')['value']) == (
|
||||||
|
'1000'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('new_limit, expected_api_argument', [
|
||||||
|
('1', 1),
|
||||||
|
('250000', 250000),
|
||||||
|
pytest.param('foo', 'foo', marks=pytest.mark.xfail),
|
||||||
|
])
|
||||||
|
def test_should_set_message_limit(
|
||||||
|
platform_admin_client,
|
||||||
|
new_limit,
|
||||||
|
expected_api_argument,
|
||||||
|
mock_update_service,
|
||||||
|
):
|
||||||
|
|
||||||
|
response = platform_admin_client.post(
|
||||||
|
url_for(
|
||||||
|
'main.set_message_limit',
|
||||||
|
service_id=SERVICE_ONE_ID,
|
||||||
|
),
|
||||||
|
data={
|
||||||
|
'message_limit': new_limit,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == url_for('main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||||
|
|
||||||
|
mock_update_service.assert_called_once_with(
|
||||||
|
SERVICE_ONE_ID,
|
||||||
|
message_limit=expected_api_argument,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_old_set_letters_page_redirects(
|
def test_old_set_letters_page_redirects(
|
||||||
client_request,
|
client_request,
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user