Merge branch 'master' into template_history_view

Conflicts:
	requirements.txt
This commit is contained in:
Rebecca Law
2016-05-13 17:30:33 +01:00
10 changed files with 133 additions and 104 deletions

View File

@@ -11,12 +11,15 @@ from flask import (
render_template, render_template,
make_response, make_response,
current_app, current_app,
request) request,
g)
from flask._compat import string_types from flask._compat import string_types
from flask.globals import _lookup_req_object from flask.globals import _lookup_req_object
from flask_login import LoginManager from flask_login import LoginManager
from flask_wtf import CsrfProtect from flask_wtf import CsrfProtect
from functools import partial from functools import partial
from monotonic import monotonic
from notifications_python_client.errors import HTTPError from notifications_python_client.errors import HTTPError
from notifications_utils import logging from notifications_utils import logging
from notifications_utils.recipients import validate_phone_number, InvalidPhoneError from notifications_utils.recipients import validate_phone_number, InvalidPhoneError
@@ -141,6 +144,11 @@ def init_csrf(application):
def init_app(application): def init_app(application):
@application.before_request
def record_start_time():
g.start = monotonic()
@application.context_processor @application.context_processor
def inject_global_template_variables(): def inject_global_template_variables():
return { return {

View File

@@ -57,9 +57,19 @@
margin: 0 0 20px 0; margin: 0 0 20px 0;
} }
pre,
code {
font-size: 16px;
}
code {
background: $highlight-colour;
padding: 2px 5px;
}
.highlight { .highlight {
margin: 0 0 20px 0; margin: 0 0 20px 0;
background: #F8F8F8; background: $highlight-colour;
} }
strong, strong,

View File

@@ -57,7 +57,7 @@ def view_jobs(service_id):
@user_has_permissions('view_activity', admin_override=True) @user_has_permissions('view_activity', admin_override=True)
def view_job(service_id, job_id): def view_job(service_id, job_id):
job = job_api_client.get_job(service_id, job_id)['data'] job = job_api_client.get_job(service_id, job_id)['data']
template = service_api_client.get_service_template(service_id, job['template'])['data'] template = service_api_client.get_service_template(service_id, job['template'], job['template_version'])['data']
notifications = notification_api_client.get_notifications_for_service(service_id, job_id) notifications = notification_api_client.get_notifications_for_service(service_id, job_id)
finished = job['status'] == 'finished' finished = job['status'] == 'finished'
return render_template( return render_template(

View File

@@ -175,7 +175,7 @@ def send_test(service_id, template_id):
get_example_csv_rows(template, use_example_as_example=False, submitted_fields=request.form) get_example_csv_rows(template, use_example_as_example=False, submitted_fields=request.form)
]) ])
filedata = { filedata = {
'file_name': 'Test run', 'file_name': 'Test message',
'data': output.getvalue() 'data': output.getvalue()
} }
upload_id = str(uuid.uuid4()) upload_id = str(uuid.uuid4())

View File

@@ -141,7 +141,7 @@ class ServiceAPIClient(NotificationsAPIClient):
""" """
Retrieve a list of versions for a template Retrieve a list of versions for a template
""" """
endpoint = '/service/{service_id}/template/{template_id}/version'.format( endpoint = '/service/{service_id}/template/{template_id}/versions'.format(
service_id=service_id, service_id=service_id,
template_id=template_id template_id=template_id
) )

View File

@@ -81,7 +81,7 @@
{{ item.to }} {{ item.to }}
</p> </p>
<p class="hint"> <p class="hint">
<a href="{{ url_for('.view_template', service_id=current_service.id, template_id=item.template.id) }}">{{ item.template.name }}</a> <a href="{{ url_for('.view_template_version', service_id=current_service.id, template_id=item.template.id, version=item.template_version) }}">{{ item.template.name }}</a>
sent from sent from
{% if item.job %} {% if item.job %}
<a href="{{ url_for(".view_job", service_id=current_service.id, job_id=item.job.id) }}">{{ item.job.original_file_name }}</a> <a href="{{ url_for(".view_job", service_id=current_service.id, job_id=item.job.id) }}">{{ item.job.original_file_name }}</a>

View File

@@ -31,6 +31,10 @@
<div class="column-one-third"> <div class="column-one-third">
<div class="sms-message-use-links{% if show_title %}-with-title{% endif %}"> <div class="sms-message-use-links{% if show_title %}-with-title{% endif %}">
<p>Edited by {{ template.get_raw('created_by').name }}</p> <p>Edited by {{ template.get_raw('created_by').name }}</p>
<p>Edited on {{ template.get_raw('created_at')|format_datetime }}</p> <p>Created on {{ template.get_raw('created_at')|format_datetime }}</p>
<p>Edited on
{% if template.get_raw('updated_at') %}
{{ template.get_raw('updated_at')|format_datetime }}</p>
{% endif %}
</div> </div>
</div> </div>

View File

@@ -58,8 +58,8 @@ There are 2 ways to integrate the API into your service:
* use one of the client libraries provided by GOV.UK Notify (see the Usage section in the Readme files): * use one of the client libraries provided by GOV.UK Notify (see the Usage section in the Readme files):
* [Python library](https://github.com/alphagov/notifications-python-client) * [Python library](https://github.com/alphagov/notifications-python-client)
* [PHP library] (https://github.com/alphagov/notifications-php-client) * [PHP library](https://github.com/alphagov/notifications-php-client)
* [Java library] (https://github.com/alphagov/notifications-java-client) * [Java library](https://github.com/alphagov/notifications-java-client)
* develop your own integration to produce requests in the correct format * develop your own integration to produce requests in the correct format
<h3 id="AuthRequests">Authenticate requests</h3> <h3 id="AuthRequests">Authenticate requests</h3>
@@ -169,11 +169,11 @@ where:
The response (status code 201) will be: The response (status code 201) will be:
``` ```
{ {
'data':{ 'data':{
'notification': { 'notification': {
'id':1 'id':1
} }
} }
} }
``` ```
@@ -190,25 +190,28 @@ The response (status code 200) will be:
``` ```
{ {
'notification': 'notification': {
{ 'status': 'delivered',
'status': 'delivered', 'to': '07515 987 456',
'to': '07515 987 456', 'template': {
'template': {'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb', 'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb',
'name': 'First template', 'name': 'First template',
'template_type': 'sms'}, 'template_type': 'sms'
'created_at': '2016-04-26T15:29:36.891512+00:00', },
'updated_at': '2016-04-26T15:29:38.724808+00:00', 'created_at': '2016-04-26T15:29:36.891512+00:00',
'sent_at': '2016-04-26T15:29:37.230976+00:00', 'updated_at': '2016-04-26T15:29:38.724808+00:00',
'job': {'id': 'f9043884-acac-46db-b2ea-f08cd8ec6d67', 'sent_at': '2016-04-26T15:29:37.230976+00:00',
'original_file_name': 'Test run'}, 'job': {
'sent_at': '2016-04-26T15:29:37.230976+00:00', 'id': 'f9043884-acac-46db-b2ea-f08cd8ec6d67',
'id': 'f163deaf-2d3f-4ec6-98fc-f23fa511518f', 'original_file_name': 'Test run'
'content_char_count': 490, },
'service': '5cf87313-fddd-4482-a2ea-48e37320efd1', 'sent_at': '2016-04-26T15:29:37.230976+00:00',
'reference': None, 'id': 'f163deaf-2d3f-4ec6-98fc-f23fa511518f',
'sent_by': 'mmg' 'content_char_count': 490,
} 'service': '5cf87313-fddd-4482-a2ea-48e37320efd1',
'reference': None,
'sent_by': 'mmg'
}
} }
``` ```
See [below](#fieldsforGET) for explanations of the fields. See [below](#fieldsforGET) for explanations of the fields.
@@ -223,48 +226,57 @@ The response (status code 200) will be:
``` ```
{'notifications': {'notifications':
[{ [{
'status': 'delivered', 'status': 'delivered',
'to': '07515 987 456', 'to': '07515 987 456',
'template': {'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb', 'template': {
'name': 'First template', 'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb',
'template_type': 'sms'}, 'name': 'First template',
'template_type': 'sms'
'job': {'id': '5cc9d7ae-ceb7-4565-8345-4931d71f8c2e', },
'original_file_name': 'Test run'}, 'job': {
'created_at': '2016-04-26T15:30:49.968969+00:00', 'id': '5cc9d7ae-ceb7-4565-8345-4931d71f8c2e',
'updated_at': '2016-04-26T15:30:50.853844+00:00', 'original_file_name': 'Test run'
'sent_at': '2016-04-26T15:30:50.383634+00:00', },
'id': '04ae9bdc-92aa-4d6c-a0da-48587c03d4c7', 'created_at': '2016-04-26T15:30:49.968969+00:00',
'content_char_count': 446, 'updated_at': '2016-04-26T15:30:50.853844+00:00',
'service': '5cf87313-fddd-4482-a2ea-48e37320efd1', 'sent_at': '2016-04-26T15:30:50.383634+00:00',
'reference': None, 'id': '04ae9bdc-92aa-4d6c-a0da-48587c03d4c7',
'sent_by': 'mmg' 'content_char_count': 446,
}, 'service': '5cf87313-fddd-4482-a2ea-48e37320efd1',
{ 'reference': None,
'status': 'delivered', 'sent_by': 'mmg'
'to': '07515 987 456', },
'template': {'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb', {
'name': 'First template', 'status': 'delivered',
'template_type': 'sms'}, 'to': '07515 987 456',
'job': {'id': 'f9043884-acac-46db-b2ea-f08cd8ec6d67', 'template': {
'original_file_name': 'Test run'}, 'id': '5e427b42-4e98-46f3-a047-32c4a87d26bb',
'created_at': '2016-04-26T15:29:36.891512+00:00', 'name': 'First template',
'updated_at': '2016-04-26T15:29:38.724808+00:00', 'template_type': 'sms'
'sent_at': '2016-04-26T15:29:37.230976+00:00', },
'id': 'f163deaf-2d3f-4ec6-98fc-f23fa511518f', 'job': {
'content_char_count': 490, 'id': 'f9043884-acac-46db-b2ea-f08cd8ec6d67',
'service': '5cf87313-fddd-4482-a2ea-48e37320efd1', 'original_file_name': 'Test run'
'reference': None, },
'sent_by': 'mmg' 'created_at': '2016-04-26T15:29:36.891512+00:00',
}, 'updated_at': '2016-04-26T15:29:38.724808+00:00',
... 'sent_at': '2016-04-26T15:29:37.230976+00:00',
] 'id': 'f163deaf-2d3f-4ec6-98fc-f23fa511518f',
'links': {'last': '/notifications?page=3&template_type=sms&status=delivered', 'content_char_count': 490,
'next': '/notifications?page=2&template_type=sms&status=delivered'}, 'service': '5cf87313-fddd-4482-a2ea-48e37320efd1',
'total': 162, 'reference': None,
'page_size': 50 'sent_by': 'mmg'
} },
],
'links': {
'last': '/notifications?page=3&template_type=sms&status=delivered',
'next': '/notifications?page=2&template_type=sms&status=delivered'
},
'total': 162,
'page_size': 50
}
``` ```
<a name="fieldsforGET"></a> <a name="fieldsforGET"></a>
where: where:
@@ -327,9 +339,3 @@ Error code | Body | Meaning
The GOV.UK Notify API code is open sourced at: The GOV.UK Notify API code is open sourced at:
[GOV.UK Notify API](https://github.com/alphagov/notifications-api) [GOV.UK Notify API](https://github.com/alphagov/notifications-api)

View File

@@ -7,7 +7,8 @@ boto3==1.3.0
Pygments==2.0.2 Pygments==2.0.2
py-gfm==0.1.2 py-gfm==0.1.2
blinker==1.4 blinker==1.4
monotonic==0.3
git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0 git+https://github.com/alphagov/notifications-python-client.git@1.0.0#egg=notifications-python-client==1.0.0
git+https://github.com/alphagov/notifications-utils.git@5.2.1#egg=notifications-utils==5.2.1 git+https://github.com/alphagov/notifications-utils.git@5.2.3#egg=notifications-utils==5.2.3

View File

@@ -91,7 +91,7 @@ def test_send_test_sms_message(
fake_uuid fake_uuid
): ):
expected_data = {'data': 'phone number\r\n07700 900 762\r\n', 'file_name': 'Test run'} expected_data = {'data': 'phone number\r\n07700 900 762\r\n', 'file_name': 'Test message'}
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234') mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')
with app_.test_request_context(): with app_.test_request_context():
@@ -119,7 +119,7 @@ def test_send_test_email_message(
fake_uuid fake_uuid
): ):
expected_data = {'data': 'email address\r\ntest@user.gov.uk\r\n', 'file_name': 'Test run'} expected_data = {'data': 'email address\r\ntest@user.gov.uk\r\n', 'file_name': 'Test message'}
mocker.patch('app.main.views.send.s3download', return_value='email address\r\ntest@user.gov.uk') mocker.patch('app.main.views.send.s3download', return_value='email address\r\ntest@user.gov.uk')
with app_.test_request_context(): with app_.test_request_context():
@@ -149,7 +149,7 @@ def test_send_test_sms_message_with_placeholders(
expected_data = { expected_data = {
'data': 'phone number,name\r\n07700 900 762,Jo\r\n', 'data': 'phone number,name\r\n07700 900 762,Jo\r\n',
'file_name': 'Test run' 'file_name': 'Test message'
} }
mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234') mocker.patch('app.main.views.send.s3download', return_value='phone number\r\n+4412341234')