mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-28 03:39:29 -04:00
Only show contact lists relevant to template
You can’t send an email message template to a list of phone numbers. So we shouldn’t show you the lists of phone numbers when you’ve chosen an email template.
This commit is contained in:
@@ -498,9 +498,18 @@ def send_test_preview(service_id, template_id, filetype):
|
||||
)
|
||||
@user_has_permissions('send_messages')
|
||||
def choose_from_contact_list(service_id, template_id):
|
||||
db_template = current_service.get_template_with_user_permission_or_403(
|
||||
template_id, current_user
|
||||
)
|
||||
template = get_template(
|
||||
db_template, current_service,
|
||||
)
|
||||
return render_template(
|
||||
'views/send-contact-list.html',
|
||||
contact_lists=ContactLists(current_service.id),
|
||||
contact_lists=ContactLists(
|
||||
current_service.id,
|
||||
template_type=template.template_type,
|
||||
),
|
||||
template=current_service.get_template(template_id),
|
||||
)
|
||||
|
||||
|
||||
@@ -125,5 +125,13 @@ class ContactList(JSONModel):
|
||||
|
||||
|
||||
class ContactLists(ModelList):
|
||||
|
||||
client_method = contact_list_api_client.get_contact_lists
|
||||
model = ContactList
|
||||
|
||||
def __init__(self, service_id, template_type=None):
|
||||
super().__init__(service_id)
|
||||
self.items = [
|
||||
item for item in self.items
|
||||
if template_type in {item['template_type'], None}
|
||||
]
|
||||
|
||||
@@ -15,39 +15,48 @@
|
||||
back_link=url_for('.send_one_off', service_id=current_service.id, template_id=template.id)
|
||||
) }}
|
||||
|
||||
<div class='dashboard-table ajax-block-container'>
|
||||
{% call(item, row_number) list_table(
|
||||
contact_lists,
|
||||
caption="Existing contact lists",
|
||||
caption_visible=False,
|
||||
empty_message=(
|
||||
'You don’t have any contact lists yet'
|
||||
),
|
||||
field_headings=[
|
||||
'File',
|
||||
'Status'
|
||||
],
|
||||
field_headings_visible=False
|
||||
) %}
|
||||
{% call row_heading() %}
|
||||
<div class="file-list">
|
||||
<a class="file-list-filename-large govuk-link govuk-link--no-visited-state" href="{{ url_for('main.send_from_contact_list', service_id=current_service.id, template_id=template.id, contact_list_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||
<span class="file-list-hint">
|
||||
Uploaded {{ item.created_at|format_datetime_relative }}
|
||||
</span>
|
||||
</div>
|
||||
{% endcall %}
|
||||
{% call field() %}
|
||||
{{ big_number(
|
||||
item.row_count,
|
||||
smallest=True,
|
||||
label=recipient_count_label(
|
||||
{% if contact_lists %}
|
||||
<div class='dashboard-table ajax-block-container'>
|
||||
{% call(item, row_number) list_table(
|
||||
contact_lists,
|
||||
caption="Existing contact lists",
|
||||
caption_visible=False,
|
||||
empty_message=(
|
||||
'You don’t have any contact lists yet'
|
||||
),
|
||||
field_headings=[
|
||||
'File',
|
||||
'Status'
|
||||
],
|
||||
field_headings_visible=False
|
||||
) %}
|
||||
{% call row_heading() %}
|
||||
<div class="file-list">
|
||||
<a class="file-list-filename-large govuk-link govuk-link--no-visited-state" href="{{ url_for('main.send_from_contact_list', service_id=current_service.id, template_id=template.id, contact_list_id=item.id) }}">{{ item.original_file_name }}</a>
|
||||
<span class="file-list-hint">
|
||||
Uploaded {{ item.created_at|format_datetime_relative }}
|
||||
</span>
|
||||
</div>
|
||||
{% endcall %}
|
||||
{% call field() %}
|
||||
{{ big_number(
|
||||
item.row_count,
|
||||
item.template_type
|
||||
)
|
||||
) }}
|
||||
smallest=True,
|
||||
label=recipient_count_label(
|
||||
item.row_count,
|
||||
item.template_type
|
||||
)
|
||||
) }}
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
{% endcall %}
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<p class="govuk-body">
|
||||
You have not saved any lists of {{ recipient_count_label(99, template.template_type) }} yet.
|
||||
</p>
|
||||
<p class="govuk-body">
|
||||
To upload and save a new contact list, go to the <a class="govuk-link govuk-link--no-visited-state" href="{{ url_for('main.uploads', service_id=current_service.id) }}">uploads</a> page.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -3839,37 +3839,96 @@ def test_redirects_to_template_if_job_exists_already(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize((
|
||||
'template_type, '
|
||||
'expected_list_id, '
|
||||
'expected_filename, '
|
||||
'expected_time, '
|
||||
'expected_count'
|
||||
), (
|
||||
(
|
||||
'email',
|
||||
'6ce466d0-fd6a-11e5-82f5-e0accb9d11a6',
|
||||
'EmergencyContactList.xls',
|
||||
'Uploaded today at 10:59am',
|
||||
'100 email addresses',
|
||||
),
|
||||
(
|
||||
'sms',
|
||||
'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
|
||||
'phone number list.csv',
|
||||
'Uploaded today at 1:00pm',
|
||||
'123 phone numbers',
|
||||
),
|
||||
))
|
||||
@freeze_time('2020-03-13 13:00')
|
||||
def test_choose_from_contact_list(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_service_template,
|
||||
mock_get_contact_lists,
|
||||
fake_uuid,
|
||||
template_type,
|
||||
expected_list_id,
|
||||
expected_filename,
|
||||
expected_time,
|
||||
expected_count,
|
||||
):
|
||||
template = create_template(template_type=template_type)
|
||||
mocker.patch(
|
||||
'app.service_api_client.get_service_template',
|
||||
return_value={'data': template},
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
)
|
||||
assert len(page.select('.file-list-filename-large')) == 2
|
||||
assert len(page.select('.file-list-filename-large')) == 1
|
||||
assert normalize_spaces(page.select_one('.file-list-filename-large').text) == (
|
||||
'EmergencyContactList.xls'
|
||||
expected_filename
|
||||
)
|
||||
assert page.select_one('a.file-list-filename-large')['href'] == url_for(
|
||||
'main.send_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
contact_list_id=fake_uuid,
|
||||
template_id=template['id'],
|
||||
contact_list_id=expected_list_id,
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.file-list-hint').text) == (
|
||||
'Uploaded today at 10:59am'
|
||||
expected_time
|
||||
)
|
||||
assert normalize_spaces(page.select_one('.big-number-smallest').text) == (
|
||||
'100 email addresses'
|
||||
expected_count
|
||||
)
|
||||
|
||||
|
||||
def test_choose_from_contact_list_with_no_lists(
|
||||
mocker,
|
||||
client_request,
|
||||
mock_get_service_template,
|
||||
fake_uuid,
|
||||
):
|
||||
mocker.patch(
|
||||
'app.models.contact_list.ContactLists.client_method',
|
||||
return_value=[],
|
||||
)
|
||||
page = client_request.get(
|
||||
'main.choose_from_contact_list',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
template_id=fake_uuid,
|
||||
)
|
||||
assert [
|
||||
normalize_spaces(p.text) for p in page.select('main p')
|
||||
] == [
|
||||
'You have not saved any lists of phone numbers yet.',
|
||||
'To upload and save a new contact list, go to the uploads page.',
|
||||
]
|
||||
assert page.select_one('main p a')['href'] == url_for(
|
||||
'main.uploads',
|
||||
service_id=SERVICE_ONE_ID,
|
||||
)
|
||||
assert not page.select('table')
|
||||
|
||||
|
||||
def test_send_from_contact_list(
|
||||
mocker,
|
||||
client_request,
|
||||
|
||||
@@ -1844,7 +1844,7 @@ def mock_create_contact_list(mocker, api_user_active):
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_contact_lists(mocker, api_user_active, fake_uuid):
|
||||
def _get(service_id):
|
||||
def _get(service_id, template_type=None):
|
||||
return [{
|
||||
'created_at': '2020-03-13 10:59:56',
|
||||
'created_by': 'Test User',
|
||||
@@ -1856,8 +1856,8 @@ def mock_get_contact_lists(mocker, api_user_active, fake_uuid):
|
||||
}, {
|
||||
'created_at': '2020-03-13 13:00:00',
|
||||
'created_by': 'Test User',
|
||||
'id': uuid4(),
|
||||
'original_file_name': 'another ist.csv',
|
||||
'id': 'd7b0bd1a-d1c7-4621-be5c-3c1b4278a2ad',
|
||||
'original_file_name': 'phone number list.csv',
|
||||
'row_count': 123,
|
||||
'service_id': service_id,
|
||||
'template_type': 'sms',
|
||||
|
||||
Reference in New Issue
Block a user