mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-14 02:09:44 -04:00
removed .value because we have StrEnum
This commit is contained in:
10
app/enums.py
10
app/enums.py
@@ -1,4 +1,4 @@
|
||||
from enum import Enum, StrEnum
|
||||
from enum import StrEnum
|
||||
|
||||
|
||||
class NotificationStatus(StrEnum):
|
||||
@@ -60,15 +60,15 @@ class AuthType(StrEnum):
|
||||
SMS_AUTH = "sms_auth"
|
||||
|
||||
|
||||
# TODO: UserRole enum
|
||||
# class UserRole(Enum):
|
||||
# TODO:
|
||||
# class UserRole(StrEnum):
|
||||
# ADMIN = "admin"
|
||||
# USER = "user"
|
||||
# GUEST = "guest"
|
||||
|
||||
|
||||
# TODO: NotificationType enum
|
||||
# class NotificationType(Enum):
|
||||
# TODO:
|
||||
# class NotificationType(StrEnum):
|
||||
# EMAIL = "email"
|
||||
# SMS = "sms"
|
||||
# PUSH = "push"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from flask import abort, render_template, request, url_for
|
||||
|
||||
from app import current_service, job_api_client
|
||||
from app.enums import NotificationStatus
|
||||
from app.formatters import get_time_left
|
||||
from app.main import main
|
||||
from app.utils.pagination import (
|
||||
@@ -78,8 +79,7 @@ def handle_pagination(jobs, service_id, page):
|
||||
return prev_page, next_page, pagination
|
||||
|
||||
|
||||
JOB_STATUS_DELIVERED = "delivered"
|
||||
JOB_STATUS_FAILED = "failed"
|
||||
|
||||
|
||||
|
||||
def get_job_statistics(job, status):
|
||||
@@ -109,8 +109,8 @@ def create_job_dict_entry(job):
|
||||
"activity_time": activity_time,
|
||||
"created_by": job.get("created_by"),
|
||||
"template_name": job.get("template_name"),
|
||||
"delivered_count": get_job_statistics(job, JOB_STATUS_DELIVERED),
|
||||
"failed_count": get_job_statistics(job, JOB_STATUS_FAILED),
|
||||
"delivered_count": get_job_statistics(job, NotificationStatus.DELIVERED),
|
||||
"failed_count": get_job_statistics(job, NotificationStatus.FAILED),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ def get_job_partials(job):
|
||||
counts=_get_job_counts(job),
|
||||
status=filter_args["status"],
|
||||
notifications_deleted=(
|
||||
job.status == JobStatus.FINISHED.value and not notifications["notifications"]
|
||||
job.status == JobStatus.FINISHED and not notifications["notifications"]
|
||||
),
|
||||
)
|
||||
service_data_retention_days = current_service.get_days_of_retention(
|
||||
|
||||
@@ -398,10 +398,10 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
|
||||
if replace:
|
||||
existing = current_service.get_email_reply_to_address(replace)
|
||||
existing_is_default = existing["is_default"]
|
||||
verification_status = VerificationStatus.PENDING.value
|
||||
verification_status = VerificationStatus.PENDING
|
||||
is_default = True if (request.args.get("is_default", False) == "True") else False
|
||||
if notification["status"] in DELIVERED_STATUSES:
|
||||
verification_status = VerificationStatus.SUCCESS.value
|
||||
verification_status = VerificationStatus.SUCCESS
|
||||
if notification["to"] not in [
|
||||
i["email_address"] for i in current_service.email_reply_to_addresses
|
||||
]:
|
||||
@@ -442,7 +442,7 @@ def get_service_verify_reply_to_address_partials(service_id, notification_id):
|
||||
first_email_address=first_email_address,
|
||||
replace=replace,
|
||||
),
|
||||
"stop": 0 if verification_status == VerificationStatus.PENDING.value else 1,
|
||||
"stop": 0 if verification_status == VerificationStatus.PENDING else 1,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -567,7 +567,7 @@ class InvitedUser(JSONModel):
|
||||
# current_app.logger.warning(
|
||||
# f"Checking invited user {self.id} for permissions: {permissions}"
|
||||
# )
|
||||
if self.status == InvitedUserStatus.CANCELLED.value:
|
||||
if self.status == InvitedUserStatus.CANCELLED:
|
||||
return False
|
||||
return set(self.permissions) > set(permissions)
|
||||
|
||||
@@ -575,7 +575,7 @@ class InvitedUser(JSONModel):
|
||||
# current_app.logger.warn(
|
||||
# f"Checking invited user {self.id} for permission: {permission} on service {service_id}"
|
||||
# )
|
||||
if self.status == InvitedUserStatus.CANCELLED.value:
|
||||
if self.status == InvitedUserStatus.CANCELLED:
|
||||
return False
|
||||
return self.service == service_id and permission in self.permissions
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ class InviteApiClient(NotifyAdminAPIClient):
|
||||
return self.get(url=f"/invite/service/check/{token}")["data"]
|
||||
|
||||
def cancel_invited_user(self, service_id, invited_user_id):
|
||||
data = {"status": InvitedUserStatus.CANCELLED.value}
|
||||
data = {"status": InvitedUserStatus.CANCELLED}
|
||||
data = _attach_current_user(data)
|
||||
self.post(url=f"/service/{service_id}/invite/{invited_user_id}", data=data)
|
||||
|
||||
@@ -132,7 +132,7 @@ class InviteApiClient(NotifyAdminAPIClient):
|
||||
@cache.delete("service-{service_id}")
|
||||
@cache.delete("user-{invited_user_id}")
|
||||
def accept_invite(self, service_id, invited_user_id):
|
||||
data = {"status": InvitedUserStatus.ACCEPTED.value}
|
||||
data = {"status": InvitedUserStatus.ACCEPTED}
|
||||
self.post(url=f"/service/{service_id}/invite/{invited_user_id}", data=data)
|
||||
|
||||
|
||||
|
||||
@@ -14,16 +14,16 @@ from notifications_python_client.errors import HTTPError
|
||||
@status.route("/_status", methods=["GET"])
|
||||
def show_status():
|
||||
if request.args.get("elb", None) or request.args.get("simple", None):
|
||||
return jsonify(status=HealthStatus.OK.value), 200
|
||||
return jsonify(status=HealthStatus.OK), 200
|
||||
else:
|
||||
try:
|
||||
api_status = status_api_client.get_status()
|
||||
except HTTPError as err:
|
||||
current_app.logger.exception("API failed to respond")
|
||||
return jsonify(status=HealthStatus.ERROR.value, message=str(err.message)), 500
|
||||
return jsonify(status=HealthStatus.ERROR, message=str(err.message)), 500
|
||||
return (
|
||||
jsonify(
|
||||
status=HealthStatus.OK.value,
|
||||
status=HealthStatus.OK,
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
@@ -61,10 +61,10 @@ def show_redis_status():
|
||||
)
|
||||
except HTTPError as err:
|
||||
current_app.logger.exception("API failed to respond")
|
||||
return jsonify(status=HealthStatus.ERROR.value, message=str(err.message)), 500
|
||||
return jsonify(status=HealthStatus.ERROR, message=str(err.message)), 500
|
||||
return (
|
||||
jsonify(
|
||||
status=HealthStatus.OK.value,
|
||||
status=HealthStatus.OK,
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
@@ -77,7 +77,7 @@ def show_redis_status():
|
||||
)
|
||||
return (
|
||||
jsonify(
|
||||
status=f"{HealthStatus.ERROR.value}: {err}",
|
||||
status=f"{HealthStatus.ERROR}: {err}",
|
||||
api=api_status,
|
||||
git_commit=version.__git_commit__,
|
||||
build_time=version.__time__,
|
||||
|
||||
Reference in New Issue
Block a user