mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 09:18:24 -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 %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div class="column-one-third">
|
<div class="column-one-third">
|
||||||
<div class="message-use-links{% if show_title %}-with-title{% endif %}">
|
{% if template._template.archived %}
|
||||||
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
|
<div class="message-updated-at">
|
||||||
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}" class="primary">
|
This template was deleted<br/>{{ template._template.updated_at|format_date_normal }}
|
||||||
Send {{ 'text messages' if 'sms' == template.template_type else 'emails' }}
|
</div>
|
||||||
</a>
|
{% else %}
|
||||||
{% endif %}
|
<div class="message-use-links{% if show_title %}-with-title{% endif %}">
|
||||||
{% if current_user.has_permissions(permissions=['manage_templates'], admin_override=True) %}
|
{% if current_user.has_permissions(permissions=['send_texts', 'send_emails', 'send_letters']) %}
|
||||||
<a href="{{ url_for(".edit_service_template", service_id=current_service.id, template_id=template.id) }}">Edit template</a>
|
<a href="{{ url_for(".send_messages", service_id=current_service.id, template_id=template.id) }}" class="primary">
|
||||||
{% endif %}
|
Send {{ 'text messages' if 'sms' == template.template_type else 'emails' }}
|
||||||
<a href="{{ url_for(".send_from_api", service_id=current_service.id, template_id=template.id) }}">API info</a>
|
</a>
|
||||||
</div>
|
{% 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>
|
</div>
|
||||||
|
|||||||
@@ -68,14 +68,17 @@ def template_json(service_id,
|
|||||||
type_="sms",
|
type_="sms",
|
||||||
content="template content",
|
content="template content",
|
||||||
subject=None,
|
subject=None,
|
||||||
version=1):
|
version=1,
|
||||||
|
archived=False):
|
||||||
template = {
|
template = {
|
||||||
'id': id_,
|
'id': id_,
|
||||||
'name': name,
|
'name': name,
|
||||||
'template_type': type_,
|
'template_type': type_,
|
||||||
'content': content,
|
'content': content,
|
||||||
'service': service_id,
|
'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:
|
if subject is not None:
|
||||||
template['subject'] = subject
|
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
|
from app.main.views.templates import get_last_use_message, get_human_readable_delta
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_page_for_one_templates(app_,
|
def test_should_show_page_for_one_template(
|
||||||
api_user_active,
|
app_,
|
||||||
mock_login,
|
api_user_active,
|
||||||
mock_get_service,
|
mock_login,
|
||||||
mock_get_service_template,
|
mock_get_service,
|
||||||
mock_get_user,
|
mock_get_service_template,
|
||||||
mock_get_user_by_email,
|
mock_get_user,
|
||||||
mock_has_permissions,
|
mock_get_user_by_email,
|
||||||
fake_uuid):
|
mock_has_permissions,
|
||||||
|
fake_uuid
|
||||||
|
):
|
||||||
with app_.test_request_context():
|
with app_.test_request_context():
|
||||||
with app_.test_client() as client:
|
with app_.test_client() as client:
|
||||||
client.login(api_user_active)
|
client.login(api_user_active)
|
||||||
@@ -291,6 +293,39 @@ def test_should_redirect_when_deleting_a_template(app_,
|
|||||||
service_id, template_id)
|
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', [
|
@pytest.mark.parametrize('route', [
|
||||||
'main.add_service_template',
|
'main.add_service_template',
|
||||||
'main.edit_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')
|
@pytest.fixture(scope='function')
|
||||||
def mock_get_template_version(mocker, fake_uuid, user=None):
|
def mock_get_template_version(mocker, fake_uuid, user=None):
|
||||||
if user is None:
|
if user is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user