mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-06 03:13:42 -05:00
Using StrEnum to drop .value
This commit is contained in:
18
app/enums.py
18
app/enums.py
@@ -1,7 +1,7 @@
|
||||
from enum import Enum
|
||||
from enum import Enum, StrEnum
|
||||
|
||||
|
||||
class NotificationStatus(Enum):
|
||||
class NotificationStatus(StrEnum):
|
||||
CREATED = "created"
|
||||
PENDING = "pending"
|
||||
SENDING = "sending"
|
||||
@@ -17,13 +17,13 @@ class NotificationStatus(Enum):
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class ApiKeyType(Enum):
|
||||
class ApiKeyType(StrEnum):
|
||||
NORMAL = "normal"
|
||||
TEAM = "team"
|
||||
TEST = "test"
|
||||
|
||||
|
||||
class JobStatus(Enum):
|
||||
class JobStatus(StrEnum):
|
||||
PENDING = "pending"
|
||||
IN_PROGRESS = "in progress"
|
||||
FINISHED = "finished"
|
||||
@@ -34,28 +34,28 @@ class JobStatus(Enum):
|
||||
SENT_TO_DVLA = "sent to dvla"
|
||||
|
||||
|
||||
class InvitedUserStatus(Enum):
|
||||
class InvitedUserStatus(StrEnum):
|
||||
ACCEPTED = "accepted"
|
||||
CANCELLED = "cancelled"
|
||||
EXPIRED = "expired"
|
||||
|
||||
|
||||
class InvitedOrgUserStatus(Enum):
|
||||
class InvitedOrgUserStatus(StrEnum):
|
||||
ACCEPTED = "accepted"
|
||||
CANCELLED = "cancelled"
|
||||
|
||||
|
||||
class VerificationStatus(Enum):
|
||||
class VerificationStatus(StrEnum):
|
||||
PENDING = "pending"
|
||||
SUCCESS = "success"
|
||||
|
||||
|
||||
class HealthStatus(Enum):
|
||||
class HealthStatus(StrEnum):
|
||||
OK = "ok"
|
||||
ERROR = "error"
|
||||
|
||||
|
||||
class AuthType(Enum):
|
||||
class AuthType(StrEnum):
|
||||
EMAIL_AUTH = "email_auth"
|
||||
SMS_AUTH = "sms_auth"
|
||||
|
||||
|
||||
@@ -30,14 +30,14 @@ def accept_invite(token):
|
||||
|
||||
abort(403)
|
||||
|
||||
if invited_user.status == InvitedUserStatus.CANCELLED.value:
|
||||
if invited_user.status == InvitedUserStatus.CANCELLED:
|
||||
service = Service.from_id(invited_user.service)
|
||||
return render_template(
|
||||
"views/cancelled-invitation.html",
|
||||
from_user=invited_user.from_user.name,
|
||||
service_name=service.name,
|
||||
)
|
||||
if invited_user.status == InvitedUserStatus.ACCEPTED.value:
|
||||
if invited_user.status == InvitedUserStatus.ACCEPTED:
|
||||
session.pop("invited_user_id", None)
|
||||
service = Service.from_id(invited_user.service)
|
||||
return redirect(
|
||||
@@ -105,7 +105,7 @@ def accept_org_invite(token):
|
||||
|
||||
abort(403)
|
||||
|
||||
if invited_org_user.status == InvitedOrgUserStatus.CANCELLED.value:
|
||||
if invited_org_user.status == InvitedOrgUserStatus.CANCELLED:
|
||||
organization = Organization.from_id(invited_org_user.organization)
|
||||
return render_template(
|
||||
"views/cancelled-invitation.html",
|
||||
@@ -113,7 +113,7 @@ def accept_org_invite(token):
|
||||
organization_name=organization.name,
|
||||
)
|
||||
|
||||
if invited_org_user.status == InvitedOrgUserStatus.ACCEPTED.value:
|
||||
if invited_org_user.status == InvitedOrgUserStatus.ACCEPTED:
|
||||
session.pop("invited_org_user_id", None)
|
||||
return redirect(
|
||||
url_for("main.organization_dashboard", org_id=invited_org_user.organization)
|
||||
|
||||
@@ -255,14 +255,14 @@ def get_invited_user_email_address(invited_user_id):
|
||||
def invited_user_accept_invite(invited_user_id):
|
||||
invited_user = InvitedUser.by_id(invited_user_id)
|
||||
|
||||
if invited_user.status == InvitedUserStatus.EXPIRED.value:
|
||||
if invited_user.status == InvitedUserStatus.EXPIRED:
|
||||
current_app.logger.error("User invitation has expired")
|
||||
flash(
|
||||
"Your invitation has expired; please contact the person who invited you for additional help."
|
||||
)
|
||||
abort(401)
|
||||
|
||||
if invited_user.status == InvitedUserStatus.CANCELLED.value:
|
||||
if invited_user.status == InvitedUserStatus.CANCELLED:
|
||||
current_app.logger.error("User invitation has been cancelled")
|
||||
flash(
|
||||
"Your invitation is no longer valid; please contact the person who invited you for additional help."
|
||||
|
||||
@@ -33,11 +33,11 @@ class Job(JSONModel):
|
||||
|
||||
@property
|
||||
def cancelled(self):
|
||||
return self.status == JobStatus.CANCELLED.value
|
||||
return self.status == JobStatus.CANCELLED
|
||||
|
||||
@property
|
||||
def scheduled(self):
|
||||
return self.status == JobStatus.SCHEDULED.value
|
||||
return self.status == JobStatus.SCHEDULED
|
||||
|
||||
@property
|
||||
def scheduled_for(self):
|
||||
@@ -63,17 +63,17 @@ class Job(JSONModel):
|
||||
@property
|
||||
def notifications_delivered(self):
|
||||
return self._aggregate_statistics(
|
||||
NotificationStatus.DELIVERED.value, NotificationStatus.SENT.value
|
||||
NotificationStatus.DELIVERED, NotificationStatus.SENT
|
||||
)
|
||||
|
||||
@property
|
||||
def notifications_failed(self):
|
||||
return self._aggregate_statistics(
|
||||
NotificationStatus.FAILED.value,
|
||||
NotificationStatus.TECHNICAL_FAILURE.value,
|
||||
NotificationStatus.TEMPORARY_FAILURE.value,
|
||||
NotificationStatus.PERMANENT_FAILURE.value,
|
||||
NotificationStatus.CANCELLED.value,
|
||||
NotificationStatus.FAILED,
|
||||
NotificationStatus.TECHNICAL_FAILURE,
|
||||
NotificationStatus.TEMPORARY_FAILURE,
|
||||
NotificationStatus.PERMANENT_FAILURE,
|
||||
NotificationStatus.CANCELLED,
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -98,7 +98,7 @@ class Job(JSONModel):
|
||||
|
||||
@property
|
||||
def still_processing(self):
|
||||
return self.status != JobStatus.FINISHED.value or self.percentage_complete < 100
|
||||
return self.status != JobStatus.FINISHED or self.percentage_complete < 100
|
||||
|
||||
@cached_property
|
||||
def finished_processing(self):
|
||||
|
||||
@@ -2,9 +2,9 @@ from app.notify_client import NotifyAdminAPIClient, _attach_current_user
|
||||
from app.enums import ApiKeyType
|
||||
|
||||
# must match key types in notifications-api/app/models.py
|
||||
KEY_TYPE_NORMAL = ApiKeyType.NORMAL.value
|
||||
KEY_TYPE_TEAM = ApiKeyType.TEAM.value
|
||||
KEY_TYPE_TEST = ApiKeyType.TEST.value
|
||||
KEY_TYPE_NORMAL = ApiKeyType.NORMAL
|
||||
KEY_TYPE_TEAM = ApiKeyType.TEAM
|
||||
KEY_TYPE_TEST = ApiKeyType.TEST
|
||||
|
||||
|
||||
class ApiKeyApiClient(NotifyAdminAPIClient):
|
||||
|
||||
@@ -9,17 +9,17 @@ from app.enums import JobStatus
|
||||
|
||||
class JobApiClient(NotifyAdminAPIClient):
|
||||
JOB_STATUSES = {
|
||||
JobStatus.SCHEDULED.value,
|
||||
JobStatus.PENDING.value,
|
||||
JobStatus.IN_PROGRESS.value,
|
||||
JobStatus.FINISHED.value,
|
||||
JobStatus.CANCELLED.value,
|
||||
JobStatus.SENDING_LIMITS_EXCEEDED.value,
|
||||
JobStatus.READY_TO_SEND.value,
|
||||
JobStatus.SENT_TO_DVLA.value,
|
||||
JobStatus.SCHEDULED,
|
||||
JobStatus.PENDING,
|
||||
JobStatus.IN_PROGRESS,
|
||||
JobStatus.FINISHED,
|
||||
JobStatus.CANCELLED,
|
||||
JobStatus.SENDING_LIMITS_EXCEEDED,
|
||||
JobStatus.READY_TO_SEND,
|
||||
JobStatus.SENT_TO_DVLA,
|
||||
}
|
||||
SCHEDULED_JOB_STATUS = JobStatus.SCHEDULED.value
|
||||
CANCELLED_JOB_STATUS = JobStatus.CANCELLED.value
|
||||
SCHEDULED_JOB_STATUS = JobStatus.SCHEDULED
|
||||
CANCELLED_JOB_STATUS = JobStatus.CANCELLED
|
||||
NON_CANCELLED_JOB_STATUSES = JOB_STATUSES - {CANCELLED_JOB_STATUS}
|
||||
NON_SCHEDULED_JOB_STATUSES = JOB_STATUSES - {
|
||||
SCHEDULED_JOB_STATUS,
|
||||
|
||||
Reference in New Issue
Block a user