mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Getting NotificationStatus implemented everywhere.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -8,12 +8,10 @@ from sqlalchemy.sql.expression import case, literal
|
||||
from app import db
|
||||
from app.dao.date_util import get_calendar_year_dates, get_calendar_year_for_datetime
|
||||
from app.dao.organization_dao import dao_get_organization_live_services
|
||||
from app.enums import NotificationType
|
||||
from app.enums import NotificationStatus, NotificationType
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
NOTIFICATION_STATUS_TYPES_BILLABLE_SMS,
|
||||
NOTIFICATION_STATUS_TYPES_SENT_EMAILS,
|
||||
AnnualBilling,
|
||||
FactBilling,
|
||||
NotificationAllTimeView,
|
||||
@@ -412,9 +410,7 @@ def _query_for_billing_data(notification_type, start_date, end_date, service):
|
||||
func.count().label("notifications_sent"),
|
||||
)
|
||||
.filter(
|
||||
NotificationAllTimeView.status.in_(
|
||||
NOTIFICATION_STATUS_TYPES_SENT_EMAILS
|
||||
),
|
||||
NotificationAllTimeView.status.in_(NotificationStatus.sent_emails),
|
||||
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
@@ -446,9 +442,7 @@ def _query_for_billing_data(notification_type, start_date, end_date, service):
|
||||
func.count().label("notifications_sent"),
|
||||
)
|
||||
.filter(
|
||||
NotificationAllTimeView.status.in_(
|
||||
NOTIFICATION_STATUS_TYPES_BILLABLE_SMS
|
||||
),
|
||||
NotificationAllTimeView.status.in_(NotificationStatus.billable_sms),
|
||||
NotificationAllTimeView.key_type.in_((KEY_TYPE_NORMAL, KEY_TYPE_TEAM)),
|
||||
NotificationAllTimeView.created_at >= start_date,
|
||||
NotificationAllTimeView.created_at < end_date,
|
||||
|
||||
@@ -7,21 +7,11 @@ from sqlalchemy.types import DateTime, Integer
|
||||
|
||||
from app import db
|
||||
from app.dao.dao_utils import autocommit
|
||||
from app.enums import NotificationType
|
||||
from app.enums import NotificationType, NotificationStatus
|
||||
from app.models import (
|
||||
KEY_TYPE_NORMAL,
|
||||
KEY_TYPE_TEAM,
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_CANCELLED,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_DELIVERED,
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_TECHNICAL_FAILURE,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
FactNotificationStatus,
|
||||
Notification,
|
||||
NotificationAllTimeView,
|
||||
@@ -386,7 +376,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
FactNotificationStatus.local_date >= start_date,
|
||||
FactNotificationStatus.local_date <= end_date,
|
||||
FactNotificationStatus.key_type != KEY_TYPE_TEST,
|
||||
FactNotificationStatus.notification_status != NOTIFICATION_CANCELLED,
|
||||
FactNotificationStatus.notification_status != NotificationStatus.CANCELLED,
|
||||
)
|
||||
.group_by(
|
||||
FactNotificationStatus.template_id,
|
||||
@@ -423,7 +413,7 @@ def fetch_monthly_template_usage_for_service(start_date, end_date, service_id):
|
||||
Notification.created_at >= today,
|
||||
Notification.service_id == service_id,
|
||||
Notification.key_type != KEY_TYPE_TEST,
|
||||
Notification.status != NOTIFICATION_CANCELLED,
|
||||
Notification.status != NotificationStatus.CANCELLED,
|
||||
)
|
||||
.group_by(
|
||||
Notification.template_id,
|
||||
@@ -517,7 +507,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status.in_(
|
||||
[NOTIFICATION_SENDING, NOTIFICATION_PENDING]
|
||||
[NotificationStatus.SENDING, NotificationStatus.PENDING]
|
||||
),
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
@@ -530,7 +520,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status
|
||||
== NOTIFICATION_DELIVERED,
|
||||
== NotificationStatus.DELIVERED,
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
],
|
||||
@@ -542,7 +532,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status.in_(
|
||||
[NOTIFICATION_TECHNICAL_FAILURE, NOTIFICATION_FAILED]
|
||||
[NotificationStatus.TECHNICAL_FAILURE, NotificationStatus.FAILED]
|
||||
),
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
@@ -555,7 +545,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status
|
||||
== NOTIFICATION_TEMPORARY_FAILURE,
|
||||
== NotificationStatus.TEMPORARY_FAILURE,
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
],
|
||||
@@ -567,7 +557,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status
|
||||
== NOTIFICATION_PERMANENT_FAILURE,
|
||||
== NotificationStatus.PERMANENT_FAILURE,
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
],
|
||||
@@ -579,7 +569,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
[
|
||||
(
|
||||
FactNotificationStatus.notification_status
|
||||
== NOTIFICATION_SENT,
|
||||
== NotificationStatus.SENT,
|
||||
FactNotificationStatus.notification_count,
|
||||
)
|
||||
],
|
||||
@@ -589,7 +579,7 @@ def fetch_monthly_notification_statuses_per_service(start_date, end_date):
|
||||
)
|
||||
.join(Service, FactNotificationStatus.service_id == Service.id)
|
||||
.filter(
|
||||
FactNotificationStatus.notification_status != NOTIFICATION_CREATED,
|
||||
FactNotificationStatus.notification_status != NotificationStatus.CREATED,
|
||||
Service.active.is_(True),
|
||||
FactNotificationStatus.key_type != KEY_TYPE_TEST,
|
||||
Service.restricted.is_(False),
|
||||
|
||||
@@ -16,17 +16,9 @@ from werkzeug.datastructures import MultiDict
|
||||
|
||||
from app import create_uuid, db
|
||||
from app.dao.dao_utils import autocommit
|
||||
from app.enums import NotificationType
|
||||
from app.enums import NotificationType, NotificationStatus
|
||||
from app.models import (
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_FAILED,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_TEMPORARY_FAILURE,
|
||||
FactNotificationStatus,
|
||||
Notification,
|
||||
NotificationHistory,
|
||||
@@ -70,7 +62,7 @@ def dao_create_notification(notification):
|
||||
# need to populate defaulted fields before we create the notification history object
|
||||
notification.id = create_uuid()
|
||||
if not notification.status:
|
||||
notification.status = NOTIFICATION_CREATED
|
||||
notification.status = NotificationStatus.CREATED
|
||||
# notify-api-742 remove phone numbers from db
|
||||
notification.to = "1"
|
||||
notification.normalised_to = "1"
|
||||
@@ -85,10 +77,10 @@ def country_records_delivery(phone_prefix):
|
||||
def _decide_permanent_temporary_failure(current_status, status):
|
||||
# If we go from pending to delivered we need to set failure type as temporary-failure
|
||||
if (
|
||||
current_status == NOTIFICATION_PENDING
|
||||
and status == NOTIFICATION_PERMANENT_FAILURE
|
||||
current_status == NotificationStatus.PENDING
|
||||
and status == NotificationStatus.PERMANENT_FAILURE
|
||||
):
|
||||
status = NOTIFICATION_TEMPORARY_FAILURE
|
||||
status = NotificationStatus.TEMPORARY_FAILURE
|
||||
return status
|
||||
|
||||
|
||||
@@ -127,11 +119,11 @@ def update_notification_status_by_id(
|
||||
return None
|
||||
|
||||
if notification.status not in {
|
||||
NOTIFICATION_CREATED,
|
||||
NOTIFICATION_SENDING,
|
||||
NOTIFICATION_PENDING,
|
||||
NOTIFICATION_SENT,
|
||||
NOTIFICATION_PENDING_VIRUS_CHECK,
|
||||
NotificationStatus.CREATED,
|
||||
NotificationStatus.SENDING,
|
||||
NotificationStatus.PENDING,
|
||||
NotificationStatus.SENT,
|
||||
NotificationStatus.PENDING_VIRUS_CHECK,
|
||||
}:
|
||||
_duplicate_update_warning(notification, status)
|
||||
return None
|
||||
@@ -171,7 +163,7 @@ def update_notification_status_by_reference(reference, status):
|
||||
)
|
||||
return None
|
||||
|
||||
if notification.status not in {NOTIFICATION_SENDING, NOTIFICATION_PENDING}:
|
||||
if notification.status not in {NotificationStatus.SENDING, NotificationStatus.PENDING}:
|
||||
_duplicate_update_warning(notification, status)
|
||||
return None
|
||||
|
||||
@@ -209,7 +201,7 @@ def dao_get_notification_count_for_service(*, service_id):
|
||||
|
||||
|
||||
def dao_get_failed_notification_count():
|
||||
failed_count = Notification.query.filter_by(status=NOTIFICATION_FAILED).count()
|
||||
failed_count = Notification.query.filter_by(status=NotificationStatus.FAILED).count()
|
||||
return failed_count
|
||||
|
||||
|
||||
@@ -437,8 +429,8 @@ def dao_timeout_notifications(cutoff_time, limit=100000):
|
||||
if they're still sending from before the specified cutoff_time.
|
||||
"""
|
||||
updated_at = datetime.utcnow()
|
||||
current_statuses = [NOTIFICATION_SENDING, NOTIFICATION_PENDING]
|
||||
new_status = NOTIFICATION_TEMPORARY_FAILURE
|
||||
current_statuses = [NotificationStatus.SENDING, NotificationStatus.PENDING]
|
||||
new_status = NotificationStatus.TEMPORARY_FAILURE
|
||||
|
||||
notifications = (
|
||||
Notification.query.filter(
|
||||
@@ -608,7 +600,7 @@ def notifications_not_yet_sent(should_be_sending_after_seconds, notification_typ
|
||||
notifications = Notification.query.filter(
|
||||
Notification.created_at <= older_than_date,
|
||||
Notification.notification_type == notification_type,
|
||||
Notification.status == NOTIFICATION_CREATED,
|
||||
Notification.status == NotificationStatus.CREATED,
|
||||
).all()
|
||||
return notifications
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ from app.dao.organization_dao import dao_get_organization_by_email_address
|
||||
from app.dao.service_sms_sender_dao import insert_service_sms_sender
|
||||
from app.dao.service_user_dao import dao_get_service_user
|
||||
from app.dao.template_folder_dao import dao_get_valid_template_folders_by_id
|
||||
from app.enums import NotificationType, ServicePermissionType
|
||||
from app.enums import NotificationStatus, NotificationType, ServicePermissionType
|
||||
from app.models import (
|
||||
KEY_TYPE_TEST,
|
||||
NOTIFICATION_PERMANENT_FAILURE,
|
||||
AnnualBilling,
|
||||
ApiKey,
|
||||
FactBilling,
|
||||
@@ -565,7 +564,7 @@ def dao_find_services_with_high_failure_rates(start_date, end_date, threshold=10
|
||||
Notification.created_at <= end_date,
|
||||
Notification.key_type != KEY_TYPE_TEST,
|
||||
Notification.notification_type == NotificationType.SMS,
|
||||
Notification.status == NOTIFICATION_PERMANENT_FAILURE,
|
||||
Notification.status == NotificationStatus.PERMANENT_FAILURE,
|
||||
Service.restricted == False, # noqa
|
||||
Service.active == True, # noqa
|
||||
)
|
||||
|
||||
@@ -5,11 +5,10 @@ from flask import current_app
|
||||
from sqlalchemy import String, and_, desc, func, literal, text
|
||||
|
||||
from app import db
|
||||
from app.enums import NotificationType
|
||||
from app.enums import NotificationStatus, NotificationType
|
||||
from app.models import (
|
||||
JOB_STATUS_CANCELLED,
|
||||
JOB_STATUS_SCHEDULED,
|
||||
NOTIFICATION_CANCELLED,
|
||||
Job,
|
||||
Notification,
|
||||
ServiceDataRetention,
|
||||
@@ -92,7 +91,7 @@ def dao_get_uploads_by_service_id(service_id, limit_days=None, page=1, page_size
|
||||
Notification.service_id == service_id,
|
||||
Notification.notification_type == NotificationType.LETTER,
|
||||
Notification.api_key_id == None, # noqa
|
||||
Notification.status != NOTIFICATION_CANCELLED,
|
||||
Notification.status != NotificationStatus.CANCELLED,
|
||||
Template.hidden == True, # noqa
|
||||
Notification.created_at
|
||||
>= today - func.coalesce(ServiceDataRetention.days_of_retention, 7),
|
||||
|
||||
Reference in New Issue
Block a user