mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 07:46:23 -04:00
Roll up messages in inbox
The inbox should work a bit like the one on your phone. You shouldn’t see all the messages, but the latest one from each of your ‘contacts’ only.
This commit is contained in:
@@ -29,7 +29,11 @@ from functools import partial
|
|||||||
from notifications_python_client.errors import HTTPError
|
from notifications_python_client.errors import HTTPError
|
||||||
from notifications_utils import logging, request_id, formatters
|
from notifications_utils import logging, request_id, formatters
|
||||||
from notifications_utils.clients.statsd.statsd_client import StatsdClient
|
from notifications_utils.clients.statsd.statsd_client import StatsdClient
|
||||||
from notifications_utils.recipients import validate_phone_number, InvalidPhoneError
|
from notifications_utils.recipients import (
|
||||||
|
validate_phone_number,
|
||||||
|
InvalidPhoneError,
|
||||||
|
format_phone_number_human_readable,
|
||||||
|
)
|
||||||
from notifications_utils.formatters import formatted_list
|
from notifications_utils.formatters import formatted_list
|
||||||
from pygments import highlight
|
from pygments import highlight
|
||||||
from pygments.formatters.html import HtmlFormatter
|
from pygments.formatters.html import HtmlFormatter
|
||||||
@@ -139,6 +143,7 @@ def create_app():
|
|||||||
application.add_template_filter(format_notification_status_as_url)
|
application.add_template_filter(format_notification_status_as_url)
|
||||||
application.add_template_filter(formatted_list)
|
application.add_template_filter(formatted_list)
|
||||||
application.add_template_filter(nl2br)
|
application.add_template_filter(nl2br)
|
||||||
|
application.add_template_filter(format_phone_number_human_readable)
|
||||||
|
|
||||||
application.after_request(useful_headers_after_request)
|
application.after_request(useful_headers_after_request)
|
||||||
application.after_request(save_service_after_request)
|
application.after_request(save_service_after_request)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ from flask import (
|
|||||||
)
|
)
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
|
from notifications_utils.recipients import format_phone_number_human_readable
|
||||||
|
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app import (
|
from app import (
|
||||||
current_service,
|
current_service,
|
||||||
@@ -144,9 +146,21 @@ def inbox(service_id):
|
|||||||
if 'inbound_sms' not in current_service['permissions']:
|
if 'inbound_sms' not in current_service['permissions']:
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
messages_to_show = list()
|
||||||
|
inbound_messages = service_api_client.get_inbound_sms(service_id)
|
||||||
|
|
||||||
|
for message in inbound_messages:
|
||||||
|
if format_phone_number_human_readable(message['user_number']) not in {
|
||||||
|
format_phone_number_human_readable(message['user_number'])
|
||||||
|
for message in messages_to_show
|
||||||
|
}:
|
||||||
|
messages_to_show.append(message)
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
'views/dashboard/inbox.html',
|
'views/dashboard/inbox.html',
|
||||||
messages=service_api_client.get_inbound_sms(service_id),
|
messages=messages_to_show,
|
||||||
|
count_of_messages=len(inbound_messages),
|
||||||
|
count_of_users=len(messages_to_show),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
{% extends "withnav_template.html" %}
|
{% extends "withnav_template.html" %}
|
||||||
|
|
||||||
{% block service_page_title %}
|
{% block service_page_title %}
|
||||||
Inbox
|
Received text messages
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block maincolumn_content %}
|
{% block maincolumn_content %}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
field_headings_visible=False
|
field_headings_visible=False
|
||||||
) %}
|
) %}
|
||||||
{% call field() %}
|
{% call field() %}
|
||||||
<span class="file-list-filename" href="#">{{ item.user_number }}</span>
|
<span class="file-list-filename" href="#">{{ item.user_number | format_phone_number_human_readable }}</span>
|
||||||
<span class="wide-left-hand-column">{{ item.content }}</span>
|
<span class="wide-left-hand-column">{{ item.content }}</span>
|
||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% call field(align='right') %}
|
{% call field(align='right') %}
|
||||||
@@ -36,7 +36,8 @@
|
|||||||
{% endcall %}
|
{% endcall %}
|
||||||
{% if messages %}
|
{% if messages %}
|
||||||
<p class="table-show-more-link">
|
<p class="table-show-more-link">
|
||||||
Showing all {{ messages | length }} messages
|
{{ count_of_messages }} message{{ '' if 1 == count_of_messages else 's' }}
|
||||||
|
from {{ count_of_users }} user{{ '' if 1 == count_of_users else 's' }}
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -28,4 +28,4 @@ notifications-python-client>=3.1,<3.2
|
|||||||
awscli>=1.11,<1.12
|
awscli>=1.11,<1.12
|
||||||
awscli-cwlogs>=1.4,<1.5
|
awscli-cwlogs>=1.4,<1.5
|
||||||
|
|
||||||
git+https://github.com/alphagov/notifications-utils.git@17.1.2#egg=notifications-utils==17.1.2
|
git+https://github.com/alphagov/notifications-utils.git@17.2.0#egg=notifications-utils==17.2.0
|
||||||
|
|||||||
@@ -131,11 +131,11 @@ def test_inbound_messages_shows_count_of_messages(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('index, expected_row', enumerate([
|
@pytest.mark.parametrize('index, expected_row', enumerate([
|
||||||
'07900900000 foo 1 hour ago',
|
'07900 900000 message-1 1 hour ago',
|
||||||
'07900900001 foo 2 hours ago',
|
'07900 900002 message-4 3 hours ago',
|
||||||
'07900900002 foo 3 hours ago',
|
'07900 900004 message-5 5 hours ago',
|
||||||
'07900900003 foo 4 hours ago',
|
'07900 900006 message-6 7 hours ago',
|
||||||
'07900900004 foo 5 hours ago',
|
'07900 900008 message-7 9 hours ago',
|
||||||
]))
|
]))
|
||||||
def test_inbox_showing_inbound_messages(
|
def test_inbox_showing_inbound_messages(
|
||||||
logged_in_client,
|
logged_in_client,
|
||||||
@@ -159,6 +159,9 @@ def test_inbox_showing_inbound_messages(
|
|||||||
rows = page.select('tbody tr')
|
rows = page.select('tbody tr')
|
||||||
assert len(rows) == 5
|
assert len(rows) == 5
|
||||||
assert normalize_spaces(rows[index].text) == expected_row
|
assert normalize_spaces(rows[index].text) == expected_row
|
||||||
|
assert normalize_spaces(page.select('.table-show-more-link')) == (
|
||||||
|
'8 messages from 5 users'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_empty_inbox(
|
def test_empty_inbox(
|
||||||
|
|||||||
@@ -1139,9 +1139,9 @@ def mock_get_inbound_sms(mocker):
|
|||||||
):
|
):
|
||||||
return [{
|
return [{
|
||||||
'user_number': '0790090000' + str(i),
|
'user_number': '0790090000' + str(i),
|
||||||
'content': 'foo',
|
'content': 'message-{}'.format(index + 1),
|
||||||
'created_at': (datetime.utcnow() - timedelta(minutes=60 * (i + 1))).isoformat()
|
'created_at': (datetime.utcnow() - timedelta(minutes=60 * (i + 1))).isoformat()
|
||||||
} for i in range(5)]
|
} for index, i in enumerate([0, 0, 0, 2, 4, 6, 8, 8])]
|
||||||
|
|
||||||
return mocker.patch(
|
return mocker.patch(
|
||||||
'app.service_api_client.get_inbound_sms',
|
'app.service_api_client.get_inbound_sms',
|
||||||
|
|||||||
Reference in New Issue
Block a user