|
| 1 | +""" |
| 2 | +
|
| 3 | +Revision ID: 0444_pentest_whs_003 |
| 4 | +Revises: 0443_add_spryng_provider |
| 5 | +Create Date: 2024-08-09 11:14:31.873491 |
| 6 | +
|
| 7 | +""" |
| 8 | + |
| 9 | +from alembic import op |
| 10 | +from flask import current_app |
| 11 | + |
| 12 | +# revision identifiers, used by Alembic. |
| 13 | +revision = "0444_pentest_whs_003" |
| 14 | +down_revision = "0443_add_spryng_provider" |
| 15 | + |
| 16 | + |
| 17 | +update = """UPDATE {} |
| 18 | + SET content = '{}', created_at = current_timestamp |
| 19 | + WHERE id = '{}' |
| 20 | + """ |
| 21 | + |
| 22 | +template_redacted_update = """UPDATE template_redacted |
| 23 | + SET updated_at = current_timestamp, updated_by_id = '{}' |
| 24 | + WHERE template_id = '{}' |
| 25 | + """ |
| 26 | + |
| 27 | + |
| 28 | +def upgrade(): |
| 29 | + templates = [ |
| 30 | + # Create new account |
| 31 | + { |
| 32 | + "id": "afd325cd-c83e-4b0b-8426-7acb9c0aa62b", |
| 33 | + "name": "NotifyNL email verification code", |
| 34 | + "type": "email", |
| 35 | + "subject": "Confirm NotifyNL registration", |
| 36 | + "content": """Hi,\n\n |
| 37 | + To complete your registration for NotifyNL please click the link below\n\n((url)) |
| 38 | + """, |
| 39 | + }, |
| 40 | + # Invitation to collaborate - service |
| 41 | + { |
| 42 | + "id": "b24bf0fa-dd64-4105-867c-4ed529e12df3", |
| 43 | + "name": "NotifyNL service invitation email", |
| 44 | + "type": "email", |
| 45 | + "subject": "You have been invited to collaborate on ((service_name)) on NotifyNL", |
| 46 | + "content": """You have been invited to collaborate on ((service_name)) on NotifyNL.\n\n |
| 47 | + NotifyNL makes it easy to keep people updated by helping you send text messages and emails.\n\n |
| 48 | + Click this link to create an account on NotifyNL:\n((url))\n\n |
| 49 | + This invitation will stop working at midnight tomorrow. This is to keep ((service_name)) secure. |
| 50 | + """, |
| 51 | + }, |
| 52 | + # Invitation to collaborate - organisation |
| 53 | + { |
| 54 | + "id": "dfd254da-39d1-468f-bd0d-2c9e017c13a6", |
| 55 | + "name": "NotifyNL organisation invitation email", |
| 56 | + "type": "email", |
| 57 | + "subject": "You have been invited to collaborate on ((organisation_name)) on NotifyNL", |
| 58 | + "content": """You have been invited to collaborate on ((organisation_name)) on NotifyNL.\n\n |
| 59 | + NotifyNL makes it easy to keep people updated by helping you send text messages and emails.\n\n |
| 60 | + Click this link to create an account on NotifyNL:\n((url))\n\n |
| 61 | + This invitation will stop working at midnight tomorrow. This is to keep ((organisation_name)) secure. |
| 62 | + """, |
| 63 | + }, |
| 64 | + # Password reset |
| 65 | + { |
| 66 | + "id": "4cc48b09-62d0-473f-8514-3023b306a0fb", |
| 67 | + "name": "NotifyNL password reset email", |
| 68 | + "type": "email", |
| 69 | + "subject": "Reset your NotifyNL password", |
| 70 | + "content": """Hi,\n\n |
| 71 | + We received a request to reset your password on NotifyNL.\n\n |
| 72 | + If you didn''t request this email, you can ignore it – |
| 73 | + your password has not been changed.\n\n |
| 74 | + To reset your password, click this link:\n\n |
| 75 | + ((url)) |
| 76 | + """, |
| 77 | + }, |
| 78 | + # Change email address |
| 79 | + { |
| 80 | + "id": "9eefb5bf-f1fb-46ce-9079-691260b0af9b", |
| 81 | + "name": "Confirm new email address", |
| 82 | + "type": "email", |
| 83 | + "subject": "Confirm new email address for NotifyNL", |
| 84 | + "content": """Hi,\n\n |
| 85 | + Click this link to confirm your new email address:\n\n((url)) |
| 86 | + """, |
| 87 | + }, |
| 88 | + # Email verification code |
| 89 | + { |
| 90 | + "id": "320a5f19-600f-451e-9646-11206c69828d", |
| 91 | + "name": "NotifyNL email verify code", |
| 92 | + "type": "email", |
| 93 | + "subject": "Sign in to NotifyNL", |
| 94 | + "content": """Hi,\n\n |
| 95 | + To sign in to NotifyNL please open this link: ((url)) |
| 96 | + """, |
| 97 | + }, |
| 98 | + # Broadcast invitation email |
| 99 | + { |
| 100 | + "id": "86761e21-b39c-43e1-a06b-a3340bc2bc7a", |
| 101 | + "name": "NotifyNL broadcast invitation email", |
| 102 | + "type": "email", |
| 103 | + "subject": "You have been invited to join ((service_name)) on NotifyNL", |
| 104 | + "content": """You have been invited to join ((service_name)) on NotifyNL.\n\n |
| 105 | + In an emergency, use Notify to broadcast an alert, warning the public about an imminent risk to life.\n\n |
| 106 | + Use this link to join the team: ((url))\n\n |
| 107 | + This invitation will stop working at midnight tomorrow. This is to keep ((service_name)) secure. |
| 108 | + """, |
| 109 | + }, |
| 110 | + # Service is live |
| 111 | + { |
| 112 | + "id": "ec92ba79-222b-46f1-944a-79b3c072234d", |
| 113 | + "name": "Automated \"You''re now live\" message on NotifyNL", |
| 114 | + "type": "email", |
| 115 | + "subject": "((service name)) is now live on NotifyNL", |
| 116 | + "content": """Hi,\n\n((service name)) is now live on NotifyNL.""", |
| 117 | + }, |
| 118 | + ] |
| 119 | + |
| 120 | + op.get_bind() |
| 121 | + |
| 122 | + for template in templates: |
| 123 | + for table_name in ["templates", "templates_history"]: |
| 124 | + op.execute( |
| 125 | + update.format( |
| 126 | + table_name, |
| 127 | + template["content"], |
| 128 | + template["id"], |
| 129 | + ) |
| 130 | + ) |
| 131 | + |
| 132 | + op.execute(template_redacted_update.format(current_app.config["NOTIFY_USER_ID"], template["id"])) |
| 133 | + |
| 134 | + |
| 135 | +def downgrade(): |
| 136 | + old_templates = [ |
| 137 | + # Create new account |
| 138 | + { |
| 139 | + "id": "afd325cd-c83e-4b0b-8426-7acb9c0aa62b", |
| 140 | + "name": "NotifyNL email verification code", |
| 141 | + "type": "email", |
| 142 | + "subject": "Confirm NotifyNL registration", |
| 143 | + "content": """Hi ((name)),\n\n |
| 144 | + To complete your registration for NotifyNL please click the link below\n\n((url)) |
| 145 | + """, |
| 146 | + }, |
| 147 | + # Invitation to collaborate - service |
| 148 | + { |
| 149 | + "id": "b24bf0fa-dd64-4105-867c-4ed529e12df3", |
| 150 | + "name": "NotifyNL service invitation email", |
| 151 | + "type": "email", |
| 152 | + "subject": "((user_name)) has invited you to collaborate on ((service_name)) on NotifyNL", |
| 153 | + "content": """((user_name)) has invited you to collaborate on ((service_name)) on NotifyNL.\n\n |
| 154 | + NotifyNL makes it easy to keep people updated by helping you send text messages and emails.\n\n |
| 155 | + Click this link to create an account on NotifyNL:\n((url))\n\n |
| 156 | + This invitation will stop working at midnight tomorrow. This is to keep ((service_name)) secure. |
| 157 | + """, |
| 158 | + }, |
| 159 | + # Invitation to collaborate - organisation |
| 160 | + { |
| 161 | + "id": "dfd254da-39d1-468f-bd0d-2c9e017c13a6", |
| 162 | + "name": "NotifyNL organisation invitation email", |
| 163 | + "type": "email", |
| 164 | + "subject": "((user_name)) has invited you to collaborate on ((organisation_name)) on NotifyNL", |
| 165 | + "content": """((user_name)) has invited you to collaborate on ((organisation_name)) on NotifyNL.\n\n |
| 166 | + NotifyNL makes it easy to keep people updated by helping you send text messages and emails.\n\n |
| 167 | + Click this link to create an account on NotifyNL:\n((url))\n\n |
| 168 | + This invitation will stop working at midnight tomorrow. This is to keep ((organisation_name)) secure. |
| 169 | + """, |
| 170 | + }, |
| 171 | + # Password reset |
| 172 | + { |
| 173 | + "id": "4cc48b09-62d0-473f-8514-3023b306a0fb", |
| 174 | + "name": "NotifyNL password reset email", |
| 175 | + "type": "email", |
| 176 | + "subject": "Reset your NotifyNL password", |
| 177 | + "content": """Hi ((user_name)),\n\n |
| 178 | + We received a request to reset your password on NotifyNL.\n\n |
| 179 | + If you didn''t request this email, you can ignore it – |
| 180 | + your password has not been changed.\n\n |
| 181 | + To reset your password, click this link:\n\n |
| 182 | + ((url)) |
| 183 | + """, |
| 184 | + }, |
| 185 | + # Change email address |
| 186 | + { |
| 187 | + "id": "9eefb5bf-f1fb-46ce-9079-691260b0af9b", |
| 188 | + "name": "Confirm new email address", |
| 189 | + "type": "email", |
| 190 | + "subject": "Confirm new email address for NotifyNL", |
| 191 | + "content": """Hi ((name)),\n\n |
| 192 | + Click this link to confirm your new email address:\n\n((url)) |
| 193 | + """, |
| 194 | + }, |
| 195 | + # Email verification code |
| 196 | + { |
| 197 | + "id": "320a5f19-600f-451e-9646-11206c69828d", |
| 198 | + "name": "NotifyNL email verify code", |
| 199 | + "type": "email", |
| 200 | + "subject": "Sign in to NotifyNL", |
| 201 | + "content": """Hi ((name)),\n\n |
| 202 | + To sign in to NotifyNL please open this link: ((url)) |
| 203 | + """, |
| 204 | + }, |
| 205 | + # Broadcast invitation email |
| 206 | + { |
| 207 | + "id": "86761e21-b39c-43e1-a06b-a3340bc2bc7a", |
| 208 | + "name": "NotifyNL broadcast invitation email", |
| 209 | + "type": "email", |
| 210 | + "subject": "((user_name)) has invited you to join ((service_name)) on NotifyNL", |
| 211 | + "content": """((user_name)) has invited you to join ((service_name)) on NotifyNL.\n\n |
| 212 | + In an emergency, use Notify to broadcast an alert, warning the public about an imminent risk to life.\n\n |
| 213 | + Use this link to join the team: ((url))\n\n |
| 214 | + This invitation will stop working at midnight tomorrow. This is to keep ((service_name)) secure. |
| 215 | + """, |
| 216 | + }, |
| 217 | + # Service is live |
| 218 | + { |
| 219 | + "id": "ec92ba79-222b-46f1-944a-79b3c072234d", |
| 220 | + "name": "Automated \"You''re now live\" message on NotifyNL", |
| 221 | + "type": "email", |
| 222 | + "subject": "((service name)) is now live on NotifyNL", |
| 223 | + "content": """Hi ((name)),\n\n((service name)) is now live on NotifyNL.""", |
| 224 | + }, |
| 225 | + ] |
| 226 | + |
| 227 | + op.get_bind() |
| 228 | + |
| 229 | + for template in old_templates: |
| 230 | + for table_name in ["templates", "templates_history"]: |
| 231 | + op.execute( |
| 232 | + update.format( |
| 233 | + table_name, |
| 234 | + template["content"], |
| 235 | + template["id"], |
| 236 | + ) |
| 237 | + ) |
| 238 | + |
| 239 | + op.execute(template_redacted_update.format(current_app.config["NOTIFY_USER_ID"], template["id"])) |
0 commit comments