|
| 1 | +""" |
| 2 | +
|
| 3 | +Revision ID: 0492_add_service_del_template |
| 4 | +Revises: 0491_split_deactivate_templates |
| 5 | +Create Date: 2025-10-21 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 = "0492_add_service_del_template" |
| 14 | +down_revision = "0491_split_deactivate_templates" |
| 15 | + |
| 16 | +service_deactivated_template_id = current_app.config["SERVICE_DEACTIVATED_TEMPLATE_ID"] |
| 17 | +template_ids = [service_deactivated_template_id] |
| 18 | + |
| 19 | +def upgrade(): |
| 20 | + template_insert = """ |
| 21 | + INSERT INTO templates (id, name, template_type, created_at, content, archived, service_id, subject, |
| 22 | + created_by_id, version, process_type, hidden) |
| 23 | + VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false) |
| 24 | + """ |
| 25 | + template_history_insert = """ |
| 26 | + INSERT INTO templates_history (id, name, template_type, created_at, content, archived, service_id, subject, |
| 27 | + created_by_id, version, process_type, hidden) |
| 28 | + VALUES ('{}', '{}', '{}', '{}', '{}', False, '{}', '{}', '{}', 1, '{}', false) |
| 29 | + """ |
| 30 | + |
| 31 | + service_suspended_content = "\n".join( |
| 32 | + [ |
| 33 | + "[[fr]](la version française suit)[[/fr]]", |
| 34 | + "", |
| 35 | + "[[en]]", |
| 36 | + "You or one of your team members has deleted ((service_name)).", |
| 37 | + "", |
| 38 | + "You cannot:", |
| 39 | + "- Access, manage or make changes to ((service_name)).", |
| 40 | + "- Send messages from ((service_name)).", |
| 41 | + "", |
| 42 | + "If no one on your team deleted this service, immediately [contact us](https://notification.canada.ca/en/contact).", |
| 43 | + "", |
| 44 | + "The GC Notify Team", |
| 45 | + "[[/en]]", |
| 46 | + "", |
| 47 | + "---", |
| 48 | + "", |
| 49 | + "[[fr]]", |
| 50 | + "Vous ou un membre de votre équipe avez supprimé le service ((service_name)).", |
| 51 | + "", |
| 52 | + "Vous ne pouvez plus :", |
| 53 | + "- Accéder, gérer ou apporter des changements au service ((service_name)).", |
| 54 | + "- Envoyer des messages provenant du service ((service_name)).", |
| 55 | + "", |
| 56 | + "Si vous ni votre équipe n’avez demandé de supprimer ce service, contactez-nous immédiatement.", |
| 57 | + "", |
| 58 | + "L’équipe Notification GC", |
| 59 | + "[[/fr]]", |
| 60 | + ] |
| 61 | + ) |
| 62 | + |
| 63 | + templates = [ |
| 64 | + { |
| 65 | + "id": service_deactivated_template_id, |
| 66 | + "name": "Service deleted", |
| 67 | + "subject": "((service_name)) deleted | ((service_name)) supprimé", |
| 68 | + "content": service_suspended_content, |
| 69 | + "template_type": "email", |
| 70 | + "process_type": "normal", |
| 71 | + }, |
| 72 | + ] |
| 73 | + |
| 74 | + for template in templates: |
| 75 | + op.execute( |
| 76 | + template_insert.format( |
| 77 | + template["id"], |
| 78 | + template["name"], |
| 79 | + template["template_type"], |
| 80 | + datetime.utcnow(), |
| 81 | + template["content"], |
| 82 | + current_app.config["NOTIFY_SERVICE_ID"], |
| 83 | + template["subject"], |
| 84 | + current_app.config["NOTIFY_USER_ID"], |
| 85 | + template["process_type"], |
| 86 | + ) |
| 87 | + ) |
| 88 | + |
| 89 | + op.execute( |
| 90 | + template_history_insert.format( |
| 91 | + template["id"], |
| 92 | + template["name"], |
| 93 | + template["template_type"], |
| 94 | + datetime.utcnow(), |
| 95 | + template["content"], |
| 96 | + current_app.config["NOTIFY_SERVICE_ID"], |
| 97 | + template["subject"], |
| 98 | + current_app.config["NOTIFY_USER_ID"], |
| 99 | + template["process_type"], |
| 100 | + ) |
| 101 | + ) |
| 102 | + |
| 103 | +def downgrade(): |
| 104 | + for template_id in template_ids: |
| 105 | + op.execute("DELETE FROM notifications WHERE template_id = '{}'".format(template_id)) |
| 106 | + op.execute("DELETE FROM notification_history WHERE template_id = '{}'".format(template_id)) |
| 107 | + op.execute("DELETE FROM template_redacted WHERE template_id = '{}'".format(template_id)) |
| 108 | + op.execute("DELETE FROM templates_history WHERE id = '{}'".format(template_id)) |
| 109 | + op.execute("DELETE FROM templates WHERE id = '{}'".format(template_id)) |
| 110 | + |
0 commit comments