2017-11-03 14:25:58 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
Revision ID: 0134_add_email_2fa_template
|
|
|
|
|
|
Revises: 0133_set_services_sms_prefix
|
|
|
|
|
|
Create Date: 2017-11-03 13:52:59.715203
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2024-04-01 15:12:33 -07:00
|
|
|
|
|
2017-11-03 14:25:58 +00:00
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from alembic import op
|
|
|
|
|
|
from flask import current_app
|
2023-07-18 09:02:40 -07:00
|
|
|
|
from sqlalchemy import text
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
2024-06-14 16:01:04 -06:00
|
|
|
|
from app.utils import utc_now
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
revision = "0134_add_email_2fa_template"
|
|
|
|
|
|
down_revision = "0133_set_services_sms_prefix"
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
template_id = "299726d2-dba6-42b8-8209-30e1d66ea164"
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upgrade():
|
|
|
|
|
|
template_insert = """
|
|
|
|
|
|
INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
|
2023-07-18 09:02:40 -07:00
|
|
|
|
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1,:process_type)
|
2017-11-03 14:25:58 +00:00
|
|
|
|
"""
|
|
|
|
|
|
template_history_insert = """
|
|
|
|
|
|
INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, created_by_id, version, process_type)
|
2023-07-18 09:02:40 -07:00
|
|
|
|
VALUES (:template_id, :template_name, :template_type, :time_now, :content, False, :notify_service_id, :subject, :user_id, 1,:process_type)
|
2017-11-03 14:25:58 +00:00
|
|
|
|
"""
|
|
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
template_content = "\n".join(
|
|
|
|
|
|
[
|
|
|
|
|
|
"Hi ((name)),",
|
|
|
|
|
|
"",
|
|
|
|
|
|
"To sign in to GOV.UK Notify please open this link:",
|
|
|
|
|
|
"((url))",
|
|
|
|
|
|
]
|
|
|
|
|
|
)
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
template_name = "Notify email verify code"
|
2023-08-29 14:54:30 -07:00
|
|
|
|
template_subject = "Sign in to GOV.UK Notify"
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
2023-07-18 09:02:40 -07:00
|
|
|
|
input_params = {
|
2023-08-29 14:54:30 -07:00
|
|
|
|
"template_id": template_id,
|
|
|
|
|
|
"template_name": template_name,
|
|
|
|
|
|
"template_type": "email",
|
2024-06-14 16:01:04 -06:00
|
|
|
|
"time_now": utc_now(),
|
2023-08-29 14:54:30 -07:00
|
|
|
|
"content": template_content,
|
|
|
|
|
|
"notify_service_id": current_app.config["NOTIFY_SERVICE_ID"],
|
|
|
|
|
|
"subject": template_subject,
|
|
|
|
|
|
"user_id": current_app.config["NOTIFY_USER_ID"],
|
|
|
|
|
|
"process_type": "normal",
|
2023-07-18 09:02:40 -07:00
|
|
|
|
}
|
|
|
|
|
|
conn = op.get_bind()
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
conn.execute(text(template_history_insert), input_params)
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
2023-08-29 14:54:30 -07:00
|
|
|
|
conn.execute(text(template_insert), input_params)
|
2019-06-26 18:33:24 +01:00
|
|
|
|
|
2017-11-03 14:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
def downgrade():
|
2023-07-18 09:02:40 -07:00
|
|
|
|
conn = op.get_bind()
|
2023-08-29 14:54:30 -07:00
|
|
|
|
input_params = {"template_id": template_id}
|
|
|
|
|
|
conn.execute(
|
|
|
|
|
|
text("DELETE FROM notifications WHERE template_id = :template_id"), input_params
|
|
|
|
|
|
)
|
|
|
|
|
|
conn.execute(
|
|
|
|
|
|
text("DELETE FROM notification_history WHERE template_id = :template_id"),
|
|
|
|
|
|
input_params,
|
|
|
|
|
|
)
|
|
|
|
|
|
conn.execute(
|
|
|
|
|
|
text("DELETE FROM template_redacted WHERE template_id = :template_id"),
|
|
|
|
|
|
input_params,
|
|
|
|
|
|
)
|
|
|
|
|
|
conn.execute(
|
|
|
|
|
|
text("DELETE FROM templates_history WHERE id = :template_id"), input_params
|
|
|
|
|
|
)
|
2023-07-18 09:02:40 -07:00
|
|
|
|
conn.execute(text("DELETE FROM templates WHERE id = :template_id"), input_params)
|