More fixes for enums.

Signed-off-by: Cliff Hill <Clifford.hill@gsa.gov>
This commit is contained in:
Cliff Hill
2024-02-28 12:43:32 -05:00
parent f120641087
commit 661904e2cd
4 changed files with 38 additions and 28 deletions
+3 -1
View File
@@ -53,6 +53,7 @@ class PermissionType(Enum):
cls.VIEW_ACTIVITY, cls.VIEW_ACTIVITY,
) )
class ServicePermissionType(Enum): class ServicePermissionType(Enum):
EMAIL = "email" EMAIL = "email"
SMS = "sms" SMS = "sms"
@@ -72,7 +73,8 @@ class ServicePermissionType(Enum):
cls.INTERNATIONAL_SMS, cls.INTERNATIONAL_SMS,
) )
class GuestListRecipientType(Enum):
class RecipientType(Enum):
MOBILE = "mobile" MOBILE = "mobile"
EMAIL = "email" EMAIL = "email"
+29 -21
View File
@@ -23,10 +23,9 @@ from app import db, encryption
from app.enums import ( # JobStatusType,; KeyType,; UserAuthType,; TemplateProcessType, from app.enums import ( # JobStatusType,; KeyType,; UserAuthType,; TemplateProcessType,
AgreementStatus, AgreementStatus,
AgreementType, AgreementType,
GuestListRecipientType,
InvitedUserStatusType, InvitedUserStatusType,
NotificationType, NotificationType,
PermissionType, RecipientType,
ServicePermissionType, ServicePermissionType,
TemplateType, TemplateType,
VerifyCodeType, VerifyCodeType,
@@ -749,12 +748,11 @@ class ServicePermission(db.Model):
index=True, index=True,
nullable=False, nullable=False,
) )
permission = db.Enum( permission = db.Column(
PermissionType, db.Enum(ServicePermissionType, name="service_permission_types"),
name="permission_type",
index=True, index=True,
primary_key=True, primary_key=True,
nullable=False nullable=False,
) )
created_at = db.Column( created_at = db.Column(
db.DateTime, default=datetime.datetime.utcnow, nullable=False db.DateTime, default=datetime.datetime.utcnow, nullable=False
@@ -770,9 +768,6 @@ class ServicePermission(db.Model):
) )
guest_list_recipient_types = db.Enum(GuestListRecipientType, name="recipient_type")
class ServiceGuestList(db.Model): class ServiceGuestList(db.Model):
__tablename__ = "service_whitelist" __tablename__ = "service_whitelist"
@@ -781,7 +776,9 @@ class ServiceGuestList(db.Model):
UUID(as_uuid=True), db.ForeignKey("services.id"), index=True, nullable=False UUID(as_uuid=True), db.ForeignKey("services.id"), index=True, nullable=False
) )
service = db.relationship("Service", backref="guest_list") service = db.relationship("Service", backref="guest_list")
recipient_type = db.Column(guest_list_recipient_types, nullable=False) recipient_type = db.Column(
db.Enum(RecipientType, name="recipient_types"), nullable=False
)
recipient = db.Column(db.String(255), nullable=False) recipient = db.Column(db.String(255), nullable=False)
created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow) created_at = db.Column(db.DateTime, default=datetime.datetime.utcnow)
@@ -790,11 +787,11 @@ class ServiceGuestList(db.Model):
instance = cls(service_id=service_id, recipient_type=recipient_type) instance = cls(service_id=service_id, recipient_type=recipient_type)
try: try:
if recipient_type == GuestListRecipientType.MOBILE: if recipient_type == RecipientType.MOBILE:
instance.recipient = validate_phone_number( instance.recipient = validate_phone_number(
recipient, international=True recipient, international=True
) )
elif recipient_type == GuestListRecipientType.EMAIL: elif recipient_type == RecipientType.EMAIL:
instance.recipient = validate_email_address(recipient) instance.recipient = validate_email_address(recipient)
else: else:
raise ValueError("Invalid recipient type") raise ValueError("Invalid recipient type")
@@ -1252,8 +1249,6 @@ EMAIL_PROVIDERS = [SES_PROVIDER]
PROVIDERS = SMS_PROVIDERS + EMAIL_PROVIDERS PROVIDERS = SMS_PROVIDERS + EMAIL_PROVIDERS
# TODO: What about these? # TODO: What about these?
notification_types = db.Enum(NotificationType, name="notification_type")
class ProviderDetails(db.Model): class ProviderDetails(db.Model):
__tablename__ = "provider_details" __tablename__ = "provider_details"
@@ -1262,7 +1257,9 @@ class ProviderDetails(db.Model):
display_name = db.Column(db.String, nullable=False) display_name = db.Column(db.String, nullable=False)
identifier = db.Column(db.String, nullable=False) identifier = db.Column(db.String, nullable=False)
priority = db.Column(db.Integer, nullable=False) priority = db.Column(db.Integer, nullable=False)
notification_type = db.Column(notification_types, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"), nullable=False
)
active = db.Column(db.Boolean, default=False, nullable=False) active = db.Column(db.Boolean, default=False, nullable=False)
version = db.Column(db.Integer, default=1, nullable=False) version = db.Column(db.Integer, default=1, nullable=False)
updated_at = db.Column( updated_at = db.Column(
@@ -1282,7 +1279,10 @@ class ProviderDetailsHistory(db.Model, HistoryModel):
display_name = db.Column(db.String, nullable=False) display_name = db.Column(db.String, nullable=False)
identifier = db.Column(db.String, nullable=False) identifier = db.Column(db.String, nullable=False)
priority = db.Column(db.Integer, nullable=False) priority = db.Column(db.Integer, nullable=False)
notification_type = db.Column(notification_types, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"),
nullable=False,
)
active = db.Column(db.Boolean, nullable=False) active = db.Column(db.Boolean, nullable=False)
version = db.Column(db.Integer, primary_key=True, nullable=False) version = db.Column(db.Integer, primary_key=True, nullable=False)
updated_at = db.Column( updated_at = db.Column(
@@ -1533,7 +1533,7 @@ class NotificationAllTimeView(db.Model):
api_key_id = db.Column(UUID(as_uuid=True)) api_key_id = db.Column(UUID(as_uuid=True))
key_type = db.Column(db.String) key_type = db.Column(db.String)
billable_units = db.Column(db.Integer) billable_units = db.Column(db.Integer)
notification_type = db.Column(notification_types) notification_type = db.Column(db.Enum(NotificationType, name="notification_type"))
created_at = db.Column(db.DateTime) created_at = db.Column(db.DateTime)
sent_at = db.Column(db.DateTime) sent_at = db.Column(db.DateTime)
sent_by = db.Column(db.String) sent_by = db.Column(db.String)
@@ -1574,7 +1574,9 @@ class Notification(db.Model):
db.String, db.ForeignKey("key_types.name"), unique=False, nullable=False db.String, db.ForeignKey("key_types.name"), unique=False, nullable=False
) )
billable_units = db.Column(db.Integer, nullable=False, default=0) billable_units = db.Column(db.Integer, nullable=False, default=0)
notification_type = db.Column(notification_types, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"), nullable=False
)
created_at = db.Column(db.DateTime, index=True, unique=False, nullable=False) created_at = db.Column(db.DateTime, index=True, unique=False, nullable=False)
sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True) sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
sent_by = db.Column(db.String, nullable=True) sent_by = db.Column(db.String, nullable=True)
@@ -1847,7 +1849,9 @@ class NotificationHistory(db.Model, HistoryModel):
db.String, db.ForeignKey("key_types.name"), unique=False, nullable=False db.String, db.ForeignKey("key_types.name"), unique=False, nullable=False
) )
billable_units = db.Column(db.Integer, nullable=False, default=0) billable_units = db.Column(db.Integer, nullable=False, default=0)
notification_type = db.Column(notification_types, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"), nullable=False
)
created_at = db.Column(db.DateTime, unique=False, nullable=False) created_at = db.Column(db.DateTime, unique=False, nullable=False)
sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True) sent_at = db.Column(db.DateTime, index=False, unique=False, nullable=True)
sent_by = db.Column(db.String, nullable=True) sent_by = db.Column(db.String, nullable=True)
@@ -2036,7 +2040,9 @@ class Rate(db.Model):
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4) id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
valid_from = db.Column(db.DateTime, nullable=False) valid_from = db.Column(db.DateTime, nullable=False)
rate = db.Column(db.Float(asdecimal=False), nullable=False) rate = db.Column(db.Float(asdecimal=False), nullable=False)
notification_type = db.Column(notification_types, index=True, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"), index=True, nullable=False
)
def __str__(self): def __str__(self):
the_string = "{}".format(self.rate) the_string = "{}".format(self.rate)
@@ -2259,7 +2265,9 @@ class ServiceDataRetention(db.Model):
collection_class=attribute_mapped_collection("notification_type"), collection_class=attribute_mapped_collection("notification_type"),
), ),
) )
notification_type = db.Column(notification_types, nullable=False) notification_type = db.Column(
db.Enum(NotificationType, name="notification_type"), nullable=False
)
days_of_retention = db.Column(db.Integer, nullable=False) days_of_retention = db.Column(db.Integer, nullable=False)
created_at = db.Column( created_at = db.Column(
db.DateTime, nullable=False, default=datetime.datetime.utcnow db.DateTime, nullable=False, default=datetime.datetime.utcnow
+3 -3
View File
@@ -633,7 +633,7 @@ def get_detailed_services(
@service_blueprint.route("/<uuid:service_id>/guest-list", methods=["GET"]) @service_blueprint.route("/<uuid:service_id>/guest-list", methods=["GET"])
def get_guest_list(service_id): def get_guest_list(service_id):
from app.enums import GuestListRecipientType from app.enums import RecipientType
service = dao_fetch_service_by_id(service_id) service = dao_fetch_service_by_id(service_id)
@@ -645,12 +645,12 @@ def get_guest_list(service_id):
email_addresses=[ email_addresses=[
item.recipient item.recipient
for item in guest_list for item in guest_list
if item.recipient_type == GuestListRecipientType.EMAIL if item.recipient_type == RecipientType.EMAIL
], ],
phone_numbers=[ phone_numbers=[
item.recipient item.recipient
for item in guest_list for item in guest_list
if item.recipient_type == GuestListRecipientType.MOBILE if item.recipient_type == RecipientType.MOBILE
], ],
) )
+3 -3
View File
@@ -3,7 +3,7 @@ import itertools
from notifications_utils.recipients import allowed_to_send_to from notifications_utils.recipients import allowed_to_send_to
from app.dao.services_dao import dao_fetch_service_by_id from app.dao.services_dao import dao_fetch_service_by_id
from app.enums import GuestListRecipientType from app.enums import RecipientType
from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, ServiceGuestList from app.models import KEY_TYPE_NORMAL, KEY_TYPE_TEAM, KEY_TYPE_TEST, ServiceGuestList
@@ -16,10 +16,10 @@ def get_guest_list_objects(service_id, request_json):
ServiceGuestList.from_string(service_id, type, recipient) ServiceGuestList.from_string(service_id, type, recipient)
for type, recipient in ( for type, recipient in (
get_recipients_from_request( get_recipients_from_request(
request_json, "phone_numbers", GuestListRecipientType.MOBILE request_json, "phone_numbers", RecipientType.MOBILE
) )
+ get_recipients_from_request( + get_recipients_from_request(
request_json, "email_addresses", GuestListRecipientType.EMAIL request_json, "email_addresses", RecipientType.EMAIL
) )
) )
] ]