feat: add maintenance notification email

go
codex 2 weeks ago
parent 0e9598481a
commit cbd4798f4c

@ -0,0 +1,30 @@
{extends file='layout.tpl'}
{block name='email_title'}{$notice_subject|escape:"html"} | {$config["appName"]|escape:"html"}{/block}
{block name='preheader'}{$scope_label|escape:"html"} 将进行维护,请查看受影响实例和 UTC 时间窗口。{/block}
{block name='content'}
<p style="margin:0 0 10px; color:#159da9; font-size:11px; line-height:16px; font-weight:800; letter-spacing:1.8px;">MAINTENANCE NOTICE</p>
<h1 class="email-title" style="margin:0 0 14px; color:#15243a; font-size:28px; line-height:36px; font-weight:800; letter-spacing:-.5px;">{$notice_subject|escape:"html"}</h1>
<p class="email-copy" style="margin:0 0 23px; color:#53647a; font-size:15px; line-height:25px;">{$message_text|escape:"html"|nl2br}</p>
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#f2f6f9" style="width:100%; margin:0 0 22px; background-color:#f2f6f9; border-radius:12px;">
<tr>
<td class="email-fact-cell email-fact-first" width="50%" valign="top" style="width:50%; padding:15px 14px 15px 16px; vertical-align:top;"><span style="display:block; margin-bottom:5px; color:#8494a6; font-size:10px; line-height:15px; font-weight:700;">维护范围</span><strong style="display:block; color:#2b4055; font-size:14px; line-height:20px; word-break:break-word;">{$scope_label|escape:"html"}</strong></td>
<td class="email-fact-cell" width="50%" valign="top" style="width:50%; padding:15px 16px 15px 14px; vertical-align:top;"><span style="display:block; margin-bottom:5px; color:#8494a6; font-size:10px; line-height:15px; font-weight:700;">预计影响</span><strong style="display:block; color:#2b4055; font-size:14px; line-height:20px; word-break:break-word;">{$impact_label|escape:"html"}</strong></td>
</tr>
<tr>
<td class="email-fact-cell" width="50%" valign="top" style="width:50%; padding:15px 14px 15px 16px; vertical-align:top;"><span style="display:block; margin-bottom:5px; color:#8494a6; font-size:10px; line-height:15px; font-weight:700;">开始时间(UTC)</span><strong style="display:block; color:#2b4055; font-size:13px; line-height:20px; word-break:break-word;">{$maintenance_starts_utc|escape:"html"}</strong></td>
<td class="email-fact-cell" width="50%" valign="top" style="width:50%; padding:15px 16px 15px 14px; vertical-align:top;"><span style="display:block; margin-bottom:5px; color:#8494a6; font-size:10px; line-height:15px; font-weight:700;">结束时间(UTC)</span><strong style="display:block; color:#2b4055; font-size:13px; line-height:20px; word-break:break-word;">{$maintenance_ends_utc|escape:"html"}</strong></td>
</tr>
</table>
<p style="margin:0 0 10px; color:#34445a; font-size:13px; line-height:20px; font-weight:800;">受影响的实例</p>
{foreach $instances as $instance}
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" bgcolor="#f5f8fb" style="width:100%; margin:0 0 10px; background-color:#f5f8fb; border-radius:10px;">
<tr><td class="email-panel" style="padding:14px 16px; color:#53647a; font-size:12px; line-height:20px;"><strong style="display:block; margin-bottom:3px; color:#263d53; font-size:14px; line-height:20px; word-break:break-word;">{$instance.name|escape:"html"}</strong><span style="display:block; word-break:break-all;">IPv4:{$instance.ipv4|default:'—'|escape:"html"}</span><span style="display:block; word-break:break-all;">IPv6:{$instance.ipv6|default:'—'|escape:"html"}</span></td></tr>
</table>
{/foreach}
<table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="margin:12px 0 0;"><tr><td class="email-panel" bgcolor="#fff4e7" style="padding:15px 16px; background-color:#fff4e7; border-radius:10px; color:#8d622d; font-size:12px; line-height:20px;">维护时间统一使用 UTC。实际开始和结束时间可能因现场进度略有变化,请提前保存未完成的工作。</td></tr></table>
{/block}

@ -16,6 +16,7 @@ $verify = file_get_contents($root . '/resources/email/auth/verify.tpl');
$reset = file_get_contents($root . '/resources/email/password/reset.tpl');
$renewal = file_get_contents($root . '/resources/email/cloud/invoice.tpl');
$provisioned = file_get_contents($root . '/resources/email/cloud/provision-success.tpl');
$maintenance = file_get_contents($root . '/resources/email/cloud/maintenance-notice.tpl');
$contentTemplates = [];
$templateFiles = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
$root . '/resources/email', FilesystemIterator::SKIP_DOTS
@ -42,8 +43,8 @@ foreach ($contentTemplates as $path => $template) {
$assert(str_contains($template, "{extends file='layout.tpl'}"),
'An email template does not use the shared panel theme: ' . $path);
}
$assert(count($contentTemplates) === 13,
'Expected every one of the 13 content email templates to be covered.');
$assert(count($contentTemplates) === 14,
'Expected every one of the 14 content email templates to be covered.');
foreach (['#edf3f8', '#102235', '#159da9', '#15243a', '#f5f8fb'] as $color) {
$assert(str_contains(strtolower($layout), $color),
'Shared email layout is missing a user-panel theme color: ' . $color);
@ -90,6 +91,18 @@ foreach (['root_password', 'private_key', 'sealed_credential', 'generated_passwo
$assert(!str_contains($provisioned, $secret),
'Provision success email references a forbidden secret: ' . $secret);
}
foreach (['notice_subject', 'message_text', 'scope_label', 'impact_label',
'maintenance_starts_utc', 'maintenance_ends_utc'] as $field) {
$assert(str_contains($maintenance, '{$' . $field . '|escape:"html"'),
'Maintenance email is missing escaped field: ' . $field);
}
$assert(str_contains($maintenance, '{foreach $instances as $instance}')
&& str_contains($maintenance, '{$instance.name|escape:"html"}')
&& str_contains($maintenance, '{$instance.ipv4|default:\'—\'|escape:"html"}')
&& str_contains($maintenance, '{$instance.ipv6|default:\'—\'|escape:"html"}')
&& str_contains($maintenance, '开始时间(UTC)')
&& str_contains($maintenance, '结束时间(UTC)'),
'Maintenance email lost its escaped instance list or UTC window.');
$assert(str_contains($worker,
'CloudInvoiceService::queueProvisionSucceeded(')

@ -71,6 +71,19 @@ try {
'expires_at' => '2026-10-28 18:00:00',
'instance_url' => 'https://cloud.example.test/user/cloud/instances/43?x=1&y=2',
]);
$maintenance = $render('cloud/maintenance-notice.tpl', [
'notice_subject' => '网络 <维护>',
'message_text' => "请保存 <script>alert('x')</script>\n第二行",
'scope_label' => 'HKG-A & IPv4 pool',
'impact_label' => '网络可能短时中断',
'maintenance_starts_utc' => '2026-11-06 03:00:00 UTC',
'maintenance_ends_utc' => '2026-11-06 04:00:00 UTC',
'instances' => [
['name' => 'vm-<one>', 'ipv4' => '203.0.113.10',
'ipv6' => '2001:db8::10'],
['name' => 'vm-two', 'ipv4' => '', 'ipv6' => ''],
],
]);
$user = (object) [
'user_name' => '云端 <用户>',
@ -115,7 +128,7 @@ try {
]);
$renderedEmails = [$registration, $login, $emailChange, $reset, $renewal,
$provisioned, $ticketCreated, $ticketReplied, $backup, $monitor,
$provisioned, $maintenance, $ticketCreated, $ticketReplied, $backup, $monitor,
$warning, $finance, $addressNotice, $newYear, $testMail];
foreach ($renderedEmails as $html) {
$assert(str_contains(strtolower($html), '<!doctype html>')
@ -148,6 +161,15 @@ try {
&& str_contains($provisioned, '203.0.113.43')
&& !str_contains($provisioned, 'not-for-email'),
'Provision-success email did not render safe instance details.');
$assert(str_contains($maintenance, '网络 &lt;维护&gt;')
&& str_contains($maintenance,
'&lt;script&gt;alert(&#039;x&#039;)&lt;/script&gt;')
&& !str_contains($maintenance, '<script>')
&& str_contains($maintenance, 'vm-&lt;one&gt;')
&& str_contains($maintenance, '203.0.113.10')
&& str_contains($maintenance, '2001:db8::10')
&& str_contains($maintenance, '2026-11-06 03:00:00 UTC'),
'Maintenance email did not escape content or render its UTC scope.');
$assert(str_contains($ticketCreated, '工单已提交')
&& str_contains($ticketReplied, '工单收到回复')
&& str_contains($ticketCreated, '网络 &lt;异常&gt; &amp; 排查'),

Loading…
Cancel
Save