Only show the link to use list if service has lists

Most services won’t be interested in the contact list feature, so we
shouldn’t clutter up the interface with the extra link.
This commit is contained in:
Chris Hill-Scott
2020-03-16 10:14:11 +00:00
parent 6c2021aeb2
commit 31d2fd9b58
3 changed files with 33 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ from notifications_utils.timezones import local_timezone
from werkzeug.utils import cached_property from werkzeug.utils import cached_property
from app.models import JSONModel from app.models import JSONModel
from app.models.contact_list import ContactLists
from app.models.job import ( from app.models.job import (
ImmediateJobs, ImmediateJobs,
PaginatedJobs, PaginatedJobs,
@@ -695,3 +696,7 @@ class Service(JSONModel):
for report in self.returned_letter_summary for report in self.returned_letter_summary
if parse(report['reported_at'] + " 00:00:00") >= seven_days_ago if parse(report['reported_at'] + " 00:00:00") >= seven_days_ago
) )
@property
def contact_lists(self):
return ContactLists(self.id)

View File

@@ -33,7 +33,7 @@
<div class="govuk-grid-column-full"> <div class="govuk-grid-column-full">
{% if link_to_upload %} {% if link_to_upload %}
<a class="govuk-link govuk-link--no-visited-state govuk-!-margin-right-3" href="{{ url_for('.send_messages', service_id=current_service.id, template_id=template.id) }}">Upload a list of {{ recipient_count_label(999, template.template_type) }}</a> <a class="govuk-link govuk-link--no-visited-state govuk-!-margin-right-3" href="{{ url_for('.send_messages', service_id=current_service.id, template_id=template.id) }}">Upload a list of {{ recipient_count_label(999, template.template_type) }}</a>
{% if current_user.platform_admin %} {% if current_user.platform_admin and current_service.contact_lists %}
<a class="govuk-link govuk-link--no-visited-state govuk-!-margin-right-3" href="{{ url_for('.choose_from_contact_list', service_id=current_service.id, template_id=template.id) }}">Use a saved list</a> <a class="govuk-link govuk-link--no-visited-state govuk-!-margin-right-3" href="{{ url_for('.choose_from_contact_list', service_id=current_service.id, template_id=template.id) }}">Use a saved list</a>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@@ -1424,6 +1424,7 @@ def test_platform_admin_has_link_to_use_existing_list(
client_request, client_request,
mock_get_service_template, mock_get_service_template,
mock_has_jobs, mock_has_jobs,
mock_get_contact_lists,
fake_uuid, fake_uuid,
user, user,
): ):
@@ -1465,6 +1466,32 @@ def test_platform_admin_has_link_to_use_existing_list(
] ]
def test_no_link_to_use_existing_list_for_service_without_lists(
mocker,
client_request,
mock_get_service_template,
mock_has_jobs,
fake_uuid,
):
mocker.patch(
'app.models.contact_list.ContactLists.client_method',
return_value=[],
)
client_request.login(create_platform_admin_user())
page = client_request.get(
'main.send_one_off',
service_id=SERVICE_ONE_ID,
template_id=fake_uuid,
_follow_redirects=True,
)
assert [
link.text for link in page.select('form a')
] == [
'Upload a list of phone numbers',
'Use my phone number',
]
@pytest.mark.parametrize('user', ( @pytest.mark.parametrize('user', (
create_active_user_with_permissions(), create_active_user_with_permissions(),
create_active_caseworking_user(), create_active_caseworking_user(),