mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-11 10:28:41 -04:00
Merge pull request #3772 from alphagov/add-service-notes
Add service notes
This commit is contained in:
@@ -156,6 +156,18 @@
|
||||
|
||||
}
|
||||
|
||||
td.table-field-wrap-text {
|
||||
|
||||
div {
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
ul li {
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.table-heading {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
@@ -1706,6 +1706,10 @@ class ServiceEditInboundNumberForm(StripWhitespaceForm):
|
||||
is_default = GovukCheckboxField("Make this text message sender the default")
|
||||
|
||||
|
||||
class EditServiceNotesForm(StripWhitespaceForm):
|
||||
notes = TextAreaField(validators=[])
|
||||
|
||||
|
||||
class ServiceLetterContactBlockForm(StripWhitespaceForm):
|
||||
letter_contact_block = TextAreaField(
|
||||
validators=[
|
||||
|
||||
@@ -34,6 +34,7 @@ from app.main import main
|
||||
from app.main.forms import (
|
||||
BrandingOptions,
|
||||
ConfirmPasswordForm,
|
||||
EditServiceNotesForm,
|
||||
EstimateUsageForm,
|
||||
FreeSMSAllowance,
|
||||
LinkOrganisationsForm,
|
||||
@@ -1188,6 +1189,27 @@ def edit_data_retention(service_id, data_retention_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<uuid:service_id>/notes", methods=['GET', 'POST'])
|
||||
@user_has_permissions('manage_service')
|
||||
def edit_service_notes(service_id):
|
||||
form = EditServiceNotesForm(notes=current_service.notes)
|
||||
|
||||
if form.validate_on_submit():
|
||||
|
||||
if form.notes.data == current_service.notes:
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
current_service.update(
|
||||
notes=form.notes.data
|
||||
)
|
||||
return redirect(url_for('.service_settings', service_id=service_id))
|
||||
|
||||
return render_template(
|
||||
'views/service-settings/edit-service-notes.html',
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
def get_branding_as_value_and_label(email_branding):
|
||||
return [
|
||||
(branding['id'], branding['name'])
|
||||
|
||||
@@ -37,6 +37,7 @@ class Service(JSONModel):
|
||||
'message_limit',
|
||||
'rate_limit',
|
||||
'name',
|
||||
'notes',
|
||||
'prefix_sms',
|
||||
'research_mode',
|
||||
'service_callback_api',
|
||||
|
||||
@@ -190,6 +190,7 @@ class HeaderNavigation(Navigation):
|
||||
'edit_organisation_name',
|
||||
'edit_organisation_type',
|
||||
'edit_provider',
|
||||
'edit_service_notes',
|
||||
'edit_service_template',
|
||||
'edit_template_postage',
|
||||
'edit_user_org_permissions',
|
||||
@@ -582,6 +583,7 @@ class MainNavigation(Navigation):
|
||||
'edit_organisation_name',
|
||||
'edit_organisation_type',
|
||||
'edit_provider',
|
||||
'edit_service_notes',
|
||||
'edit_sms_provider_ratio',
|
||||
'edit_user_org_permissions',
|
||||
'email_branding',
|
||||
@@ -835,6 +837,7 @@ class CaseworkNavigation(Navigation):
|
||||
'edit_organisation_name',
|
||||
'edit_organisation_type',
|
||||
'edit_provider',
|
||||
'edit_service_notes',
|
||||
'edit_sms_provider_ratio',
|
||||
'edit_service_template',
|
||||
'edit_template_postage',
|
||||
@@ -1158,6 +1161,7 @@ class OrgNavigation(Navigation):
|
||||
'download_notifications_csv',
|
||||
'edit_data_retention',
|
||||
'edit_provider',
|
||||
'edit_service_notes',
|
||||
'edit_service_template',
|
||||
'edit_sms_provider_ratio',
|
||||
'edit_template_postage',
|
||||
|
||||
@@ -109,12 +109,12 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
'go_live_user',
|
||||
'go_live_at',
|
||||
'rate_limit',
|
||||
'notes',
|
||||
}
|
||||
if disallowed_attributes:
|
||||
raise TypeError('Not allowed to update service attributes: {}'.format(
|
||||
", ".join(disallowed_attributes)
|
||||
))
|
||||
|
||||
endpoint = "/service/{0}".format(service_id)
|
||||
return self.post(endpoint, data)
|
||||
|
||||
|
||||
@@ -63,12 +63,13 @@
|
||||
{% endif %}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro field(align='left', status='', border=True, colspan=None) -%}
|
||||
{% macro field(align='left', status='', border=True, colspan=None, wrap=False) -%}
|
||||
|
||||
{% set field_alignment = 'table-field-right-aligned' if align == 'right' else 'table-field-left-aligned' %}
|
||||
{% set border = '' if border else 'table-field-noborder' %}
|
||||
{% set wrap = 'table-field-wrap-text' if wrap else '' %}
|
||||
|
||||
<td class="{{ [field_alignment, border]|join(' ') }}" {% if colspan %}colspan="{{ colspan }}"{% endif %}>
|
||||
<td class="{{ [field_alignment, border, wrap]|join(' ') }}" {% if colspan %}colspan="{{ colspan }}"{% endif %}>
|
||||
<div class="{{ 'table-field-status-' + status if status }}">{{ caller() }}</div>
|
||||
</td>
|
||||
{%- endmacro %}
|
||||
@@ -85,8 +86,8 @@
|
||||
</td>
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro text_field(text, status='', truncate=false) -%}
|
||||
{% call field(status=status) %}
|
||||
{% macro text_field(text, status='', truncate=false, wrap=False) -%}
|
||||
{% call field(status=status, wrap=wrap) %}
|
||||
{% if text is iterable and text is not string %}
|
||||
<ul>
|
||||
{% for item in text %}
|
||||
@@ -105,11 +106,12 @@
|
||||
{% endcall %}
|
||||
{%- endmacro %}
|
||||
|
||||
{% macro optional_text_field(text, default='Not set', truncate=false) -%}
|
||||
{% macro optional_text_field(text, default='Not set', truncate=false, wrap=False) -%}
|
||||
{{ text_field(
|
||||
text or default,
|
||||
status='' if text else 'default',
|
||||
truncate=truncate
|
||||
truncate=truncate,
|
||||
wrap=wrap
|
||||
) }}
|
||||
{%- endmacro %}
|
||||
|
||||
|
||||
@@ -335,6 +335,12 @@
|
||||
{{ edit_field('Change', url_for('.service_switch_count_as_live', service_id=current_service.id), suffix='if service is counted in list of live services') }}
|
||||
{% endcall %}
|
||||
|
||||
{% call row() %}
|
||||
{{ text_field('Notes')}}
|
||||
{{ optional_text_field(current_service.notes, default="No notes yet", wrap=True) }}
|
||||
{{ edit_field('Change', url_for('.edit_service_notes', service_id=current_service.id), suffix='the notes for the service') }}
|
||||
{% endcall %}
|
||||
|
||||
{% call row() %}
|
||||
{{ text_field('Organisation')}}
|
||||
{% call field() %}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
{% 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 %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
|
||||
{% block service_page_title %}
|
||||
Data retention
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
{{ page_header(
|
||||
'Edit service notes',
|
||||
back_link=url_for('.service_settings', service_id=current_service.id)
|
||||
) }}
|
||||
{% call form_wrapper() %}
|
||||
{{ textbox(
|
||||
form.notes,
|
||||
rows=4,
|
||||
width='1-1',
|
||||
autofocus=True,
|
||||
autosize=True,
|
||||
) }}
|
||||
{{ page_footer('Save') }}
|
||||
{% endcall %}
|
||||
|
||||
{% endblock %}
|
||||
@@ -150,6 +150,7 @@ def service_json(
|
||||
contact_link=None,
|
||||
organisation_id=None,
|
||||
rate_limit=3000,
|
||||
notes=None,
|
||||
):
|
||||
if users is None:
|
||||
users = []
|
||||
@@ -188,6 +189,7 @@ def service_json(
|
||||
'consent_to_research': True,
|
||||
'count_as_live': True,
|
||||
'organisation': organisation_id,
|
||||
'notes': notes
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ def mock_get_service_settings_page_common(
|
||||
'Label Value Action',
|
||||
'Live Off Change service status',
|
||||
'Count in list of live services Yes Change if service is counted in list of live services',
|
||||
'Notes No notes yet Change the notes for the service',
|
||||
'Organisation Test organisation Central government Change organisation for service',
|
||||
'Rate limit 3,000 per minute Change rate limit',
|
||||
'Message limit 1,000 per day Change daily message limit',
|
||||
@@ -5231,3 +5232,51 @@ def test_update_service_data_retention_populates_form(
|
||||
assert response.status_code == 200
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.find('input', attrs={'name': 'days_of_retention'})['value'] == '5'
|
||||
|
||||
|
||||
def test_service_settings_links_to_edit_service_notes_page_for_platform_admins(
|
||||
mocker,
|
||||
service_one,
|
||||
platform_admin_client,
|
||||
no_reply_to_email_addresses,
|
||||
no_letter_contact_blocks,
|
||||
single_sms_sender,
|
||||
mock_get_service_settings_page_common,
|
||||
mock_get_organisation,
|
||||
):
|
||||
response = platform_admin_client.get(url_for(
|
||||
'.service_settings', service_id=SERVICE_ONE_ID
|
||||
))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert len(page.find_all('a', attrs={'href': '/services/{}/notes'.format(SERVICE_ONE_ID)})) == 1
|
||||
|
||||
|
||||
def test_view_edit_service_notes(
|
||||
platform_admin_client,
|
||||
service_one,
|
||||
|
||||
):
|
||||
response = platform_admin_client.get(url_for('main.edit_service_notes', service_id=SERVICE_ONE_ID))
|
||||
page = BeautifulSoup(response.data.decode('utf-8'), 'html.parser')
|
||||
assert page.select_one('h1').text == "Edit service notes"
|
||||
assert page.find('label', class_="form-label").text.strip() == "Notes"
|
||||
assert page.find('textarea').attrs["name"] == "notes"
|
||||
|
||||
|
||||
def test_update_service_notes(
|
||||
platform_admin_client,
|
||||
service_one,
|
||||
mock_update_service
|
||||
):
|
||||
response = platform_admin_client.post(
|
||||
url_for(
|
||||
'main.edit_service_notes',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
),
|
||||
data={'notes': "Very fluffy"}
|
||||
)
|
||||
assert response.status_code == 302
|
||||
settings_url = url_for(
|
||||
'main.service_settings', service_id=SERVICE_ONE_ID, _external=True)
|
||||
assert settings_url == response.location
|
||||
mock_update_service.assert_called_with(SERVICE_ONE_ID, notes="Very fluffy")
|
||||
|
||||
Reference in New Issue
Block a user