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