|
| 1 | +""" |
| 2 | +
|
| 3 | +Revision ID: 0447_update_verify_code_template |
| 4 | +Revises: 0446_add_alt_text |
| 5 | +Create Date: 2023-10-05 00:00:00 |
| 6 | +
|
| 7 | +""" |
| 8 | +from datetime import datetime |
| 9 | + |
| 10 | +from alembic import op |
| 11 | +from flask import current_app |
| 12 | + |
| 13 | +revision = "0447_update_verify_code_template" |
| 14 | +down_revision = "0446_add_alt_text" |
| 15 | + |
| 16 | +near_content = "\n".join( |
| 17 | + [ |
| 18 | + "[[en]]", |
| 19 | + "Hi ((name)),", |
| 20 | + "", |
| 21 | + "Here is your security code to log in to GC Notify:", |
| 22 | + "", |
| 23 | + "^ **((verify_code))**", |
| 24 | + "[[/en]]", |
| 25 | + "", |
| 26 | + "---", |
| 27 | + "", |
| 28 | + "[[fr]]", |
| 29 | + "Bonjour ((name)),", |
| 30 | + "", |
| 31 | + "Voici votre code de sécurité pour vous connecter à Notification GC:", |
| 32 | + "", |
| 33 | + "^ **((verify_code))**", |
| 34 | + "[[/fr]]", |
| 35 | + ] |
| 36 | +) |
| 37 | + |
| 38 | + |
| 39 | +templates = [ |
| 40 | + { |
| 41 | + "id": current_app.config["EMAIL_2FA_TEMPLATE_ID"], |
| 42 | + "template_type": "email", |
| 43 | + "subject": "Sign in | Connectez-vous", |
| 44 | + "content": near_content, |
| 45 | + "process_type": "priority", |
| 46 | + }, |
| 47 | +] |
| 48 | + |
| 49 | + |
| 50 | +def upgrade(): |
| 51 | + conn = op.get_bind() |
| 52 | + |
| 53 | + for template in templates: |
| 54 | + current_version = conn.execute("select version from templates where id='{}'".format(template["id"])).fetchone() |
| 55 | + name = conn.execute("select name from templates where id='{}'".format(template["id"])).fetchone() |
| 56 | + template["version"] = current_version[0] + 1 |
| 57 | + template["name"] = name[0] |
| 58 | + |
| 59 | + template_update = """ |
| 60 | + UPDATE templates SET content = '{}', subject = '{}', version = '{}', updated_at = '{}' |
| 61 | + WHERE id = '{}' |
| 62 | + """ |
| 63 | + template_history_insert = """ |
| 64 | + INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, |
| 65 | + created_by_id, version, process_type, hidden) |
| 66 | + VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', {}, '{}', false) |
| 67 | + """ |
| 68 | + |
| 69 | + for template in templates: |
| 70 | + op.execute( |
| 71 | + template_update.format( |
| 72 | + template["content"], |
| 73 | + template["subject"], |
| 74 | + template["version"], |
| 75 | + datetime.utcnow(), |
| 76 | + template["id"], |
| 77 | + ) |
| 78 | + ) |
| 79 | + |
| 80 | + op.execute( |
| 81 | + template_history_insert.format( |
| 82 | + template["id"], |
| 83 | + template["name"], |
| 84 | + template["template_type"], |
| 85 | + datetime.utcnow(), |
| 86 | + template["content"], |
| 87 | + current_app.config["NOTIFY_SERVICE_ID"], |
| 88 | + template["subject"], |
| 89 | + current_app.config["NOTIFY_USER_ID"], |
| 90 | + template["version"], |
| 91 | + template["process_type"], |
| 92 | + ) |
| 93 | + ) |
| 94 | + |
| 95 | + |
| 96 | +def downgrade(): |
| 97 | + pass |
0 commit comments