mirror of
https://github.com/GSA/notifications-api.git
synced 2026-09-11 02:23:32 -04:00
Made enums.py for all the enums to avoid cyclic imports.
Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
from app.enums import NotificationType
|
||||||
|
|
||||||
create_or_update_free_sms_fragment_limit_schema = {
|
create_or_update_free_sms_fragment_limit_schema = {
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
"description": "POST annual billing schema",
|
"description": "POST annual billing schema",
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ from app.dao.notifications_dao import (
|
|||||||
from app.dao.service_data_retention_dao import (
|
from app.dao.service_data_retention_dao import (
|
||||||
fetch_service_data_retention_for_all_services_by_notification_type,
|
fetch_service_data_retention_for_all_services_by_notification_type,
|
||||||
)
|
)
|
||||||
from app.models import FactProcessingTime, NotificationType
|
from app.enums import NotificationType
|
||||||
|
from app.models import FactProcessingTime
|
||||||
from app.utils import get_midnight_in_utc
|
from app.utils import get_midnight_in_utc
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from app.cronitor import cronitor
|
|||||||
from app.dao.fact_billing_dao import fetch_billing_data_for_day, update_fact_billing
|
from app.dao.fact_billing_dao import fetch_billing_data_for_day, update_fact_billing
|
||||||
from app.dao.fact_notification_status_dao import update_fact_notification_status
|
from app.dao.fact_notification_status_dao import update_fact_notification_status
|
||||||
from app.dao.notifications_dao import get_service_ids_with_notifications_on_date
|
from app.dao.notifications_dao import get_service_ids_with_notifications_on_date
|
||||||
from app.models import NotificationType
|
from app.enums import NotificationType
|
||||||
|
|
||||||
|
|
||||||
@notify_celery.task(name="create-nightly-billing")
|
@notify_celery.task(name="create-nightly-billing")
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from requests import HTTPError, request
|
|||||||
from app.celery.process_ses_receipts_tasks import process_ses_results
|
from app.celery.process_ses_receipts_tasks import process_ses_results
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames
|
||||||
from app.dao.notifications_dao import get_notification_by_id
|
from app.dao.notifications_dao import get_notification_by_id
|
||||||
from app.models import NotificationType
|
from app.enums import NotificationType
|
||||||
|
|
||||||
temp_fail = "2028675303"
|
temp_fail = "2028675303"
|
||||||
perm_fail = "2028675302"
|
perm_fail = "2028675302"
|
||||||
|
|||||||
@@ -34,13 +34,8 @@ from app.dao.services_dao import (
|
|||||||
)
|
)
|
||||||
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
from app.dao.users_dao import delete_codes_older_created_more_than_a_day_ago
|
||||||
from app.delivery.send_to_providers import provider_to_use
|
from app.delivery.send_to_providers import provider_to_use
|
||||||
from app.models import (
|
from app.enums import NotificationType
|
||||||
JOB_STATUS_ERROR,
|
from app.models import JOB_STATUS_ERROR, JOB_STATUS_IN_PROGRESS, JOB_STATUS_PENDING, Job
|
||||||
JOB_STATUS_IN_PROGRESS,
|
|
||||||
JOB_STATUS_PENDING,
|
|
||||||
Job,
|
|
||||||
NotificationType,
|
|
||||||
)
|
|
||||||
from app.notifications.process_notifications import send_notification_to_queue
|
from app.notifications.process_notifications import send_notification_to_queue
|
||||||
|
|
||||||
MAX_NOTIFICATION_FAILS = 10000
|
MAX_NOTIFICATION_FAILS = 10000
|
||||||
|
|||||||
+1
-1
@@ -20,13 +20,13 @@ from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
|||||||
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
|
from app.dao.service_inbound_api_dao import get_service_inbound_api_for_service
|
||||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||||
from app.dao.templates_dao import dao_get_template_by_id
|
from app.dao.templates_dao import dao_get_template_by_id
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
JOB_STATUS_CANCELLED,
|
JOB_STATUS_CANCELLED,
|
||||||
JOB_STATUS_FINISHED,
|
JOB_STATUS_FINISHED,
|
||||||
JOB_STATUS_IN_PROGRESS,
|
JOB_STATUS_IN_PROGRESS,
|
||||||
JOB_STATUS_PENDING,
|
JOB_STATUS_PENDING,
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
NotificationType,
|
|
||||||
)
|
)
|
||||||
from app.notifications.process_notifications import persist_notification
|
from app.notifications.process_notifications import persist_notification
|
||||||
from app.notifications.validators import check_service_over_total_message_limit
|
from app.notifications.validators import check_service_over_total_message_limit
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from requests import HTTPError, request
|
|||||||
from app.celery.process_ses_receipts_tasks import process_ses_results
|
from app.celery.process_ses_receipts_tasks import process_ses_results
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames
|
||||||
from app.dao.notifications_dao import get_notification_by_id
|
from app.dao.notifications_dao import get_notification_by_id
|
||||||
from app.models import NotificationType
|
from app.enums import NotificationType
|
||||||
|
|
||||||
temp_fail = "2028675303"
|
temp_fail = "2028675303"
|
||||||
perm_fail = "2028675302"
|
perm_fail = "2028675302"
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import Protocol
|
from typing import Protocol
|
||||||
|
|
||||||
from app.models import NotificationType
|
|
||||||
from botocore.config import Config
|
from botocore.config import Config
|
||||||
|
|
||||||
|
from app.enums import NotificationType
|
||||||
|
|
||||||
AWS_CLIENT_CONFIG = Config(
|
AWS_CLIENT_CONFIG = Config(
|
||||||
# This config is required to enable S3 to connect to FIPS-enabled
|
# This config is required to enable S3 to connect to FIPS-enabled
|
||||||
# endpoints. See https://aws.amazon.com/compliance/fips/ for more
|
# endpoints. See https://aws.amazon.com/compliance/fips/ for more
|
||||||
@@ -54,7 +55,10 @@ class NotificationProviderClients(object):
|
|||||||
return self.email_clients.get(name)
|
return self.email_clients.get(name)
|
||||||
|
|
||||||
def get_client_by_name_and_type(self, name, notification_type):
|
def get_client_by_name_and_type(self, name, notification_type):
|
||||||
assert notification_type in {NotificationType.EMAIL, NotificationType.SMS} # nosec B101
|
assert notification_type in {
|
||||||
|
NotificationType.EMAIL,
|
||||||
|
NotificationType.SMS,
|
||||||
|
} # nosec B101
|
||||||
|
|
||||||
if notification_type == NotificationType.EMAIL:
|
if notification_type == NotificationType.EMAIL:
|
||||||
return self.get_email_client(name)
|
return self.get_email_client(name)
|
||||||
|
|||||||
+1
-1
@@ -49,6 +49,7 @@ from app.dao.users_dao import (
|
|||||||
delete_user_verify_codes,
|
delete_user_verify_codes,
|
||||||
get_user_by_email,
|
get_user_by_email,
|
||||||
)
|
)
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
@@ -56,7 +57,6 @@ from app.models import (
|
|||||||
Domain,
|
Domain,
|
||||||
EmailBranding,
|
EmailBranding,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationType,
|
|
||||||
Organization,
|
Organization,
|
||||||
Service,
|
Service,
|
||||||
Template,
|
Template,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from sqlalchemy.sql.expression import case, literal
|
|||||||
from app import db
|
from app import db
|
||||||
from app.dao.date_util import get_calendar_year_dates, get_calendar_year_for_datetime
|
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.dao.organization_dao import dao_get_organization_live_services
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
KEY_TYPE_TEAM,
|
KEY_TYPE_TEAM,
|
||||||
@@ -17,7 +18,6 @@ from app.models import (
|
|||||||
FactBilling,
|
FactBilling,
|
||||||
NotificationAllTimeView,
|
NotificationAllTimeView,
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
NotificationType,
|
|
||||||
Organization,
|
Organization,
|
||||||
Rate,
|
Rate,
|
||||||
Service,
|
Service,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from sqlalchemy.types import DateTime, Integer
|
|||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_NORMAL,
|
KEY_TYPE_NORMAL,
|
||||||
KEY_TYPE_TEAM,
|
KEY_TYPE_TEAM,
|
||||||
@@ -23,7 +24,6 @@ from app.models import (
|
|||||||
NOTIFICATION_TEMPORARY_FAILURE,
|
NOTIFICATION_TEMPORARY_FAILURE,
|
||||||
FactNotificationStatus,
|
FactNotificationStatus,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationType,
|
|
||||||
NotificationAllTimeView,
|
NotificationAllTimeView,
|
||||||
Service,
|
Service,
|
||||||
Template,
|
Template,
|
||||||
@@ -468,7 +468,8 @@ def get_total_notifications_for_date_range(start_date, end_date):
|
|||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
FactNotificationStatus.notification_type == NotificationType.EMAIL,
|
FactNotificationStatus.notification_type
|
||||||
|
== NotificationType.EMAIL,
|
||||||
FactNotificationStatus.notification_count,
|
FactNotificationStatus.notification_count,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -479,7 +480,8 @@ def get_total_notifications_for_date_range(start_date, end_date):
|
|||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
FactNotificationStatus.notification_type == NotificationType.SMS,
|
FactNotificationStatus.notification_type
|
||||||
|
== NotificationType.SMS,
|
||||||
FactNotificationStatus.notification_count,
|
FactNotificationStatus.notification_count,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,13 +5,8 @@ from sqlalchemy.orm import aliased
|
|||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
from app.models import (
|
from app.enums import NotificationType
|
||||||
InboundSms,
|
from app.models import InboundSms, InboundSmsHistory, Service, ServiceDataRetention
|
||||||
InboundSmsHistory,
|
|
||||||
NotificationType,
|
|
||||||
Service,
|
|
||||||
ServiceDataRetention,
|
|
||||||
)
|
|
||||||
from app.utils import midnight_n_days_ago
|
from app.utils import midnight_n_days_ago
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ from werkzeug.datastructures import MultiDict
|
|||||||
|
|
||||||
from app import create_uuid, db
|
from app import create_uuid, db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
NOTIFICATION_CREATED,
|
NOTIFICATION_CREATED,
|
||||||
@@ -29,7 +30,6 @@ from app.models import (
|
|||||||
FactNotificationStatus,
|
FactNotificationStatus,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
NotificationType,
|
|
||||||
)
|
)
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
escape_special_characters,
|
escape_special_characters,
|
||||||
|
|||||||
@@ -5,13 +5,8 @@ from sqlalchemy import asc, desc, func
|
|||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
from app.dao.dao_utils import autocommit
|
from app.dao.dao_utils import autocommit
|
||||||
from app.models import (
|
from app.enums import NotificationType
|
||||||
FactBilling,
|
from app.models import FactBilling, ProviderDetails, ProviderDetailsHistory, User
|
||||||
NotificationType,
|
|
||||||
ProviderDetails,
|
|
||||||
ProviderDetailsHistory,
|
|
||||||
User,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_provider_details_by_id(provider_details_id):
|
def get_provider_details_by_id(provider_details_id):
|
||||||
@@ -62,7 +57,8 @@ def _get_sms_providers_for_update(time_threshold):
|
|||||||
# get current priority of both providers
|
# get current priority of both providers
|
||||||
q = (
|
q = (
|
||||||
ProviderDetails.query.filter(
|
ProviderDetails.query.filter(
|
||||||
ProviderDetails.notification_type == NotificationType.SMS, ProviderDetails.active
|
ProviderDetails.notification_type == NotificationType.SMS,
|
||||||
|
ProviderDetails.active,
|
||||||
)
|
)
|
||||||
.with_for_update()
|
.with_for_update()
|
||||||
.all()
|
.all()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ 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_sms_sender_dao import insert_service_sms_sender
|
||||||
from app.dao.service_user_dao import dao_get_service_user
|
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.dao.template_folder_dao import dao_get_valid_template_folders_by_id
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
KEY_TYPE_TEST,
|
KEY_TYPE_TEST,
|
||||||
NOTIFICATION_PERMANENT_FAILURE,
|
NOTIFICATION_PERMANENT_FAILURE,
|
||||||
@@ -24,7 +25,6 @@ from app.models import (
|
|||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationHistory,
|
NotificationHistory,
|
||||||
NotificationType,
|
|
||||||
Organization,
|
Organization,
|
||||||
Permission,
|
Permission,
|
||||||
Service,
|
Service,
|
||||||
@@ -106,7 +106,8 @@ def dao_fetch_live_services_data():
|
|||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
this_year_ft_billing.c.notification_type == NotificationType.EMAIL,
|
this_year_ft_billing.c.notification_type
|
||||||
|
== NotificationType.EMAIL,
|
||||||
func.sum(this_year_ft_billing.c.notifications_sent),
|
func.sum(this_year_ft_billing.c.notifications_sent),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@@ -115,7 +116,8 @@ def dao_fetch_live_services_data():
|
|||||||
case(
|
case(
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
this_year_ft_billing.c.notification_type == NotificationType.SMS,
|
this_year_ft_billing.c.notification_type
|
||||||
|
== NotificationType.SMS,
|
||||||
func.sum(this_year_ft_billing.c.notifications_sent),
|
func.sum(this_year_ft_billing.c.notifications_sent),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ from flask import current_app
|
|||||||
from sqlalchemy import String, and_, desc, func, literal, text
|
from sqlalchemy import String, and_, desc, func, literal, text
|
||||||
|
|
||||||
from app import db
|
from app import db
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.models import (
|
from app.models import (
|
||||||
JOB_STATUS_CANCELLED,
|
JOB_STATUS_CANCELLED,
|
||||||
JOB_STATUS_SCHEDULED,
|
JOB_STATUS_SCHEDULED,
|
||||||
NOTIFICATION_CANCELLED,
|
NOTIFICATION_CANCELLED,
|
||||||
Job,
|
Job,
|
||||||
Notification,
|
Notification,
|
||||||
NotificationType,
|
|
||||||
ServiceDataRetention,
|
ServiceDataRetention,
|
||||||
Template,
|
Template,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from app.celery.test_key_tasks import send_email_response, send_sms_response
|
|||||||
from app.dao.email_branding_dao import dao_get_email_branding_by_id
|
from app.dao.email_branding_dao import dao_get_email_branding_by_id
|
||||||
from app.dao.notifications_dao import dao_update_notification
|
from app.dao.notifications_dao import dao_update_notification
|
||||||
from app.dao.provider_details_dao import get_provider_details_by_notification_type
|
from app.dao.provider_details_dao import get_provider_details_by_notification_type
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.exceptions import NotificationTechnicalFailureException
|
from app.exceptions import NotificationTechnicalFailureException
|
||||||
from app.models import (
|
from app.models import (
|
||||||
BRANDING_BOTH,
|
BRANDING_BOTH,
|
||||||
@@ -23,7 +24,6 @@ from app.models import (
|
|||||||
NOTIFICATION_SENDING,
|
NOTIFICATION_SENDING,
|
||||||
NOTIFICATION_STATUS_TYPES_COMPLETED,
|
NOTIFICATION_STATUS_TYPES_COMPLETED,
|
||||||
NOTIFICATION_TECHNICAL_FAILURE,
|
NOTIFICATION_TECHNICAL_FAILURE,
|
||||||
NotificationType,
|
|
||||||
)
|
)
|
||||||
from app.serialised_models import SerialisedService, SerialisedTemplate
|
from app.serialised_models import SerialisedService, SerialisedTemplate
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateType(Enum):
|
||||||
|
SMS = "sms"
|
||||||
|
EMAIL = "email"
|
||||||
|
LETTER = "letter"
|
||||||
|
|
||||||
|
|
||||||
|
class NotificationType(Enum):
|
||||||
|
SMS = "sms"
|
||||||
|
EMAIL = "email"
|
||||||
|
LETTER = "letter"
|
||||||
|
|
||||||
|
|
||||||
|
class UserAuthType(Enum):
|
||||||
|
SMS = "sms_auth"
|
||||||
|
EMAIL = "email_auth"
|
||||||
|
WEBAUTHN = "webauthn_auth"
|
||||||
|
|
||||||
|
|
||||||
|
class ServiceCallbackType(Enum):
|
||||||
|
# TODO: Should ServiceCallbackApi.callback_type be changed to use this?
|
||||||
|
DELIVERY_STATUS = "delivery_status"
|
||||||
|
COMPLAINT = "complaint"
|
||||||
|
|
||||||
|
|
||||||
|
class ServicePermissionType(Enum):
|
||||||
|
EMAIL = "email"
|
||||||
|
SMS = "sms"
|
||||||
|
INTERNATIONAL_SMS = "international_sms"
|
||||||
|
INBOUND_SMS = "inbound_sms"
|
||||||
|
SCHEDULE_NOTIFICATIONS = "schedule_notifications"
|
||||||
|
EMAIL_AUTH = "email_auth"
|
||||||
|
UPLOAD_DOCUMENT = "upload_document"
|
||||||
|
EDIT_FOLDER_PERMISSIONS = "edit_folder_permissions"
|
||||||
|
|
||||||
|
|
||||||
|
class GuestListRecipientType(Enum):
|
||||||
|
MOBILE = "mobile"
|
||||||
|
EMAIL = "email"
|
||||||
|
|
||||||
|
|
||||||
|
class KeyType(Enum):
|
||||||
|
NORMAL = "normal"
|
||||||
|
TEAM = "team"
|
||||||
|
TEST = "test"
|
||||||
|
|
||||||
|
|
||||||
|
class JobStatusType(Enum):
|
||||||
|
PENDING = "pending"
|
||||||
|
IN_PROGRESS = "in progress"
|
||||||
|
FINISHED = "finished"
|
||||||
|
SENDING_LIMITS_EXCEEDED = "sending limits exceeded"
|
||||||
|
SCHEDULED = "scheduled"
|
||||||
|
CANCELLED = "cancelled"
|
||||||
|
READY_TO_SEND = "ready to send"
|
||||||
|
SENT_TO_DVLA = "sent to dvla"
|
||||||
|
ERROR = "error"
|
||||||
|
|
||||||
|
|
||||||
|
class AgreementType(Enum):
|
||||||
|
MOU = "MOU"
|
||||||
|
IAA = "IAA"
|
||||||
|
|
||||||
|
|
||||||
|
class AgreementStatus(Enum):
|
||||||
|
ACTIVE = "active"
|
||||||
|
EXPIRED = "expired"
|
||||||
@@ -9,9 +9,9 @@ from app.dao.inbound_sms_dao import (
|
|||||||
from app.dao.service_data_retention_dao import (
|
from app.dao.service_data_retention_dao import (
|
||||||
fetch_service_data_retention_by_notification_type,
|
fetch_service_data_retention_by_notification_type,
|
||||||
)
|
)
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.errors import register_errors
|
from app.errors import register_errors
|
||||||
from app.inbound_sms.inbound_sms_schemas import get_inbound_sms_for_service_schema
|
from app.inbound_sms.inbound_sms_schemas import get_inbound_sms_for_service_schema
|
||||||
from app.models import NotificationType
|
|
||||||
from app.schema_validation import validate
|
from app.schema_validation import validate
|
||||||
|
|
||||||
inbound_sms = Blueprint(
|
inbound_sms = Blueprint(
|
||||||
|
|||||||
+16
-76
@@ -21,6 +21,13 @@ from sqlalchemy.orm import validates
|
|||||||
from sqlalchemy.orm.collections import attribute_mapped_collection
|
from sqlalchemy.orm.collections import attribute_mapped_collection
|
||||||
|
|
||||||
from app import db, encryption
|
from app import db, encryption
|
||||||
|
from app.enums import ( # JobStatusType,; KeyType,; ServicePermissionType,; UserAuthType,
|
||||||
|
AgreementStatus,
|
||||||
|
AgreementType,
|
||||||
|
GuestListRecipientType,
|
||||||
|
NotificationType,
|
||||||
|
TemplateType,
|
||||||
|
)
|
||||||
from app.hashing import check_hash, hashpw
|
from app.hashing import check_hash, hashpw
|
||||||
from app.history_meta import Versioned
|
from app.history_meta import Versioned
|
||||||
from app.utils import (
|
from app.utils import (
|
||||||
@@ -29,19 +36,6 @@ from app.utils import (
|
|||||||
get_dt_string_or_none,
|
get_dt_string_or_none,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class TemplateType(Enum):
|
|
||||||
SMS = "sms"
|
|
||||||
EMAIL = "email"
|
|
||||||
LETTER = "letter"
|
|
||||||
|
|
||||||
|
|
||||||
class NotificationType(Enum):
|
|
||||||
SMS = "sms"
|
|
||||||
EMAIL = "email"
|
|
||||||
LETTER = "letter"
|
|
||||||
|
|
||||||
|
|
||||||
NORMAL = "normal"
|
NORMAL = "normal"
|
||||||
PRIORITY = "priority"
|
PRIORITY = "priority"
|
||||||
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]
|
TEMPLATE_PROCESS_TYPE = [NORMAL, PRIORITY]
|
||||||
@@ -53,28 +47,18 @@ class TemplateProcessType(Enum):
|
|||||||
PRIORITY = "priority"
|
PRIORITY = "priority"
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Change this
|
||||||
SMS_AUTH_TYPE = "sms_auth"
|
SMS_AUTH_TYPE = "sms_auth"
|
||||||
EMAIL_AUTH_TYPE = "email_auth"
|
EMAIL_AUTH_TYPE = "email_auth"
|
||||||
WEBAUTHN_AUTH_TYPE = "webauthn_auth"
|
WEBAUTHN_AUTH_TYPE = "webauthn_auth"
|
||||||
USER_AUTH_TYPES = [SMS_AUTH_TYPE, EMAIL_AUTH_TYPE, WEBAUTHN_AUTH_TYPE]
|
USER_AUTH_TYPES = [SMS_AUTH_TYPE, EMAIL_AUTH_TYPE, WEBAUTHN_AUTH_TYPE]
|
||||||
|
|
||||||
|
|
||||||
class UserAuthType(Enum):
|
# TODO: Change this
|
||||||
# TODO: Should User.auth_type be changed to use this?
|
|
||||||
SMS = "sms_auth"
|
|
||||||
EMAIL = "email_auth"
|
|
||||||
WEBAUTHN = "webauthn_auth"
|
|
||||||
|
|
||||||
|
|
||||||
DELIVERY_STATUS_CALLBACK_TYPE = "delivery_status"
|
DELIVERY_STATUS_CALLBACK_TYPE = "delivery_status"
|
||||||
COMPLAINT_CALLBACK_TYPE = "complaint"
|
COMPLAINT_CALLBACK_TYPE = "complaint"
|
||||||
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]
|
SERVICE_CALLBACK_TYPES = [DELIVERY_STATUS_CALLBACK_TYPE, COMPLAINT_CALLBACK_TYPE]
|
||||||
|
# Need to import ServiceCallbackType from app.enums
|
||||||
|
|
||||||
# class ServiceCallbackType(Enum):
|
|
||||||
# # TODO: Should ServiceCallbackApi.callback_type be changed to use this?
|
|
||||||
# DELIVERY_STATUS = "delivery_status"
|
|
||||||
# COMPLAINT = "complaint"
|
|
||||||
|
|
||||||
|
|
||||||
def filter_null_value_fields(obj):
|
def filter_null_value_fields(obj):
|
||||||
@@ -290,6 +274,7 @@ user_folder_permissions = db.Table(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Change this
|
||||||
BRANDING_GOVUK = "govuk" # Deprecated outside migrations
|
BRANDING_GOVUK = "govuk" # Deprecated outside migrations
|
||||||
BRANDING_ORG = "org"
|
BRANDING_ORG = "org"
|
||||||
BRANDING_BOTH = "both"
|
BRANDING_BOTH = "both"
|
||||||
@@ -358,17 +343,7 @@ service_email_branding = db.Table(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ServicePermissionType(Enum):
|
# TODO: This need to be changed
|
||||||
EMAIL = "email"
|
|
||||||
SMS = "sms"
|
|
||||||
INTERNATIONAL_SMS = "international_sms"
|
|
||||||
INBOUND_SMS = "inbound_sms"
|
|
||||||
SCHEDULE_NOTIFICATIONS = "schedule_notifications"
|
|
||||||
EMAIL_AUTH = "email_auth"
|
|
||||||
UPLOAD_DOCUMENT = "upload_document"
|
|
||||||
EDIT_FOLDER_PERMISSIONS = "edit_folder_permissions"
|
|
||||||
|
|
||||||
|
|
||||||
class ServicePermissionTypes(db.Model):
|
class ServicePermissionTypes(db.Model):
|
||||||
__tablename__ = "service_permission_types"
|
__tablename__ = "service_permission_types"
|
||||||
|
|
||||||
@@ -386,6 +361,7 @@ class Domain(db.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: Change this
|
||||||
ORGANIZATION_TYPES = ["federal", "state", "other"]
|
ORGANIZATION_TYPES = ["federal", "state", "other"]
|
||||||
|
|
||||||
|
|
||||||
@@ -811,15 +787,6 @@ class ServicePermission(db.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# MOBILE_TYPE = "mobile"
|
|
||||||
# EMAIL_TYPE = "email"
|
|
||||||
|
|
||||||
|
|
||||||
class GuestListRecipientType(Enum):
|
|
||||||
MOBILE = "mobile"
|
|
||||||
EMAIL = "email"
|
|
||||||
|
|
||||||
|
|
||||||
guest_list_recipient_types = db.Enum(GuestListRecipientType, name="recipient_type")
|
guest_list_recipient_types = db.Enum(GuestListRecipientType, name="recipient_type")
|
||||||
|
|
||||||
|
|
||||||
@@ -1007,18 +974,12 @@ class ApiKey(db.Model, Versioned):
|
|||||||
self._secret = encryption.encrypt(str(secret))
|
self._secret = encryption.encrypt(str(secret))
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: This needs to be changed
|
||||||
KEY_TYPE_NORMAL = "normal"
|
KEY_TYPE_NORMAL = "normal"
|
||||||
KEY_TYPE_TEAM = "team"
|
KEY_TYPE_TEAM = "team"
|
||||||
KEY_TYPE_TEST = "test"
|
KEY_TYPE_TEST = "test"
|
||||||
|
|
||||||
|
|
||||||
class KeyType(Enum):
|
|
||||||
# TODO: Should Key Types be rewritten to use this?
|
|
||||||
NORMAL = "normal"
|
|
||||||
TEAM = "team"
|
|
||||||
TEST = "test"
|
|
||||||
|
|
||||||
|
|
||||||
class KeyTypes(db.Model):
|
class KeyTypes(db.Model):
|
||||||
__tablename__ = "key_types"
|
__tablename__ = "key_types"
|
||||||
|
|
||||||
@@ -1373,19 +1334,6 @@ JOB_STATUS_TYPES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class JobStatusType(Enum):
|
|
||||||
# TODO: Should Job.job_status be changed to use this?
|
|
||||||
PENDING = "pending"
|
|
||||||
IN_PROGRESS = "in progress"
|
|
||||||
FINISHED = "finished"
|
|
||||||
SENDING_LIMITS_EXCEEDED = "sending limits exceeded"
|
|
||||||
SCHEDULED = "scheduled"
|
|
||||||
CANCELLED = "cancelled"
|
|
||||||
READY_TO_SEND = "ready to send"
|
|
||||||
SENT_TO_DVLA = "sent to dvla"
|
|
||||||
ERROR = "error"
|
|
||||||
|
|
||||||
|
|
||||||
class JobStatus(db.Model):
|
class JobStatus(db.Model):
|
||||||
__tablename__ = "job_status"
|
__tablename__ = "job_status"
|
||||||
|
|
||||||
@@ -1986,6 +1934,7 @@ INVITED_USER_STATUS_TYPES = [
|
|||||||
INVITE_CANCELLED,
|
INVITE_CANCELLED,
|
||||||
INVITE_EXPIRED,
|
INVITE_EXPIRED,
|
||||||
]
|
]
|
||||||
|
# TODO: Change these
|
||||||
|
|
||||||
|
|
||||||
class InviteStatusType(db.Model):
|
class InviteStatusType(db.Model):
|
||||||
@@ -2091,6 +2040,7 @@ PERMISSION_LIST = [
|
|||||||
PLATFORM_ADMIN,
|
PLATFORM_ADMIN,
|
||||||
VIEW_ACTIVITY,
|
VIEW_ACTIVITY,
|
||||||
]
|
]
|
||||||
|
# TODO: Change These
|
||||||
|
|
||||||
|
|
||||||
class Permission(db.Model):
|
class Permission(db.Model):
|
||||||
@@ -2442,16 +2392,6 @@ class WebauthnCredential(db.Model):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class AgreementType(Enum):
|
|
||||||
MOU = "MOU"
|
|
||||||
IAA = "IAA"
|
|
||||||
|
|
||||||
|
|
||||||
class AgreementStatus(Enum):
|
|
||||||
ACTIVE = "active"
|
|
||||||
EXPIRED = "expired"
|
|
||||||
|
|
||||||
|
|
||||||
class Agreement(db.Model):
|
class Agreement(db.Model):
|
||||||
__tablename__ = "agreements"
|
__tablename__ = "agreements"
|
||||||
id = db.Column(
|
id = db.Column(
|
||||||
|
|||||||
@@ -16,12 +16,8 @@ from app.dao.notifications_dao import (
|
|||||||
dao_create_notification,
|
dao_create_notification,
|
||||||
dao_delete_notifications_by_id,
|
dao_delete_notifications_by_id,
|
||||||
)
|
)
|
||||||
from app.models import (
|
from app.enums import NotificationType
|
||||||
KEY_TYPE_TEST,
|
from app.models import KEY_TYPE_TEST, NOTIFICATION_CREATED, Notification
|
||||||
NOTIFICATION_CREATED,
|
|
||||||
Notification,
|
|
||||||
NotificationType,
|
|
||||||
)
|
|
||||||
from app.v2.errors import BadRequestError
|
from app.v2.errors import BadRequestError
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,9 @@ from notifications_utils import SMS_CHAR_COUNT_LIMIT
|
|||||||
from app import api_user, authenticated_service
|
from app import api_user, authenticated_service
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames
|
||||||
from app.dao import notifications_dao
|
from app.dao import notifications_dao
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.models import KEY_TYPE_TEAM, PRIORITY, NotificationType
|
from app.models import KEY_TYPE_TEAM, PRIORITY
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
|
|||||||
@@ -15,14 +15,8 @@ from app import redis_store
|
|||||||
from app.dao.notifications_dao import dao_get_notification_count_for_service
|
from app.dao.notifications_dao import dao_get_notification_count_for_service
|
||||||
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
from app.dao.service_email_reply_to_dao import dao_get_reply_to_by_id
|
||||||
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
||||||
from app.models import (
|
from app.enums import NotificationType, ServicePermissionType, TemplateType
|
||||||
KEY_TYPE_TEAM,
|
from app.models import KEY_TYPE_TEAM, KEY_TYPE_TEST, ServicePermission
|
||||||
KEY_TYPE_TEST,
|
|
||||||
NotificationType,
|
|
||||||
ServicePermission,
|
|
||||||
ServicePermissionType,
|
|
||||||
TemplateType,
|
|
||||||
)
|
|
||||||
from app.notifications.process_notifications import create_content_for_notification
|
from app.notifications.process_notifications import create_content_for_notification
|
||||||
from app.serialised_models import SerialisedTemplate
|
from app.serialised_models import SerialisedTemplate
|
||||||
from app.service.utils import service_allowed_to_send_to
|
from app.service.utils import service_allowed_to_send_to
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ from app.dao.invited_org_user_dao import (
|
|||||||
save_invited_org_user,
|
save_invited_org_user,
|
||||||
)
|
)
|
||||||
from app.dao.templates_dao import dao_get_template_by_id
|
from app.dao.templates_dao import dao_get_template_by_id
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.models import KEY_TYPE_NORMAL, InvitedOrganizationUser, NotificationType
|
from app.models import KEY_TYPE_NORMAL, InvitedOrganizationUser
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from app import performance_platform_client
|
|||||||
from app.dao.fact_notification_status_dao import (
|
from app.dao.fact_notification_status_dao import (
|
||||||
get_total_sent_notifications_for_day_and_type,
|
get_total_sent_notifications_for_day_and_type,
|
||||||
)
|
)
|
||||||
from app.models import NotificationType
|
from app.enums import NotificationType
|
||||||
|
|
||||||
|
|
||||||
# TODO: is this obsolete? it doesn't seem to be used anywhere
|
# TODO: is this obsolete? it doesn't seem to be used anywhere
|
||||||
@@ -20,7 +20,9 @@ def send_total_notifications_sent_for_day_stats(start_time, notification_type, c
|
|||||||
|
|
||||||
# TODO: is this obsolete? it doesn't seem to be used anywhere
|
# TODO: is this obsolete? it doesn't seem to be used anywhere
|
||||||
def get_total_sent_notifications_for_day(day):
|
def get_total_sent_notifications_for_day(day):
|
||||||
email_count = get_total_sent_notifications_for_day_and_type(day, NotificationType.EMAIL)
|
email_count = get_total_sent_notifications_for_day_and_type(
|
||||||
|
day, NotificationType.EMAIL
|
||||||
|
)
|
||||||
sms_count = get_total_sent_notifications_for_day_and_type(day, NotificationType.SMS)
|
sms_count = get_total_sent_notifications_for_day_and_type(day, NotificationType.SMS)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ from app.dao.service_sms_sender_dao import dao_get_service_sms_senders_by_id
|
|||||||
from app.dao.services_dao import dao_fetch_service_by_id
|
from app.dao.services_dao import dao_fetch_service_by_id
|
||||||
from app.dao.templates_dao import dao_get_template_by_id_and_service_id
|
from app.dao.templates_dao import dao_get_template_by_id_and_service_id
|
||||||
from app.dao.users_dao import get_user_by_id
|
from app.dao.users_dao import get_user_by_id
|
||||||
from app.models import KEY_TYPE_NORMAL, PRIORITY, NotificationType
|
from app.enums import NotificationType
|
||||||
|
from app.models import KEY_TYPE_NORMAL, PRIORITY
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from app.models import NotificationType
|
from app.enums import NotificationType
|
||||||
|
|
||||||
add_service_data_retention_request = {
|
add_service_data_retention_request = {
|
||||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||||
@@ -7,7 +7,9 @@ add_service_data_retention_request = {
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"days_of_retention": {"type": "integer"},
|
"days_of_retention": {"type": "integer"},
|
||||||
"notification_type": {"enum": [NotificationType.SMS.value, NotificationType.EMAIL.value]},
|
"notification_type": {
|
||||||
|
"enum": [NotificationType.SMS.value, NotificationType.EMAIL.value]
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"required": ["days_of_retention", "notification_type"],
|
"required": ["days_of_retention", "notification_type"],
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,9 @@ from app.dao.invited_user_dao import (
|
|||||||
save_invited_user,
|
save_invited_user,
|
||||||
)
|
)
|
||||||
from app.dao.templates_dao import dao_get_template_by_id
|
from app.dao.templates_dao import dao_get_template_by_id
|
||||||
|
from app.enums import NotificationType
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.models import INVITE_PENDING, KEY_TYPE_NORMAL, NotificationType, Service
|
from app.models import INVITE_PENDING, KEY_TYPE_NORMAL, Service
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
|
|||||||
+2
-8
@@ -32,15 +32,9 @@ from app.dao.users_dao import (
|
|||||||
update_user_password,
|
update_user_password,
|
||||||
use_user_code,
|
use_user_code,
|
||||||
)
|
)
|
||||||
|
from app.enums import NotificationType, TemplateType, VerifyCodeType
|
||||||
from app.errors import InvalidRequest, register_errors
|
from app.errors import InvalidRequest, register_errors
|
||||||
from app.models import (
|
from app.models import KEY_TYPE_NORMAL, Permission, Service
|
||||||
KEY_TYPE_NORMAL,
|
|
||||||
NotificationType,
|
|
||||||
Permission,
|
|
||||||
Service,
|
|
||||||
TemplateType,
|
|
||||||
VerifyCodeType,
|
|
||||||
)
|
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue,
|
send_notification_to_queue,
|
||||||
|
|||||||
+2
-1
@@ -78,7 +78,8 @@ def get_month_from_utc_column(column):
|
|||||||
|
|
||||||
|
|
||||||
def get_public_notify_type_text(notify_type, plural=False):
|
def get_public_notify_type_text(notify_type, plural=False):
|
||||||
from app.models import UPLOAD_DOCUMENT, NotificationType
|
from app.enums import NotificationType
|
||||||
|
from app.models import UPLOAD_DOCUMENT
|
||||||
|
|
||||||
notify_type_text = notify_type
|
notify_type_text = notify_type
|
||||||
if notify_type == NotificationType.SMS:
|
if notify_type == NotificationType.SMS:
|
||||||
|
|||||||
@@ -10,13 +10,8 @@ from app import api_user, authenticated_service, document_download_client, encry
|
|||||||
from app.celery.tasks import save_api_email, save_api_sms
|
from app.celery.tasks import save_api_email, save_api_sms
|
||||||
from app.clients.document_download import DocumentDownloadError
|
from app.clients.document_download import DocumentDownloadError
|
||||||
from app.config import QueueNames
|
from app.config import QueueNames
|
||||||
from app.models import (
|
from app.enums import NotificationType
|
||||||
KEY_TYPE_NORMAL,
|
from app.models import KEY_TYPE_NORMAL, NOTIFICATION_CREATED, PRIORITY, Notification
|
||||||
NOTIFICATION_CREATED,
|
|
||||||
PRIORITY,
|
|
||||||
Notification,
|
|
||||||
NotificationType,
|
|
||||||
)
|
|
||||||
from app.notifications.process_notifications import (
|
from app.notifications.process_notifications import (
|
||||||
persist_notification,
|
persist_notification,
|
||||||
send_notification_to_queue_detached,
|
send_notification_to_queue_detached,
|
||||||
|
|||||||
Reference in New Issue
Block a user