Skip to content

Commit

Permalink
chore(heartbeat): add heartbeat templates (#2063)
Browse files Browse the repository at this point in the history
* chore(heartbeat): add heartbeat templates

* chore: formatting
  • Loading branch information
andrewleith authored Dec 13, 2023
1 parent c8f8d5c commit f5cf93e
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(",")]
Expand Down
115 changes: 115 additions & 0 deletions migrations/versions/0442_add_heartbeat_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""
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))

0 comments on commit f5cf93e

Please sign in to comment.