From 410f5e291cff878373fcb9988541f4db44f8dee1 Mon Sep 17 00:00:00 2001 From: Andrew Leith Date: Wed, 13 Dec 2023 14:26:45 +0000 Subject: [PATCH 1/2] chore(heartbeat): add heartbeat templates --- app/config.py | 6 + .../versions/0442_add_heartbeat_templates.py | 114 ++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 migrations/versions/0442_add_heartbeat_templates.py diff --git a/app/config.py b/app/config.py index 4f61ebb494..10ec7f5a6f 100644 --- a/app/config.py +++ b/app/config.py @@ -339,6 +339,12 @@ class Config(object): REACHED_DAILY_EMAIL_LIMIT_TEMPLATE_ID = "ee036547-e51b-49f1-862b-10ea982cfceb" DAILY_EMAIL_LIMIT_UPDATED_TEMPLATE_ID = "97dade64-ea8d-460f-8a34-900b74ee5eb0" APIKEY_REVOKE_TEMPLATE_ID = "a0a4e7b8-8a6a-4eaa-9f4e-9c3a5b2dbcf3" + HEARTBEAT_TEMPLATE_EMAIL_LOW = "73079cb9-c169-44ea-8cf4-8d397711cc9d" + HEARTBEAT_TEMPLATE_EMAIL_MEDIUM = "c75c4539-3014-4c4c-96b5-94d326758a74" + HEARTBEAT_TEMPLATE_EMAIL_HIGH = "276da251-3103-49f3-9054-cbf6b5d74411" + HEARTBEAT_TEMPLATE_SMS_LOW = "ab3a603b-d602-46ea-8c83-e05cb280b950" + HEARTBEAT_TEMPLATE_SMS_MEDIUM = "a48b54ce-40f6-4e4a-abe8-1e2fa389455b" + HEARTBEAT_TEMPLATE_SMS_HIGH = "4969a9e9-ddfd-476e-8b93-6231e6f1be4a" # Allowed service IDs able to send HTML through their templates. ALLOW_HTML_SERVICE_IDS: List[str] = [id.strip() for id in os.getenv("ALLOW_HTML_SERVICE_IDS", "").split(",")] diff --git a/migrations/versions/0442_add_heartbeat_templates.py b/migrations/versions/0442_add_heartbeat_templates.py new file mode 100644 index 0000000000..a32e833ff7 --- /dev/null +++ b/migrations/versions/0442_add_heartbeat_templates.py @@ -0,0 +1,114 @@ +""" +Revision ID: 0442_add_heartbeat_templates +Revises: 0441_add_apikey_revoke_email +Create Date: 2022-09-21 00:00:00 +""" +from datetime import datetime + +from alembic import op +from flask import current_app + +revision = "0442_add_heartbeat_templates" +down_revision = "0441_add_apikey_revoke_email" + +templates = [ + { + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_LOW"], + "name": "HEARTBEAT_TEMPLATE_EMAIL_LOW", + "template_type": "email", + "content": "HEARTBEAT_TEMPLATE_EMAIL_LOW", + "subject": "HEARTBEAT_TEMPLATE_EMAIL_LOW", + "process_type": "bulk", + }, + { + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_MEDIUM"], + "name": "HEARTBEAT_TEMPLATE_EMAIL_MEDIUM", + "template_type": "email", + "content": "HEARTBEAT_TEMPLATE_EMAIL_MEDIUM", + "subject": "HEARTBEAT_TEMPLATE_EMAIL_MEDIUM", + "process_type": "normal", + }, + { + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_HIGH"], + "name": "HEARTBEAT_TEMPLATE_EMAIL_HIGH", + "template_type": "email", + "content": "HEARTBEAT_TEMPLATE_EMAIL_HIGH", + "subject": "HEARTBEAT_TEMPLATE_EMAIL_HIGH", + "process_type": "priority", + }, + { + "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_LOW"], + "name": "HEARTBEAT_TEMPLATE_SMS_LOW", + "template_type": "sms", + "content": "HEARTBEAT_TEMPLATE_SMS_LOW", + "subject": "HEARTBEAT_TEMPLATE_SMS_LOW", + "process_type": "bulk", + }, + { + "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_MEDIUM"], + "name": "HEARTBEAT_TEMPLATE_SMS_MEDIUM", + "template_type": "sms", + "content": "HEARTBEAT_TEMPLATE_SMS_MEDIUM", + "subject": "HEARTBEAT_TEMPLATE_SMS_MEDIUM", + "process_type": "normal", + }, + { + "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_HIGH"], + "name": "HEARTBEAT_TEMPLATE_SMS_HIGH", + "template_type": "sms", + "content": "HEARTBEAT_TEMPLATE_SMS_HIGH", + "subject": "HEARTBEAT_TEMPLATE_SMS_HIGH", + "process_type": "priority", + }, +] + + +def upgrade(): + template_insert = """ + INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, + created_by_id, version, process_type, hidden) + VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', False) + """ + template_history_insert = """ + INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, + created_by_id, version, process_type, hidden) + VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', False) + """ + + for template in templates: + op.execute( + template_insert.format( + template["id"], + template["name"], + template["template_type"], + datetime.utcnow(), + template["content"], + current_app.config["NOTIFY_SERVICE_ID"], + template["subject"], + current_app.config["NOTIFY_USER_ID"], + template["process_type"], + ) + ) + + op.execute( + template_history_insert.format( + template["id"], + template["name"], + template["template_type"], + datetime.utcnow(), + template["content"], + current_app.config["NOTIFY_SERVICE_ID"], + template["subject"], + current_app.config["NOTIFY_USER_ID"], + template["process_type"], + ) + ) + +def downgrade(): + TEMPLATE_IDS = ",".join(["'{}'".format(x["id"]) for x in templates]) + + op.execute("DELETE FROM notifications WHERE template_id in ({})".format(TEMPLATE_IDS)) + op.execute("DELETE FROM notification_history WHERE template_id in ({})".format(TEMPLATE_IDS)) + op.execute("DELETE FROM template_redacted WHERE template_id in ({})".format(TEMPLATE_IDS)) + op.execute("DELETE FROM templates_history WHERE id in ({})".format(TEMPLATE_IDS)) + op.execute("DELETE FROM templates WHERE id in ({})".format(TEMPLATE_IDS)) From 6c6abf04bfa1918a81f8e868e9ac2dc7539ee130 Mon Sep 17 00:00:00 2001 From: Andrew Leith Date: Wed, 13 Dec 2023 14:36:41 +0000 Subject: [PATCH 2/2] chore: formatting --- migrations/versions/0442_add_heartbeat_templates.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/migrations/versions/0442_add_heartbeat_templates.py b/migrations/versions/0442_add_heartbeat_templates.py index a32e833ff7..4923cf9396 100644 --- a/migrations/versions/0442_add_heartbeat_templates.py +++ b/migrations/versions/0442_add_heartbeat_templates.py @@ -13,7 +13,7 @@ templates = [ { - "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_LOW"], + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_LOW"], "name": "HEARTBEAT_TEMPLATE_EMAIL_LOW", "template_type": "email", "content": "HEARTBEAT_TEMPLATE_EMAIL_LOW", @@ -21,7 +21,7 @@ "process_type": "bulk", }, { - "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_MEDIUM"], + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_MEDIUM"], "name": "HEARTBEAT_TEMPLATE_EMAIL_MEDIUM", "template_type": "email", "content": "HEARTBEAT_TEMPLATE_EMAIL_MEDIUM", @@ -29,7 +29,7 @@ "process_type": "normal", }, { - "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_HIGH"], + "id": current_app.config["HEARTBEAT_TEMPLATE_EMAIL_HIGH"], "name": "HEARTBEAT_TEMPLATE_EMAIL_HIGH", "template_type": "email", "content": "HEARTBEAT_TEMPLATE_EMAIL_HIGH", @@ -37,7 +37,7 @@ "process_type": "priority", }, { - "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_LOW"], + "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_LOW"], "name": "HEARTBEAT_TEMPLATE_SMS_LOW", "template_type": "sms", "content": "HEARTBEAT_TEMPLATE_SMS_LOW", @@ -45,7 +45,7 @@ "process_type": "bulk", }, { - "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_MEDIUM"], + "id": current_app.config["HEARTBEAT_TEMPLATE_SMS_MEDIUM"], "name": "HEARTBEAT_TEMPLATE_SMS_MEDIUM", "template_type": "sms", "content": "HEARTBEAT_TEMPLATE_SMS_MEDIUM", @@ -104,9 +104,10 @@ def upgrade(): ) ) + def downgrade(): TEMPLATE_IDS = ",".join(["'{}'".format(x["id"]) for x in templates]) - + op.execute("DELETE FROM notifications WHERE template_id in ({})".format(TEMPLATE_IDS)) op.execute("DELETE FROM notification_history WHERE template_id in ({})".format(TEMPLATE_IDS)) op.execute("DELETE FROM template_redacted WHERE template_id in ({})".format(TEMPLATE_IDS))