mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-05 23:18:24 -04:00
Add multiple letter contact blocks for services from Admin app
This commit is contained in:
@@ -480,13 +480,14 @@ class ServiceSmsSender(Form):
|
||||
raise ValidationError('Use letters and numbers only')
|
||||
|
||||
|
||||
class ServiceLetterContactBlock(Form):
|
||||
class ServiceLetterContactBlockForm(Form):
|
||||
letter_contact_block = TextAreaField(
|
||||
validators=[
|
||||
DataRequired(message="Can’t be empty"),
|
||||
NoCommasInPlaceHolders()
|
||||
]
|
||||
)
|
||||
is_default = BooleanField("Set as your default address")
|
||||
|
||||
def validate_letter_contact_block(form, field):
|
||||
line_count = field.data.strip().count('\n')
|
||||
|
||||
@@ -29,7 +29,7 @@ from app.main.forms import (
|
||||
RequestToGoLiveForm,
|
||||
ServiceReplyToEmailForm,
|
||||
ServiceSmsSender,
|
||||
ServiceLetterContactBlock,
|
||||
ServiceLetterContactBlockForm,
|
||||
ServiceBrandingOrg,
|
||||
LetterBranding,
|
||||
ServiceInboundApiForm,
|
||||
@@ -75,6 +75,11 @@ def service_settings(service_id):
|
||||
default_reply_to_email_address = next(
|
||||
(x['email_address'] for x in reply_to_email_addresses if x['is_default']), "None"
|
||||
)
|
||||
letter_contact_details = service_api_client.get_letter_contacts(service_id)
|
||||
letter_contact_details_count = len(letter_contact_details)
|
||||
default_letter_contact_block = next(
|
||||
(Field(x['contact_block'], html='escape') for x in letter_contact_details if x['is_default']), "None"
|
||||
)
|
||||
return render_template(
|
||||
'views/service-settings.html',
|
||||
organisation=organisation,
|
||||
@@ -83,10 +88,11 @@ def service_settings(service_id):
|
||||
),
|
||||
can_receive_inbound=('inbound_sms' in current_service['permissions']),
|
||||
inbound_api_url=inbound_api_url,
|
||||
letter_contact_block=Field(current_service['letter_contact_block'], html='escape'),
|
||||
inbound_number=disp_inbound_number,
|
||||
default_reply_to_email_address=default_reply_to_email_address,
|
||||
reply_to_email_address_count=reply_to_email_address_count
|
||||
reply_to_email_address_count=reply_to_email_address_count,
|
||||
default_letter_contact_block=default_letter_contact_block,
|
||||
letter_contact_details_count=letter_contact_details_count
|
||||
)
|
||||
|
||||
|
||||
@@ -491,6 +497,58 @@ def service_set_letters(service_id):
|
||||
)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/letter-contacts", methods=['GET'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_letter_contact_details(service_id):
|
||||
letter_contact_details = service_api_client.get_letter_contacts(service_id)
|
||||
return render_template(
|
||||
'views/service-settings/letter-contact-details.html',
|
||||
letter_contact_details=letter_contact_details)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/letter-contact/add", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_add_letter_contact(service_id):
|
||||
form = ServiceLetterContactBlockForm()
|
||||
letter_contact_blocks_count = len(service_api_client.get_letter_contacts(service_id))
|
||||
first_contact_block = letter_contact_blocks_count == 0
|
||||
if form.validate_on_submit():
|
||||
service_api_client.add_letter_contact(
|
||||
current_service['id'],
|
||||
contact_block=form.letter_contact_block.data.replace('\r', '') or None,
|
||||
is_default=first_contact_block if first_contact_block else form.is_default.data
|
||||
)
|
||||
return redirect(url_for('.service_letter_contact_details', service_id=service_id))
|
||||
return render_template(
|
||||
'views/service-settings/letter-contact/add.html',
|
||||
form=form,
|
||||
first_contact_block=first_contact_block)
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/letter-contact/<letter_contact_id>/edit", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
def service_edit_letter_contact(service_id, letter_contact_id):
|
||||
letter_contact_block = service_api_client.get_letter_contact(service_id, letter_contact_id)
|
||||
form = ServiceLetterContactBlockForm(letter_contact_block=letter_contact_block['contact_block'])
|
||||
if request.method == 'GET':
|
||||
form.is_default.data = letter_contact_block['is_default']
|
||||
if form.validate_on_submit():
|
||||
service_api_client.update_letter_contact(
|
||||
current_service['id'],
|
||||
letter_contact_id=letter_contact_id,
|
||||
contact_block=form.letter_contact_block.data.replace('\r', '') or None,
|
||||
is_default=True if letter_contact_block['is_default'] else form.is_default.data
|
||||
)
|
||||
return redirect(url_for('.service_letter_contact_details', service_id=service_id))
|
||||
return render_template(
|
||||
'views/service-settings/letter-contact/edit.html',
|
||||
form=form,
|
||||
letter_contact_id=letter_contact_block['id'])
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/service-settings/set-letter-contact-block", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions('manage_settings', admin_override=True)
|
||||
@@ -499,7 +557,7 @@ def service_set_letter_contact_block(service_id):
|
||||
if 'letter' not in current_service['permissions']:
|
||||
abort(403)
|
||||
|
||||
form = ServiceLetterContactBlock(letter_contact_block=current_service['letter_contact_block'])
|
||||
form = ServiceLetterContactBlockForm(letter_contact_block=current_service['letter_contact_block'])
|
||||
if form.validate_on_submit():
|
||||
service_api_client.update_service(
|
||||
current_service['id'],
|
||||
|
||||
@@ -57,6 +57,13 @@ page_headings = {
|
||||
)
|
||||
def view_template(service_id, template_id):
|
||||
template = service_api_client.get_service_template(service_id, str(template_id))['data']
|
||||
if template["template_type"] == "letter":
|
||||
letter_contact_details = service_api_client.get_letter_contacts(service_id)
|
||||
default_letter_contact_block_id = next(
|
||||
(x['id'] for x in letter_contact_details if x['is_default']), "None"
|
||||
)
|
||||
else:
|
||||
default_letter_contact_block_id = None
|
||||
return render_template(
|
||||
'views/templates/template.html',
|
||||
template=get_template(
|
||||
@@ -72,6 +79,7 @@ def view_template(service_id, template_id):
|
||||
show_recipient=True,
|
||||
page_count=get_page_count_for_letter(template),
|
||||
),
|
||||
default_letter_contact_block_id=default_letter_contact_block_id
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -318,6 +318,42 @@ class ServiceAPIClient(NotifyAdminAPIClient):
|
||||
}
|
||||
)
|
||||
|
||||
def get_letter_contacts(self, service_id):
|
||||
return self.get(
|
||||
"/service/{}/letter-contact".format(
|
||||
service_id
|
||||
)
|
||||
)
|
||||
|
||||
def get_letter_contact(self, service_id, letter_contact_id):
|
||||
return self.get(
|
||||
"/service/{}/letter-contact/{}".format(
|
||||
service_id,
|
||||
letter_contact_id
|
||||
)
|
||||
)
|
||||
|
||||
def add_letter_contact(self, service_id, contact_block, is_default=False):
|
||||
return self.post(
|
||||
"/service/{}/letter-contact".format(service_id),
|
||||
data={
|
||||
"contact_block": contact_block,
|
||||
"is_default": is_default
|
||||
}
|
||||
)
|
||||
|
||||
def update_letter_contact(self, service_id, letter_contact_id, contact_block, is_default=False):
|
||||
return self.post(
|
||||
"/service/{}/letter-contact/{}".format(
|
||||
service_id,
|
||||
letter_contact_id,
|
||||
),
|
||||
data={
|
||||
"contact_block": contact_block,
|
||||
"is_default": is_default
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class ServicesBrowsableItem(BrowsableItem):
|
||||
@property
|
||||
|
||||
@@ -137,11 +137,16 @@
|
||||
|
||||
{% if 'letter' in current_service.permissions %}
|
||||
{% call row() %}
|
||||
{{ text_field('Letter contact details') }}
|
||||
{% call field(status='' if current_service.letter_contact_block else 'default') %}
|
||||
{{ letter_contact_block | string | nl2br | safe if current_service.letter_contact_block else 'None'}}
|
||||
{{ text_field('Sender addresses') }}
|
||||
{% call field(status='default' if default_letter_contact_block == "None" else '') %}
|
||||
{{ default_letter_contact_block | string | nl2br | safe if default_letter_contact_block else 'None'}}
|
||||
{% if letter_contact_details_count > 1 %}
|
||||
<div class="hint">
|
||||
{{ '…and %d more' | format(letter_contact_details_count - 1) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endcall %}
|
||||
{{ edit_field('Change', url_for('.service_set_letter_contact_block', service_id=current_service.id)) }}
|
||||
{{ edit_field('Manage' if letter_contact_details_count else 'Change', url_for('.service_letter_contact_details', service_id=current_service.id)) }}
|
||||
{% endcall %}
|
||||
{% endif %}
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/api-key.html" import api_key %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
{% from "components/table.html" import row_group, row, text_field, edit_field, field, boolean_field, list_table %}
|
||||
|
||||
{% block service_page_title %}
|
||||
Sender addresses
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<div class="grid-row bottom-gutter">
|
||||
<div class="column-two-thirds">
|
||||
<h1 class="heading-large">
|
||||
Sender addresses
|
||||
</h1>
|
||||
</div>
|
||||
<div class="column-one-third">
|
||||
<a href="{{ url_for('.service_add_letter_contact', service_id=current_service.id) }}" class="button align-with-heading">Add a new address</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="user-list">
|
||||
{% if not letter_contact_details %}
|
||||
<div class="user-list-item">
|
||||
<span class="hint">You haven’t added any letter contact details yet</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for item in letter_contact_details %}
|
||||
<div class="user-list-item">
|
||||
<h3>
|
||||
<span class="heading-small">{{ item.contact_block }}</span> <span class="hint">
|
||||
{%- if item.is_default -%}
|
||||
(default)
|
||||
{% endif %}
|
||||
</span>
|
||||
</h3>
|
||||
<ul class="tick-cross-list">
|
||||
<li class="tick-cross-list-edit-link">
|
||||
<a href="{{ url_for('.service_edit_letter_contact', service_id =current_service.id, letter_contact_id = item.id) }}">Change</a>
|
||||
</li>
|
||||
</ul>
|
||||
{% if letter_contact_details|length > 1 %}
|
||||
{{ api_key(item.id, thing="ID") }}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
38
app/templates/views/service-settings/letter-contact/add.html
Normal file
38
app/templates/views/service-settings/letter-contact/add.html
Normal file
@@ -0,0 +1,38 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block service_page_title %}
|
||||
Add a new address
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Add a new address
|
||||
</h1>
|
||||
<div class="grid-row">
|
||||
<form method="post" class="column-half" novalidate>
|
||||
{{ textbox(
|
||||
form.letter_contact_block,
|
||||
label='This will appear as the ‘sender’ address on your letters.'|safe,
|
||||
hint='10 lines maximum',
|
||||
width='1-1',
|
||||
rows=10,
|
||||
highlight_tags=True
|
||||
) }}
|
||||
{% if not first_contact_block %}
|
||||
<div class="form-group">
|
||||
{{ checkbox(form.is_default) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{{ page_footer(
|
||||
'Add',
|
||||
back_link=url_for('.service_letter_contact_details', service_id=current_service.id),
|
||||
back_link_text='Back'
|
||||
) }}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,42 @@
|
||||
{% extends "withnav_template.html" %}
|
||||
{% from "components/textbox.html" import textbox %}
|
||||
{% from "components/checkbox.html" import checkbox %}
|
||||
{% from "components/page-footer.html" import page_footer %}
|
||||
|
||||
{% block service_page_title %}
|
||||
Edit an address
|
||||
{% endblock %}
|
||||
|
||||
{% block maincolumn_content %}
|
||||
|
||||
<h1 class="heading-large">
|
||||
Edit an address
|
||||
</h1>
|
||||
<div class="grid-row">
|
||||
<form method="post" class="column-half">
|
||||
{{ textbox(
|
||||
form.letter_contact_block,
|
||||
label='This will appear as the ‘sender’ address on your letters.'|safe,
|
||||
hint='10 lines maximum',
|
||||
width='1-1',
|
||||
rows=10,
|
||||
highlight_tags=True
|
||||
) }}
|
||||
{% if form.is_default.data %}
|
||||
<p class="form-group">
|
||||
This is currently your default address for {{ current_service.name }}
|
||||
</p>
|
||||
{% else %}
|
||||
<div class="form-group">
|
||||
{{ checkbox(form.is_default) }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{{ page_footer(
|
||||
'Save',
|
||||
back_link=None if request.args.get('from_template') else url_for('.service_letter_contact_details', service_id=current_service.id),
|
||||
back_link_text='Back to settings'
|
||||
) }}
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
@@ -35,7 +35,7 @@
|
||||
<div class="column-whole template-container">
|
||||
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) and template.template_type == 'letter' %}
|
||||
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}" class="edit-template-link-letter-body">Edit</a>
|
||||
<a href="{{ url_for(".service_set_letter_contact_block", service_id=current_service.id, from_template=template.id) }}" class="edit-template-link-letter-contact">Edit</a>
|
||||
<a href="{{ url_for(".service_edit_letter_contact", service_id=current_service.id, letter_contact_id=default_letter_contact_block_id, from_template=template.id) }}" class="edit-template-link-letter-contact">Edit</a>
|
||||
{% endif %}
|
||||
{{ template|string }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user