mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 01:55:41 -04:00
Add link to delete a template
This is a link not a button because: - it’s less prominent—delete is an infrequent action - it’s a two-step process, and only the second part changes any data (so it has a button)
This commit is contained in:
@@ -27,3 +27,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.banner-dangerous {
|
||||||
|
|
||||||
|
@extend .banner;
|
||||||
|
background: $white;
|
||||||
|
color: $error-colour;
|
||||||
|
border: 5px solid $error-colour;
|
||||||
|
margin: 15px 0;
|
||||||
|
@include bold-19;
|
||||||
|
text-align: left;
|
||||||
|
|
||||||
|
.button {
|
||||||
|
@include button($error-colour);
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,26 @@
|
|||||||
margin-top: $gutter;
|
margin-top: $gutter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&-delete-link {
|
||||||
|
|
||||||
|
line-height: 40px;
|
||||||
|
padding: 0 0 0 5px;
|
||||||
|
|
||||||
|
a:visited,
|
||||||
|
a:link {
|
||||||
|
color: $error-colour;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
a:hover,
|
||||||
|
a:active {
|
||||||
|
color: $mellow-red;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
.button {}
|
.button {}
|
||||||
|
|
||||||
.button-destructive {
|
.button-destructive {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from flask import request, render_template, redirect, url_for
|
from flask import request, render_template, redirect, url_for, flash
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
@@ -48,7 +48,35 @@ def edit_template(service_id, template_id):
|
|||||||
'views/edit-template.html',
|
'views/edit-template.html',
|
||||||
h1='Edit template',
|
h1='Edit template',
|
||||||
form=form,
|
form=form,
|
||||||
service_id=service_id
|
service_id=service_id,
|
||||||
|
template_id=template_id
|
||||||
)
|
)
|
||||||
elif request.method == 'POST':
|
elif request.method == 'POST':
|
||||||
return redirect(url_for('.manage_templates', service_id=service_id))
|
return redirect(url_for('.manage_templates', service_id=service_id))
|
||||||
|
|
||||||
|
|
||||||
|
@main.route("/services/<int:service_id>/templates/<int:template_id>/delete", methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def delete_template(service_id, template_id):
|
||||||
|
|
||||||
|
form = TemplateForm()
|
||||||
|
|
||||||
|
form.template_name.data = templates[template_id - 1]['name']
|
||||||
|
form.template_body.data = templates[template_id - 1]['body']
|
||||||
|
|
||||||
|
if request.method == 'GET':
|
||||||
|
|
||||||
|
flash('Are you sure you want to delete ‘{}’?'.format(form.template_name.data), 'delete')
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'views/edit-template.html',
|
||||||
|
h1='Edit template',
|
||||||
|
form=form,
|
||||||
|
service_id=service_id,
|
||||||
|
template_id=template_id
|
||||||
|
)
|
||||||
|
elif request.method == 'POST':
|
||||||
|
if request.form.get('delete'):
|
||||||
|
return redirect(url_for('.manage_templates', service_id=service_id))
|
||||||
|
else:
|
||||||
|
return redirect(url_for('.manage_templates', service_id=service_id))
|
||||||
|
|||||||
@@ -68,16 +68,22 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<main id="content" role="main" class="page-container">
|
<main id="content" role="main" class="page-container">
|
||||||
{% with messages = get_flashed_messages() %}
|
{% with messages = get_flashed_messages(with_categories=true) %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<div class="error-summary">
|
<ul class="banner-dangerous">
|
||||||
<ul>
|
{% for category, message in messages %}
|
||||||
{% for message in messages %}
|
<li class="flash-message">
|
||||||
<li>{{ message }}</li>
|
{{ message }}
|
||||||
{% endfor %}
|
{% if 'delete' == category %}
|
||||||
|
<form method='post'>
|
||||||
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
|
<input type="submit" class="button" name="delete" value="Yes, delete this template" />
|
||||||
|
</form>
|
||||||
|
{% endif %}
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
{% block fullwidth_content %}{% endblock %}
|
{% block fullwidth_content %}{% endblock %}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -1,11 +1,23 @@
|
|||||||
{% macro page_footer(button_text=None, back_link=False, back_link_text="Back", destructive=False) %}
|
{% macro page_footer(
|
||||||
|
button_text=None,
|
||||||
|
destructive=False,
|
||||||
|
back_link=False,
|
||||||
|
back_link_text="Back",
|
||||||
|
delete_link=False,
|
||||||
|
delete_link_text="delete"
|
||||||
|
) %}
|
||||||
<div class="page-footer">
|
<div class="page-footer">
|
||||||
{% if button_text %}
|
{% if button_text %}
|
||||||
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
|
||||||
<input type="submit" class="button{% if destructive %}-destructive{% endif %}" value="{{ button_text }}" />
|
<input type="submit" class="button{% if destructive %}-destructive{% endif %}" value="{{ button_text }}" />
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if delete_link %}
|
||||||
|
<span class="page-footer-delete-link">
|
||||||
|
or <a href="{{ delete_link }}">{{ delete_link_text }}</a>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
{% if back_link %}
|
{% if back_link %}
|
||||||
<a class="page-footer-back-link" role="button" href="{{ back_link }}">{{ back_link_text }}</a>
|
<a class="page-footer-back-link" href="{{ back_link }}">{{ back_link_text }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ GOV.UK Notify | Edit template
|
|||||||
{{ textbox(form.template_name) }}
|
{{ textbox(form.template_name) }}
|
||||||
{{ textbox(form.template_body, highlight_tags=True) }}
|
{{ textbox(form.template_body, highlight_tags=True) }}
|
||||||
{{ page_footer(
|
{{ page_footer(
|
||||||
'Save and continue',
|
'Save',
|
||||||
|
delete_link=url_for('.delete_template', service_id=service_id, template_id=template_id) if template_id or None,
|
||||||
back_link=url_for('.manage_templates', service_id=service_id),
|
back_link=url_for('.manage_templates', service_id=service_id),
|
||||||
back_link_text='Back to templates'
|
back_link_text='Back to templates'
|
||||||
) }}
|
) }}
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ GOV.UK Notify | Manage templates
|
|||||||
|
|
||||||
<h1 class="heading-xlarge">Templates</h1>
|
<h1 class="heading-xlarge">Templates</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a href="{{ url_for('.add_template', service_id=service_id) }}">Create new template</a>
|
||||||
|
|
||||||
{% for template in templates %}
|
{% for template in templates %}
|
||||||
{% if template.type == 'sms' %}
|
{% if template.type == 'sms' %}
|
||||||
{{ sms_message(
|
{{ sms_message(
|
||||||
@@ -32,18 +35,6 @@ GOV.UK Notify | Manage templates
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="column-one-third">
|
|
||||||
{{ browse_list([
|
|
||||||
{
|
|
||||||
'title': 'New text message template',
|
|
||||||
'link': url_for('.add_template', service_id=service_id)
|
|
||||||
},
|
|
||||||
{
|
|
||||||
'title': 'New email template',
|
|
||||||
'link': url_for('.add_template', service_id=service_id)
|
|
||||||
}
|
|
||||||
]) }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ def test_should_return_list_of_all_templates(notifications_admin, notifications_
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
def test_should_show_page_for_one_templates(notifications_admin, notifications_admin_db, notify_db_session):
|
def test_should_show_page_for_one_template(notifications_admin, notifications_admin_db, notify_db_session):
|
||||||
with notifications_admin.test_request_context():
|
with notifications_admin.test_request_context():
|
||||||
with notifications_admin.test_client() as client:
|
with notifications_admin.test_client() as client:
|
||||||
user = create_test_user('active')
|
user = create_test_user('active')
|
||||||
client.login(user)
|
client.login(user)
|
||||||
response = client.get('/services/123/templates/template')
|
response = client.get('/services/123/templates/1')
|
||||||
|
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
|
|
||||||
@@ -26,7 +26,29 @@ def test_should_redirect_when_saving_a_template(notifications_admin, notificatio
|
|||||||
with notifications_admin.test_client() as client:
|
with notifications_admin.test_client() as client:
|
||||||
user = create_test_user('active')
|
user = create_test_user('active')
|
||||||
client.login(user)
|
client.login(user)
|
||||||
response = client.post('/services/123/templates/template')
|
response = client.post('/services/123/templates/1')
|
||||||
|
|
||||||
|
assert response.status_code == 302
|
||||||
|
assert response.location == 'http://localhost/services/123/templates'
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_show_delete_template_page(notifications_admin, notifications_admin_db, notify_db_session):
|
||||||
|
with notifications_admin.test_request_context():
|
||||||
|
with notifications_admin.test_client() as client:
|
||||||
|
user = create_test_user('active')
|
||||||
|
client.login(user)
|
||||||
|
response = client.get('/services/123/templates/1/delete')
|
||||||
|
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert 'Are you sure' in response.get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
|
def test_should_redirect_when_deleting_a_template(notifications_admin, notifications_admin_db, notify_db_session):
|
||||||
|
with notifications_admin.test_request_context():
|
||||||
|
with notifications_admin.test_client() as client:
|
||||||
|
user = create_test_user('active')
|
||||||
|
client.login(user)
|
||||||
|
response = client.post('/services/123/templates/1/delete')
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == 'http://localhost/services/123/templates'
|
assert response.location == 'http://localhost/services/123/templates'
|
||||||
|
|||||||
Reference in New Issue
Block a user