remove view_notifications unsed code

This commit is contained in:
Beverly Nguyen
2025-10-08 16:37:42 -07:00
parent 78878da532
commit a013f30600
6 changed files with 265 additions and 355 deletions

View File

@@ -1564,20 +1564,20 @@ class SearchUsersForm(StripWhitespaceForm):
search = UsaSearchField("Search by name or email address") search = UsaSearchField("Search by name or email address")
class SearchNotificationsForm(StripWhitespaceForm): # class SearchNotificationsForm(StripWhitespaceForm):
to = UsaSearchField() # to = UsaSearchField()
#
labels = { # labels = {
"email": "Search by email address", # "email": "Search by email address",
"sms": "Search by phone number", # "sms": "Search by phone number",
} # }
#
def __init__(self, message_type, *args, **kwargs): # def __init__(self, message_type, *args, **kwargs):
super().__init__(*args, **kwargs) # super().__init__(*args, **kwargs)
self.to.label.text = self.labels.get( # self.to.label.text = self.labels.get(
message_type, # message_type,
"Search by phone number or email address", # "Search by phone number or email address",
) # )
class SearchTemplatesForm(StripWhitespaceForm): class SearchTemplatesForm(StripWhitespaceForm):

View File

@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from functools import partial # from functools import partial
from flask import ( from flask import (
Response, Response,
@@ -12,27 +12,30 @@ from flask import (
stream_with_context, stream_with_context,
url_for, url_for,
) )
from flask_login import current_user
# from flask_login import current_user
from markupsafe import Markup from markupsafe import Markup
from app import ( from app import ( # notification_api_client,; service_api_client,
current_service, current_service,
format_datetime_table, format_datetime_table,
notification_api_client,
service_api_client,
) )
from app.enums import NotificationStatus, NotificationType, ServicePermission
# from app.enums import NotificationStatus, NotificationType, ServicePermission
from app.enums import ServicePermission
from app.formatters import get_time_left, message_count_noun from app.formatters import get_time_left, message_count_noun
from app.main import main from app.main import main
from app.main.forms import SearchNotificationsForm
# from app.main.forms import SearchNotificationsForm
from app.models.job import Job from app.models.job import Job
from app.utils import parse_filter_args, set_status_filters from app.utils import parse_filter_args, set_status_filters
from app.utils.csv import generate_notifications_csv from app.utils.csv import generate_notifications_csv
from app.utils.pagination import (
generate_next_dict, # from app.utils.pagination import (
generate_previous_dict, # generate_next_dict,
get_page_from_request, # generate_previous_dict,
) # get_page_from_request,
# )
from app.utils.user import user_has_permissions from app.utils.user import user_has_permissions
from notifications_python_client.errors import HTTPError from notifications_python_client.errors import HTTPError
from notifications_utils.template import EmailPreviewTemplate, SMSBodyPreviewTemplate from notifications_utils.template import EmailPreviewTemplate, SMSBodyPreviewTemplate
@@ -197,242 +200,242 @@ def view_job_notifications_table(service_id, job_id):
) )
@main.route("/services/<uuid:service_id>/notifications", methods=["GET", "POST"]) # @main.route("/services/<uuid:service_id>/notifications", methods=["GET", "POST"])
@main.route( # @main.route(
"/services/<uuid:service_id>/notifications/<template_type:message_type>", # "/services/<uuid:service_id>/notifications/<template_type:message_type>",
methods=["GET", "POST"], # methods=["GET", "POST"],
) # )
@user_has_permissions() # @user_has_permissions()
def view_notifications(service_id, message_type=None): # def view_notifications(service_id, message_type=None):
return render_template( # return render_template(
"views/notifications.html", # "views/notifications.html",
partials=get_notifications(service_id, message_type), # partials=get_notifications(service_id, message_type),
message_type=message_type, # message_type=message_type,
status=request.args.get("status") or "sending,delivered,failed", # status=request.args.get("status") or "sending,delivered,failed",
page=request.args.get("page", 1), # page=request.args.get("page", 1),
search_form=SearchNotificationsForm( # search_form=SearchNotificationsForm(
message_type=message_type, # message_type=message_type,
to=request.form.get("to"), # to=request.form.get("to"),
), # ),
things_you_can_search_by={ # things_you_can_search_by={
"email": ["email address"], # "email": ["email address"],
"sms": ["phone number"], # "sms": ["phone number"],
None: ["recipient"], # None: ["recipient"],
}.get(message_type) # }.get(message_type)
+ { # + {
True: ["reference"], # True: ["reference"],
False: [], # False: [],
}.get(bool(current_service.api_keys)), # }.get(bool(current_service.api_keys)),
download_link_one_day=url_for( # download_link_one_day=url_for(
".download_notifications_csv", # ".download_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
number_of_days="one_day", # number_of_days="one_day",
), # ),
download_link_today=url_for( # download_link_today=url_for(
".download_notifications_csv", # ".download_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
number_of_days="today", # number_of_days="today",
), # ),
download_link_three_day=url_for( # download_link_three_day=url_for(
".download_notifications_csv", # ".download_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
number_of_days="three_day", # number_of_days="three_day",
), # ),
download_link_five_day=url_for( # download_link_five_day=url_for(
".download_notifications_csv", # ".download_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
number_of_days="five_day", # number_of_days="five_day",
), # ),
download_link_seven_day=url_for( # download_link_seven_day=url_for(
".download_notifications_csv", # ".download_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
number_of_days="seven_day", # number_of_days="seven_day",
), # ),
) # )
@main.route("/services/<uuid:service_id>/notifications.json", methods=["GET", "POST"]) # @main.route("/services/<uuid:service_id>/notifications.json", methods=["GET", "POST"])
@main.route( # @main.route(
"/services/<uuid:service_id>/notifications/<template_type:message_type>.json", # "/services/<uuid:service_id>/notifications/<template_type:message_type>.json",
methods=["GET", "POST"], # methods=["GET", "POST"],
) # )
@user_has_permissions() # @user_has_permissions()
def get_notifications_as_json(service_id, message_type=None): # def get_notifications_as_json(service_id, message_type=None):
return jsonify( # return jsonify(
get_notifications( # get_notifications(
service_id, message_type, status_override=request.args.get("status") # service_id, message_type, status_override=request.args.get("status")
) # )
) # )
@main.route( # @main.route(
"/services/<uuid:service_id>/notifications.csv", endpoint="view_notifications_csv" # "/services/<uuid:service_id>/notifications.csv", endpoint="view_notifications_csv"
) # )
@main.route( # @main.route(
"/services/<uuid:service_id>/notifications/<template_type:message_type>.csv", # "/services/<uuid:service_id>/notifications/<template_type:message_type>.csv",
endpoint="view_notifications_csv", # endpoint="view_notifications_csv",
) # )
@user_has_permissions() # @user_has_permissions()
def get_notifications(service_id, message_type, status_override=None): # noqa # def get_notifications(service_id, message_type, status_override=None): # noqa
# TODO get the api to return count of pages as well. # # TODO get the api to return count of pages as well.
page = get_page_from_request() # page = get_page_from_request()
if page is None: # if page is None:
abort(404, "Invalid page argument ({}).".format(request.args.get("page"))) # abort(404, "Invalid page argument ({}).".format(request.args.get("page")))
filter_args = parse_filter_args(request.args) # filter_args = parse_filter_args(request.args)
filter_args["status"] = set_status_filters(filter_args) # filter_args["status"] = set_status_filters(filter_args)
service_data_retention_days = None # service_data_retention_days = None
search_term = request.form.get("to", "") # search_term = request.form.get("to", "")
if message_type is not None: # if message_type is not None:
service_data_retention_days = current_service.get_days_of_retention( # service_data_retention_days = current_service.get_days_of_retention(
message_type, number_of_days="seven_day" # message_type, number_of_days="seven_day"
) # )
#
if request.path.endswith("csv") and current_user.has_permissions( # if request.path.endswith("csv") and current_user.has_permissions(
ServicePermission.VIEW_ACTIVITY # ServicePermission.VIEW_ACTIVITY
): # ):
return Response( # return Response(
generate_notifications_csv( # generate_notifications_csv(
service_id=service_id, # service_id=service_id,
page=page, # page=page,
page_size=5000, # page_size=5000,
template_type=[message_type], # template_type=[message_type],
status=filter_args.get("status"), # status=filter_args.get("status"),
limit_days=service_data_retention_days, # limit_days=service_data_retention_days,
), # ),
mimetype="text/csv", # mimetype="text/csv",
headers={"Content-Disposition": 'inline; filename="notifications.csv"'}, # headers={"Content-Disposition": 'inline; filename="notifications.csv"'},
) # )
notifications = notification_api_client.get_notifications_for_service( # notifications = notification_api_client.get_notifications_for_service(
service_id=service_id, # service_id=service_id,
page=page, # page=page,
template_type=[message_type] if message_type else [], # template_type=[message_type] if message_type else [],
status=filter_args.get("status"), # status=filter_args.get("status"),
limit_days=service_data_retention_days, # limit_days=service_data_retention_days,
to=search_term, # to=search_term,
) # )
#
notifications_list = notifications.get("notifications", []) # notifications_list = notifications.get("notifications", [])
#
url_args = {"message_type": message_type, "status": request.args.get("status")} # url_args = {"message_type": message_type, "status": request.args.get("status")}
prev_page = None # prev_page = None
if "links" in notifications and notifications["links"].get("prev", None): # if "links" in notifications and notifications["links"].get("prev", None):
prev_page = generate_previous_dict( # prev_page = generate_previous_dict(
"main.view_notifications", service_id, page, url_args=url_args # "main.view_notifications", service_id, page, url_args=url_args
) # )
next_page = None # next_page = None
#
total_items = notifications.get("total", 0) # total_items = notifications.get("total", 0)
page_size = notifications.get("page_size", 50) # page_size = notifications.get("page_size", 50)
total_pages = (total_items + page_size - 1) // page_size # total_pages = (total_items + page_size - 1) // page_size
if ( # if (
"links" in notifications # "links" in notifications
and notifications["links"].get("next", None) # and notifications["links"].get("next", None)
and total_items > 50 # and total_items > 50
and page < total_pages # and page < total_pages
): # ):
next_page = generate_next_dict( # next_page = generate_next_dict(
"main.view_notifications", service_id, page, url_args # "main.view_notifications", service_id, page, url_args
) # )
#
if message_type: # if message_type:
download_link = url_for( # download_link = url_for(
".view_notifications_csv", # ".view_notifications_csv",
service_id=current_service.id, # service_id=current_service.id,
message_type=message_type, # message_type=message_type,
status=request.args.get("status"), # status=request.args.get("status"),
) # )
else: # else:
download_link = None # download_link = None
return { # return {
"service_data_retention_days": service_data_retention_days, # "service_data_retention_days": service_data_retention_days,
"counts": render_template( # "counts": render_template(
"views/activity/counts.html", # "views/activity/counts.html",
status=request.args.get("status"), # status=request.args.get("status"),
status_filters=get_status_filters( # status_filters=get_status_filters(
current_service, # current_service,
message_type, # message_type,
service_api_client.get_service_statistics( # service_api_client.get_service_statistics(
service_id, limit_days=service_data_retention_days # service_id, limit_days=service_data_retention_days
), # ),
), # ),
), # ),
"notifications": render_template( # "notifications": render_template(
"views/activity/notifications.html", # "views/activity/notifications.html",
notifications=list( # notifications=list(
add_preview_of_content_to_notifications(notifications_list) # add_preview_of_content_to_notifications(notifications_list)
), # ),
page=page, # page=page,
limit_days=service_data_retention_days, # limit_days=service_data_retention_days,
prev_page=prev_page, # prev_page=prev_page,
next_page=next_page, # next_page=next_page,
show_pagination=(not search_term), # show_pagination=(not search_term),
status=request.args.get("status"), # status=request.args.get("status"),
message_type=message_type, # message_type=message_type,
download_link=download_link, # download_link=download_link,
single_notification_url=partial( # single_notification_url=partial(
url_for, # url_for,
".view_notification", # ".view_notification",
service_id=current_service.id, # service_id=current_service.id,
), # ),
), # ),
} # }
def get_status_filters(service, message_type, statistics): # def get_status_filters(service, message_type, statistics):
message_types = ( # message_types = (
[message_type] # [message_type]
if message_type # if message_type
else [NotificationType.EMAIL, NotificationType.SMS] # else [NotificationType.EMAIL, NotificationType.SMS]
) # )
#
stats = { # stats = {
NotificationStatus.REQUESTED: sum( # NotificationStatus.REQUESTED: sum(
statistics[mt].get(NotificationStatus.REQUESTED, 0) for mt in message_types # statistics[mt].get(NotificationStatus.REQUESTED, 0) for mt in message_types
), # ),
NotificationStatus.DELIVERED: sum( # NotificationStatus.DELIVERED: sum(
statistics[mt].get(NotificationStatus.DELIVERED, 0) for mt in message_types # statistics[mt].get(NotificationStatus.DELIVERED, 0) for mt in message_types
), # ),
NotificationStatus.FAILED: sum( # NotificationStatus.FAILED: sum(
statistics[mt].get(NotificationStatus.FAILED, 0) for mt in message_types # statistics[mt].get(NotificationStatus.FAILED, 0) for mt in message_types
), # ),
} # }
#
stats[NotificationStatus.PENDING] = ( # stats[NotificationStatus.PENDING] = (
stats[NotificationStatus.REQUESTED] # stats[NotificationStatus.REQUESTED]
- stats[NotificationStatus.DELIVERED] # - stats[NotificationStatus.DELIVERED]
- stats[NotificationStatus.FAILED] # - stats[NotificationStatus.FAILED]
) # )
#
filters = [ # filters = [
(NotificationStatus.REQUESTED, "total", "sending,delivered,failed"), # (NotificationStatus.REQUESTED, "total", "sending,delivered,failed"),
(NotificationStatus.PENDING, "pending", "sending,pending"), # (NotificationStatus.PENDING, "pending", "sending,pending"),
(NotificationStatus.DELIVERED, "delivered", "delivered"), # (NotificationStatus.DELIVERED, "delivered", "delivered"),
(NotificationStatus.FAILED, "failed", "failed"), # (NotificationStatus.FAILED, "failed", "failed"),
] # ]
return [ # return [
( # (
label, # label,
option, # option,
url_for( # url_for(
".view_notifications", # ".view_notifications",
service_id=service.id, # service_id=service.id,
message_type=message_type, # message_type=message_type,
status=option, # status=option,
), # ),
stats.get(key), # stats.get(key),
) # )
for key, label, option in filters # for key, label, option in filters
] # ]
def _get_job_counts(job): def _get_job_counts(job):

View File

@@ -63,7 +63,7 @@ class HeaderNavigation(Navigation):
"service_dashboard", "service_dashboard",
"template_usage", "template_usage",
"view_notification", "view_notification",
"view_notifications", # "view_notifications",
"action_blocked", "action_blocked",
"add_service_template", "add_service_template",
"check_messages", "check_messages",
@@ -160,7 +160,7 @@ class MainNavigation(Navigation):
"service_dashboard", "service_dashboard",
"template_usage", "template_usage",
"view_notification", "view_notification",
"view_notifications", # "view_notifications",
}, },
"templates": { "templates": {
"action_blocked", "action_blocked",
@@ -268,7 +268,7 @@ class CaseworkNavigation(Navigation):
"send_one_off_to_myself", "send_one_off_to_myself",
}, },
"sent-messages": { "sent-messages": {
"view_notifications", # "view_notifications",
"view_notification", "view_notification",
}, },
"uploads": { "uploads": {

View File

@@ -10,9 +10,9 @@
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('dashboard') }}" href="{{ url_for('.service_dashboard', service_id=current_service.id) }}">Dashboard</a></li> <li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('dashboard') }}" href="{{ url_for('.service_dashboard', service_id=current_service.id) }}">Dashboard</a></li>
<li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('activity') }}" href="{{ url_for('.all_jobs_activity', service_id=current_service.id) }}">Activity</a></li> <li class="usa-sidenav__item"><a class="{{ main_navigation.is_selected('activity') }}" href="{{ url_for('.all_jobs_activity', service_id=current_service.id) }}">Activity</a></li>
{% endif %} {% endif %}
{% if not current_user.has_permissions(ServicePermission.VIEW_ACTIVITY) %} {# {% if not current_user.has_permissions(ServicePermission.VIEW_ACTIVITY) %} #}
<li class="usa-sidenav__item"><a class="{{ casework_navigation.is_selected('sent-messages') }}" href="{{ url_for('.view_notifications', service_id=current_service.id, status='sending,delivered,failed') }}">Sent messages</a></li> {# <li class="usa-sidenav__item"><a class="{{ casework_navigation.is_selected('sent-messages') }}" href="{{ url_for('.view_notifications', service_id=current_service.id, status='sending,delivered,failed') }}">Sent messages</a></li> #}
{% endif %} {# {% endif %} #}
{% elif current_user.has_permissions(allow_org_user=True) %} {% elif current_user.has_permissions(allow_org_user=True) %}
<li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('usage') }}" href="{{ url_for('.usage', service_id=current_service.id) }}">Usage</a></li> <li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('usage') }}" href="{{ url_for('.usage', service_id=current_service.id) }}">Usage</a></li>
<li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('team-members') }}" href="{{ url_for('.manage_users', service_id=current_service.id) }}">Team members</a></li> <li class="usa-sidenav__item"><a class="usa-link{{ main_navigation.is_selected('team-members') }}" href="{{ url_for('.manage_users', service_id=current_service.id) }}">Team members</a></li>

View File

@@ -1,92 +0,0 @@
{% extends "withnav_template.html" %}
{% from "components/ajax-block.html" import ajax_block %}
{% from "components/page-header.html" import page_header %}
{% from "components/page-footer.html" import page_footer %}
{% from "components/form.html" import form_wrapper %}
{% from "components/components/button/macro.njk" import usaButton %}
{% set page_title = (
(99|message_count_label(message_type, suffix='')) | capitalize
if current_user.has_permissions(ServicePermission.VIEW_ACTIVITY)
else 'Sent messages'
) %}
{% block service_page_title %}
{{ page_title }}
{% endblock %}
{% block maincolumn_content %}
{{ page_header(page_title) }}
{{ ajax_block(
partials,
url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status),
'counts'
) }}
<p class="notification-status {{ field_status }}">
Messages will remain in pending state until carrier status is received, typically 5 minutes.
</p>
{% call form_wrapper(
action=url_for('.view_notifications', service_id=current_service.id, message_type=message_type),
class="usa-search margin-bottom-2"
) %}
<div class="grid-col-4 {% if message_type == 'sms' %}extra-tracking{% endif %}">
{{ search_form.to(param_extensions={
"label": {
"text": things_you_can_search_by|formatted_list(
conjunction='or',
before_each='',
after_each='',
prefix='Search by',
prefix_plural='Search by'
)
}
}) }}
</div>
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
<button class="usa-button" type="submit">
<span class="usa-search__submit-text">Search </span><img src="/assets/img/usa-icons-bg/search--white.svg"
class="usa-search__submit-icon" alt="Search" />
</button>
{% endcall %}
{% call form_wrapper(id="search-form") %}
<input type="hidden" name="to" {% if search_form.to.data %}value="{{ search_form.to.data }}{% endif %}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
{% endcall %}
{% if current_user.has_permissions(ServicePermission.VIEW_ACTIVITY) %}
<p class="font-body-sm">
<a href="{{ download_link_seven_day }}" download="download" class="usa-button usa-button--outline">Download all data last 7 days (<abbr title="Comma separated values">CSV</abbr>)</a>
&emsp;
Data available for {{ partials.service_data_retention_days }} days
</p>
<p class="font-body-sm">
<a href="{{ download_link_five_day }}" download="download" class="usa-button usa-button--outline">Download all data last 5 days (<abbr title="Comma separated values">CSV</abbr>)</a>
&emsp;
</p>
<p class="font-body-sm">
<a href="{{ download_link_three_day }}" download="download" class="usa-button usa-button--outline">Download all data last 3 days (<abbr title="Comma separated values">CSV</abbr>)</a>
&emsp;
</p>
<p class="font-body-sm">
<a href="{{ download_link_today }}" download="download" class="usa-button usa-button--outline">Download all data today (<abbr title="Comma separated values">CSV</abbr>)</a>
&emsp;
</p>
{% endif %}
{{ ajax_block(
partials,
url_for('.get_notifications_as_json', service_id=current_service.id, message_type=message_type, status=status, page=page),
'notifications',
form='search-form'
) }}
{% endblock %}

View File

@@ -104,7 +104,6 @@ EXCLUDED_ENDPOINTS = tuple(
"get_daily_stats_by_user", "get_daily_stats_by_user",
"get_volumes_by_service", "get_volumes_by_service",
"get_example_csv", "get_example_csv",
"get_notifications_as_json",
"get_redis_report", "get_redis_report",
"get_started", "get_started",
"get_started_old", "get_started_old",