mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-04-23 10:40:58 -04:00
Merge pull request #742 from alphagov/view-of-deleted-template
Don’t show send/edit links for deleted template
This commit is contained in:
@@ -16,15 +16,21 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="column-one-third">
|
||||
<div class="message-use-links{% if show_title %}-with-title{% endif %}">
|
||||
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
|
||||
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}" class="primary">
|
||||
Send {{ 'text messages' if 'sms' == template.template_type else 'emails' }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
|
||||
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}">Edit template</a>
|
||||
{% endif %}
|
||||
<a href="{{ url_for(".send_from_api", service_id=current_service.id, template_id=template.id) }}">API info</a>
|
||||
</div>
|
||||
{% if template._template.archived %}
|
||||
<div class="message-updated-at">
|
||||
This template was deleted<br/>{{ template._template.updated_at|format_date_normal }}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="message-use-links{% if show_title %}-with-title{% endif %}">
|
||||
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
|
||||
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}" class="primary">
|
||||
Send {{ 'text messages' if 'sms' == template.template_type else 'emails' }}
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
|
||||
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}">Edit template</a>
|
||||
{% endif %}
|
||||
<a href="{{ url_for(".send_from_api", service_id=current_service.id, template_id=template.id) }}">API info</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
@@ -68,14 +68,17 @@ def template_json(service_id,
|
||||
type_="sms",
|
||||
content="template content",
|
||||
subject=None,
|
||||
version=1):
|
||||
version=1,
|
||||
archived=False):
|
||||
template = {
|
||||
'id': id_,
|
||||
'name': name,
|
||||
'template_type': type_,
|
||||
'content': content,
|
||||
'service': service_id,
|
||||
'version': version
|
||||
'version': version,
|
||||
'updated_at': datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'archived': archived
|
||||
}
|
||||
if subject is not None:
|
||||
template['subject'] = subject
|
||||
|
||||
@@ -9,15 +9,17 @@ from tests import validate_route_permission
|
||||
from app.main.views.templates import get_last_use_message, get_human_readable_delta
|
||||
|
||||
|
||||
def test_should_show_page_for_one_templates(app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_service_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid):
|
||||
def test_should_show_page_for_one_template(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_service_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid
|
||||
):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
@@ -291,6 +293,39 @@ def test_should_redirect_when_deleting_a_template(app_,
|
||||
service_id, template_id)
|
||||
|
||||
|
||||
@freeze_time('2016-01-01T15:00')
|
||||
def test_should_show_page_for_a_deleted_template(
|
||||
app_,
|
||||
api_user_active,
|
||||
mock_login,
|
||||
mock_get_service,
|
||||
mock_get_deleted_template,
|
||||
mock_get_user,
|
||||
mock_get_user_by_email,
|
||||
mock_has_permissions,
|
||||
fake_uuid
|
||||
):
|
||||
with app_.test_request_context(), app_.test_client() as client:
|
||||
client.login(api_user_active)
|
||||
service_id = fake_uuid
|
||||
template_id = fake_uuid
|
||||
response = client.get(url_for(
|
||||
'.view_template',
|
||||
service_id=service_id,
|
||||
template_id=template_id
|
||||
))
|
||||
|
||||
assert response.status_code == 200
|
||||
|
||||
content = response.get_data(as_text=True)
|
||||
assert url_for("main.edit_service_template", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert url_for("main.send_from_api", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert url_for("main.send_test", service_id=fake_uuid, template_id=fake_uuid) not in content
|
||||
assert "This template was deleted<br/>1 January 2016" in content
|
||||
|
||||
mock_get_deleted_template.assert_called_with(service_id, template_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('route', [
|
||||
'main.add_service_template',
|
||||
'main.edit_service_template',
|
||||
|
||||
@@ -245,6 +245,27 @@ def mock_get_service_template(mocker):
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_deleted_template(mocker):
|
||||
def _get(service_id, template_id, version=None):
|
||||
template = template_json(
|
||||
service_id,
|
||||
template_id,
|
||||
"Two week reminder",
|
||||
"sms",
|
||||
"Your vehicle tax is about to expire",
|
||||
archived=True
|
||||
)
|
||||
if version:
|
||||
template.update({'version': version})
|
||||
return {'data': template}
|
||||
|
||||
return mocker.patch(
|
||||
'app.service_api_client.get_service_template',
|
||||
side_effect=_get
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture(scope='function')
|
||||
def mock_get_template_version(mocker, fake_uuid, user=None):
|
||||
if user is None:
|
||||
|
||||
Reference in New Issue
Block a user