Add query string parameter to search by recipient

> Service teams that use the admin interface often need to know the
> outcome of a message... at the moment they have to page through all
> the results in the activity stream. They should be able to find
> notifications by email address or phone number.

– https://www.pivotaltracker.com/n/projects/1443052

This commit adds an additional query string parameter (`to`) to the URL,
which users can use to filter down the list of notifications.

It:
- takes the status into account
- doesn’t update the counts based on the search term (in reality each
  service will only send a handful of notifications to one person in any
  7 day period)

In other words the funnel that filters down the notifications looks
like:

> all notifications for service → only failed → only to this phone
> number
This commit is contained in:
Chris Hill-Scott
2017-05-30 12:55:13 +01:00
parent d516f19a33
commit f41830e5d3
5 changed files with 30 additions and 7 deletions

View File

@@ -198,7 +198,8 @@ def view_notifications(service_id, message_type):
partials=get_notifications(service_id, message_type),
message_type=message_type,
status=request.args.get('status'),
page=request.args.get('page', 1)
page=request.args.get('page', 1),
to=request.args.get('to'),
)
@@ -241,7 +242,9 @@ def get_notifications(service_id, message_type, status_override=None):
page=page,
template_type=[message_type],
status=filter_args.get('status'),
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'])
limit_days=current_app.config['ACTIVITY_STATS_LIMIT_DAYS'],
to=request.args.get('to'),
)
url_args = {
'message_type': message_type,

View File

@@ -21,7 +21,8 @@ class NotificationApiClient(NotifyAdminAPIClient):
limit_days=None,
include_jobs=None,
include_from_test_key=None,
format_for_csv=None
format_for_csv=None,
to=None,
):
params = {}
if page is not None:
@@ -38,6 +39,8 @@ class NotificationApiClient(NotifyAdminAPIClient):
params['include_from_test_key'] = include_from_test_key
if format_for_csv is not None:
params['format_for_csv'] = format_for_csv
if to is not None:
params['to'] = to
if job_id:
return self.get(
url='/service/{}/job/{}/notifications'.format(service_id, job_id),

View File

@@ -20,7 +20,7 @@
{{ ajax_block(
partials,
url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page),
url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page, to=to),
'notifications'
) }}

View File

@@ -311,6 +311,13 @@ def test_should_show_updates_for_one_job_as_json(
(None, 1)
]
)
@pytest.mark.parametrize(
"to_argument, expected_to_argument", [
('', ''),
('+447900900123', '+447900900123'),
('test@example.com', 'test@example.com'),
]
)
def test_can_show_notifications(
logged_in_client,
service_one,
@@ -322,13 +329,17 @@ def test_can_show_notifications(
expected_api_call,
page_argument,
expected_page_argument,
to_argument,
expected_to_argument,
):
response = logged_in_client.get(url_for(
'main.view_notifications',
service_id=service_one['id'],
message_type=message_type,
status=status_argument,
page=page_argument))
page=page_argument,
to=to_argument,
))
assert response.status_code == 200
content = response.get_data(as_text=True)
notifications = notification_json(service_one['id'])
@@ -348,13 +359,16 @@ def test_can_show_notifications(
assert query_dict['status'] == [status_argument]
if expected_page_argument:
assert query_dict['page'] == [str(expected_page_argument)]
if to_argument:
assert query_dict['to'] == [to_argument]
mock_get_notifications.assert_called_with(
limit_days=7,
page=expected_page_argument,
service_id=service_one['id'],
status=expected_api_call,
template_type=[message_type]
template_type=[message_type],
to=expected_to_argument,
)
json_response = logged_in_client.get(url_for(

View File

@@ -1069,6 +1069,7 @@ def mock_get_notifications(mocker, api_user_active):
rows=5,
include_jobs=None,
include_from_test_key=None,
to=None,
):
job = None
if job_id is not None:
@@ -1101,7 +1102,9 @@ def mock_get_notifications_with_previous_next(mocker):
status=None,
limit_days=None,
include_jobs=None,
include_from_test_key=None):
include_from_test_key=None,
to=None,
):
return notification_json(service_id, with_links=True)
return mocker.patch(