feat: add maintenance notice admin page
parent
7a76d3a9e3
commit
1871059fad
@ -0,0 +1,269 @@
|
||||
const root = document.querySelector('[data-admin-maintenance-notices]');
|
||||
|
||||
if (root) {
|
||||
const byId = id => document.getElementById(id);
|
||||
const element = (tag, className = '', text = '') => {
|
||||
const node = document.createElement(tag);
|
||||
if (className) node.className = className;
|
||||
if (text !== '') node.textContent = text;
|
||||
return node;
|
||||
};
|
||||
const parseBootstrap = () => {
|
||||
try { return JSON.parse(byId('admin-maintenance-notice-bootstrap')?.textContent || 'null'); }
|
||||
catch (error) { return null; }
|
||||
};
|
||||
const bootstrap = parseBootstrap() || {};
|
||||
const canManage = root.dataset.canManage === '1' && bootstrap.can_manage === true;
|
||||
const runtime = window.VenixAdminRequestRuntime.create({});
|
||||
const state = {
|
||||
catalog: bootstrap.catalog || { hosts: [], pools: [] },
|
||||
page: bootstrap.page || { page: 1, per_page: 20, total: 0, items: [] },
|
||||
prefill: bootstrap.prefill || {},
|
||||
preview: null,
|
||||
mutationLocked: false,
|
||||
detail: null,
|
||||
};
|
||||
const labels = {
|
||||
impacts: {
|
||||
network_interruption: '网络可能中断', instance_restart: '实例需要重启',
|
||||
service_interruption: '服务可能中断', no_interruption: '预计不中断',
|
||||
},
|
||||
statuses: {
|
||||
scheduled: '待发送', sending: '发送中', completed: '已完成',
|
||||
attention: '需核对', cancelled: '已取消',
|
||||
},
|
||||
};
|
||||
|
||||
function notify(message, error = false) {
|
||||
const node = byId('maintenance-notice-status');
|
||||
node.textContent = message;
|
||||
node.classList.toggle('is-error', error);
|
||||
node.classList.toggle('is-success', !error);
|
||||
}
|
||||
function timestamp(value) {
|
||||
const milliseconds = new Date(value).getTime();
|
||||
return Number.isFinite(milliseconds) ? Math.floor(milliseconds / 1000) : 0;
|
||||
}
|
||||
function utc(value) {
|
||||
const parsed = timestamp(value);
|
||||
return parsed > 0 ? new Date(parsed * 1000).toISOString().replace('.000Z', ' UTC') : '未选择';
|
||||
}
|
||||
function localDateTime(value) {
|
||||
const date = new Date(value * 1000);
|
||||
return Number.isFinite(date.getTime()) ? date.toLocaleString() : '—';
|
||||
}
|
||||
function localInputValue(date) {
|
||||
const shifted = new Date(date.getTime() - date.getTimezoneOffset() * 60000);
|
||||
return shifted.toISOString().slice(0, 16);
|
||||
}
|
||||
function scopeLabel(scope) {
|
||||
if (!scope || typeof scope !== 'object') return '范围未知';
|
||||
return `${scope.type === 'host' ? '计算节点' : '公网地址池'} · ${scope.label || scope.id || '未知'}`;
|
||||
}
|
||||
function badge(status) {
|
||||
const tone = status === 'completed' ? 'success'
|
||||
: status === 'attention' ? 'danger'
|
||||
: status === 'cancelled' ? 'secondary' : 'primary';
|
||||
return element('span', `badge text-bg-${tone}`, labels.statuses[status] || status || '未知');
|
||||
}
|
||||
function updateUtcConfirmation() {
|
||||
byId('maintenance-utc-confirmation').textContent = `邮件所示 UTC 时间:维护开始 ${utc(byId('maintenance-starts').value)};维护结束 ${utc(byId('maintenance-ends').value)};计划发送 ${utc(byId('maintenance-scheduled').value)}。`;
|
||||
}
|
||||
function invalidatePreview() {
|
||||
state.preview = null;
|
||||
byId('maintenance-preview-card').hidden = true;
|
||||
byId('maintenance-preview-instances').replaceChildren();
|
||||
byId('maintenance-schedule').disabled = true;
|
||||
}
|
||||
function targetOptions() {
|
||||
const type = byId('maintenance-scope-type').value;
|
||||
const target = byId('maintenance-scope-id');
|
||||
const selected = String(state.prefill.scope_type === type ? state.prefill.scope_id || '' : '');
|
||||
target.replaceChildren();
|
||||
const rows = type === 'host' ? state.catalog.hosts || [] : state.catalog.pools || [];
|
||||
for (const row of rows) {
|
||||
const label = type === 'host'
|
||||
? `${row.name}${row.region ? ` · ${row.region}` : ''}${row.enabled ? '' : ' · 已停用'}`
|
||||
: `${row.host_name} · IPv${row.address_family} · ${row.name} · ${row.cidr}${row.state === 'active' ? '' : ` · ${row.state}`}`;
|
||||
target.append(new Option(label, String(row.id)));
|
||||
}
|
||||
if (selected && rows.some(row => String(row.id) === selected)) target.value = selected;
|
||||
state.prefill = {};
|
||||
invalidatePreview();
|
||||
}
|
||||
function validateTimes() {
|
||||
const starts = timestamp(byId('maintenance-starts').value);
|
||||
const ends = timestamp(byId('maintenance-ends').value);
|
||||
const scheduled = timestamp(byId('maintenance-scheduled').value);
|
||||
if (!starts || !ends || !scheduled || ends <= starts) throw new Error('请选择有效的维护窗口和发送时间。');
|
||||
return { maintenance_starts_at: starts, maintenance_ends_at: ends, scheduled_at: scheduled };
|
||||
}
|
||||
function scopeRequest() {
|
||||
const scopeId = Number(byId('maintenance-scope-id').value);
|
||||
if (!Number.isInteger(scopeId) || scopeId < 1) throw new Error('请选择通知范围。');
|
||||
return { scope_type: byId('maintenance-scope-type').value, scope_id: scopeId };
|
||||
}
|
||||
function setMutationBusy(busy) {
|
||||
for (const id of ['maintenance-preview', 'maintenance-schedule']) {
|
||||
const node = byId(id);
|
||||
node.disabled = busy || state.mutationLocked || !canManage || (id === 'maintenance-schedule' && !state.preview);
|
||||
}
|
||||
}
|
||||
function renderPreview(payload) {
|
||||
state.preview = payload;
|
||||
const card = byId('maintenance-preview-card');
|
||||
card.hidden = false;
|
||||
byId('maintenance-preview-summary').textContent = `${scopeLabel(payload.scope)} · ${Number(payload.instance_count || 0)} 台实例 · ${Number(payload.recipient_count || 0)} 位可投递用户${Number(payload.skipped_count || 0) ? ` · ${Number(payload.skipped_count)} 位跳过` : ''}`;
|
||||
const body = byId('maintenance-preview-instances');
|
||||
body.replaceChildren();
|
||||
for (const instance of payload.instances || []) {
|
||||
const row = document.createElement('tr');
|
||||
for (const value of [instance.name || `实例 #${instance.id}`, `#${instance.host_id}`, instance.ipv4 || '—', instance.ipv6 || '—']) row.append(element('td', '', String(value)));
|
||||
body.append(row);
|
||||
}
|
||||
byId('maintenance-schedule').disabled = !canManage || state.mutationLocked;
|
||||
}
|
||||
function renderList() {
|
||||
const body = byId('maintenance-notice-list');
|
||||
body.replaceChildren();
|
||||
const items = state.page.items || [];
|
||||
if (!items.length) {
|
||||
const row = document.createElement('tr');
|
||||
const cell = element('td', 'text-muted text-center py-4', '当前没有维护通知。');
|
||||
cell.colSpan = 5; row.append(cell); body.append(row);
|
||||
}
|
||||
for (const item of items) {
|
||||
const row = document.createElement('tr');
|
||||
const subject = element('td');
|
||||
subject.append(element('strong', 'd-block', item.subject || '未命名通知'), element('span', 'text-muted fs-13', scopeLabel(item.scope)));
|
||||
const windowCell = element('td');
|
||||
windowCell.append(element('span', 'd-block', localDateTime(item.maintenance_starts_at)), element('span', 'text-muted fs-13', `至 ${localDateTime(item.maintenance_ends_at)}`));
|
||||
const audience = element('td', '', `${Number(item.instance_count || 0)} 台 / ${Number(item.recipient_count || 0)} 位`);
|
||||
const status = element('td'); status.append(badge(item.status));
|
||||
const action = element('td');
|
||||
const detail = element('button', 'btn btn-sm btn-light', '查看详情');
|
||||
detail.type = 'button'; detail.addEventListener('click', () => { void openDetail(item.notice_key); });
|
||||
action.append(detail);
|
||||
row.append(subject, windowCell, audience, status, action); body.append(row);
|
||||
}
|
||||
const totalPages = Math.max(1, Math.ceil(Number(state.page.total || 0) / Number(state.page.per_page || 20)));
|
||||
const nav = byId('maintenance-pagination');
|
||||
nav.hidden = Number(state.page.total || 0) <= Number(state.page.per_page || 20);
|
||||
byId('maintenance-page-label').textContent = `第 ${state.page.page || 1} / ${totalPages} 页 · 共 ${state.page.total || 0} 条`;
|
||||
byId('maintenance-previous').disabled = Number(state.page.page || 1) <= 1;
|
||||
byId('maintenance-next').disabled = Number(state.page.page || 1) >= totalPages;
|
||||
}
|
||||
async function loadPage(page = 1) {
|
||||
const params = new URLSearchParams({ page: String(page), per_page: '20' });
|
||||
const status = byId('maintenance-status-filter').value;
|
||||
if (status) params.set('status', status);
|
||||
notify('正在刷新维护通知…');
|
||||
try {
|
||||
state.page = await runtime.read(`/api/v1/admin/maintenance-notices?${params.toString()}`);
|
||||
renderList(); notify(`已读取 ${Number(state.page.total || 0)} 条通知。`);
|
||||
} catch (error) { notify(error.message || '维护通知读取失败。', true); }
|
||||
}
|
||||
function appendFact(list, label, value) {
|
||||
list.append(element('dt', '', label), element('dd', '', String(value ?? '—')));
|
||||
}
|
||||
function detailTable(title, columns, rows) {
|
||||
const section = element('section', 'mt-4');
|
||||
section.append(element('h3', 'h6', title));
|
||||
const wrap = element('div', 'table-responsive');
|
||||
const table = element('table', 'table table-sm align-middle');
|
||||
const head = document.createElement('thead'); const headRow = document.createElement('tr');
|
||||
for (const column of columns) headRow.append(element('th', '', column));
|
||||
head.append(headRow); const body = document.createElement('tbody');
|
||||
for (const values of rows) { const row = document.createElement('tr'); for (const value of values) row.append(element('td', '', String(value ?? '—'))); body.append(row); }
|
||||
table.append(head, body); wrap.append(table); section.append(wrap); return section;
|
||||
}
|
||||
function renderDetail(detail) {
|
||||
state.detail = detail;
|
||||
byId('maintenance-detail-title').textContent = detail.subject || '维护通知';
|
||||
byId('maintenance-detail-state').textContent = `${labels.statuses[detail.status] || detail.status} · ${scopeLabel(detail.scope)}`;
|
||||
const body = byId('maintenance-detail-body'); body.replaceChildren();
|
||||
const facts = element('dl', 'admin-instance-details');
|
||||
appendFact(facts, '影响类型', labels.impacts[detail.impact] || detail.impact);
|
||||
appendFact(facts, '计划发送', localDateTime(detail.scheduled_at));
|
||||
appendFact(facts, '维护开始', localDateTime(detail.maintenance_starts_at));
|
||||
appendFact(facts, '维护结束', localDateTime(detail.maintenance_ends_at));
|
||||
appendFact(facts, '受众', `${detail.instance_count} 台实例 / ${detail.recipient_count} 位用户`);
|
||||
body.append(facts, element('h3', 'h6 mt-4', '通知正文'), element('p', 'text-break', detail.message_text || '—'));
|
||||
body.append(detailTable('受影响实例', ['实例', 'IPv4', 'IPv6'], (detail.instances || []).map(item => [item.instance_name, item.ipv4 || '—', item.ipv6 || '—'])));
|
||||
body.append(detailTable('投递结果', ['用户', '邮箱', '状态'], (detail.recipients || []).map(item => [`#${item.user_id}`, item.email, item.status])));
|
||||
const cancel = byId('maintenance-detail-cancel');
|
||||
cancel.hidden = !canManage || !['scheduled', 'sending'].includes(detail.status);
|
||||
cancel.disabled = state.mutationLocked;
|
||||
}
|
||||
async function openDetail(key) {
|
||||
const dialog = byId('maintenance-detail');
|
||||
if (!dialog.open) dialog.showModal();
|
||||
byId('maintenance-detail-state').textContent = '正在读取通知详情…';
|
||||
byId('maintenance-detail-body').replaceChildren();
|
||||
byId('maintenance-detail-cancel').hidden = true;
|
||||
try { renderDetail(await runtime.read(`/api/v1/admin/maintenance-notices/${encodeURIComponent(key)}`)); }
|
||||
catch (error) { byId('maintenance-detail-state').textContent = error.message || '详情读取失败。'; }
|
||||
}
|
||||
function uncertain(error) {
|
||||
if (!error?.mutationMayHaveApplied) return false;
|
||||
state.mutationLocked = true;
|
||||
setMutationBusy(false);
|
||||
notify('操作结果待核对,请刷新页面确认;当前页面不会再次提交。', true);
|
||||
return true;
|
||||
}
|
||||
|
||||
byId('maintenance-scope-type').value = state.prefill.scope_type || 'host';
|
||||
targetOptions();
|
||||
const now = Date.now();
|
||||
byId('maintenance-scheduled').value = localInputValue(new Date(now + 5 * 60000));
|
||||
byId('maintenance-starts').value = localInputValue(new Date(now + 60 * 60000));
|
||||
byId('maintenance-ends').value = localInputValue(new Date(now + 2 * 60 * 60000));
|
||||
updateUtcConfirmation(); renderList(); setMutationBusy(false);
|
||||
|
||||
byId('maintenance-scope-type').addEventListener('change', targetOptions);
|
||||
byId('maintenance-scope-id').addEventListener('change', invalidatePreview);
|
||||
for (const id of ['maintenance-starts', 'maintenance-ends', 'maintenance-scheduled']) byId(id).addEventListener('change', () => { updateUtcConfirmation(); invalidatePreview(); });
|
||||
byId('maintenance-preview').addEventListener('click', async () => {
|
||||
if (!canManage || state.mutationLocked) return;
|
||||
setMutationBusy(true); notify('正在核对受影响实例与用户…');
|
||||
try {
|
||||
renderPreview(await runtime.mutate('/api/v1/admin/maintenance-notices/preview', { method: 'POST', response: 'json', body: scopeRequest() }));
|
||||
notify('受众预览已冻结,请核对后调度发送。');
|
||||
} catch (error) { if (!uncertain(error)) notify(error.message || '受众预览失败。', true); }
|
||||
finally { setMutationBusy(false); }
|
||||
});
|
||||
byId('maintenance-notice-form').addEventListener('submit', async event => {
|
||||
event.preventDefault();
|
||||
if (!canManage || state.mutationLocked || !state.preview) return;
|
||||
setMutationBusy(true); notify('正在创建维护通知…');
|
||||
try {
|
||||
const payload = {
|
||||
...scopeRequest(), ...validateTimes(),
|
||||
subject: byId('maintenance-subject').value.trim(),
|
||||
message_text: byId('maintenance-message').value.trim(),
|
||||
impact: byId('maintenance-impact').value,
|
||||
audience_digest: state.preview.audience_digest,
|
||||
};
|
||||
const detail = await runtime.mutate('/api/v1/admin/maintenance-notices', { method: 'POST', response: 'json', body: payload });
|
||||
invalidatePreview(); notify(`维护通知“${detail.subject}”已创建。`); await loadPage(1);
|
||||
} catch (error) { if (!uncertain(error)) notify(error.message || '维护通知创建失败。', true); }
|
||||
finally { setMutationBusy(false); }
|
||||
});
|
||||
byId('maintenance-detail-cancel').addEventListener('click', async () => {
|
||||
if (!canManage || state.mutationLocked || !state.detail) return;
|
||||
const confirmed = await window.VenixAdminDangerDialog.confirm({ tone: 'warning', title: '取消尚未发送的维护邮件', message: '只会取消尚未被发送进程领取的邮件;正在发送的记录仍会继续收敛。', confirmText: '确认取消' });
|
||||
if (!confirmed) return;
|
||||
const button = byId('maintenance-detail-cancel'); button.disabled = true;
|
||||
try {
|
||||
renderDetail(await runtime.mutate(`/api/v1/admin/maintenance-notices/${encodeURIComponent(state.detail.notice_key)}/cancel`, { method: 'POST', response: 'json', body: {} }));
|
||||
notify('尚未领取的维护邮件已取消。'); await loadPage(state.page.page || 1);
|
||||
} catch (error) { if (!uncertain(error)) notify(error.message || '取消失败。', true); }
|
||||
finally { button.disabled = state.mutationLocked; }
|
||||
});
|
||||
byId('maintenance-detail-close').addEventListener('click', () => byId('maintenance-detail').close());
|
||||
byId('maintenance-detail').addEventListener('cancel', event => { event.preventDefault(); byId('maintenance-detail').close(); });
|
||||
byId('maintenance-notice-refresh').addEventListener('click', () => { void loadPage(state.page.page || 1); });
|
||||
byId('maintenance-status-filter').addEventListener('change', () => { void loadPage(1); });
|
||||
byId('maintenance-previous').addEventListener('click', () => { void loadPage(Math.max(1, Number(state.page.page || 1) - 1)); });
|
||||
byId('maintenance-next').addEventListener('click', () => { void loadPage(Number(state.page.page || 1) + 1); });
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
{assign var=admin_title value='维护通知'}
|
||||
{assign var=admin_active value='maintenance-notices'}
|
||||
{include file='admin/static_header.tpl'}
|
||||
<link rel="stylesheet" href="/cloud/admin.css?v={$venix_asset_version}">
|
||||
<main data-admin-maintenance-notices data-can-manage="{if $admin_can_manage|default:false}1{else}0{/if}">
|
||||
<div class="py-3 d-flex align-items-sm-center flex-sm-row flex-column gap-3">
|
||||
<div class="flex-grow-1">
|
||||
<h1 class="fs-20 fw-semibold mb-1">维护通知</h1>
|
||||
<p class="text-muted mb-0">按计算节点或公网地址池冻结受影响实例,同一用户只发送一封邮件。通知时间统一以 UTC 写入邮件。</p>
|
||||
</div>
|
||||
<div class="admin-checkout-actions">
|
||||
<span class="admin-config-status {if $maintenance_notice_error|default:''}is-error{else}is-success{/if}" id="maintenance-notice-status" role="status" aria-live="polite">{if $maintenance_notice_error|default:''}{$maintenance_notice_error|escape}{else}已读取 {$maintenance_notice_page.page.total|default:0|escape} 条通知{/if}</span>
|
||||
<button class="btn btn-light" id="maintenance-notice-refresh" type="button"><i class="mdi mdi-refresh me-1" aria-hidden="true"></i>刷新</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{if !$admin_can_manage|default:false}
|
||||
<p class="alert alert-info">当前管理员为只读模式,可查看已脱敏的通知记录,不能预览受众、创建或取消通知。</p>
|
||||
{/if}
|
||||
|
||||
<section class="card mb-3" aria-labelledby="maintenance-compose-title">
|
||||
<div class="card-header">
|
||||
<h2 class="h5 card-title mb-1" id="maintenance-compose-title">创建维护通知</h2>
|
||||
<p class="text-muted fs-13 mb-0">先预览并确认冻结受众,再调度发送。受众变化后原预览摘要会失效,服务端会拒绝创建。</p>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form id="maintenance-notice-form">
|
||||
<fieldset {if !$admin_can_manage|default:false}disabled{/if}>
|
||||
<div class="row g-3">
|
||||
<label class="col-lg-4" for="maintenance-scope-type"><span class="form-label d-block">通知范围</span><select class="form-select" id="maintenance-scope-type" required><option value="host">计算节点</option><option value="public_ip_pool">公网地址池</option></select></label>
|
||||
<label class="col-lg-8" for="maintenance-scope-id"><span class="form-label d-block">具体范围</span><select class="form-select" id="maintenance-scope-id" required></select></label>
|
||||
<label class="col-lg-8" for="maintenance-subject"><span class="form-label d-block">邮件主题</span><input class="form-control" id="maintenance-subject" maxlength="180" required autocomplete="off" placeholder="例如:香港区域网络维护通知"></label>
|
||||
<label class="col-lg-4" for="maintenance-impact"><span class="form-label d-block">影响类型</span><select class="form-select" id="maintenance-impact" required><option value="network_interruption">网络可能中断</option><option value="instance_restart">实例需要重启</option><option value="service_interruption">服务可能中断</option><option value="no_interruption">预计不中断</option></select></label>
|
||||
<label class="col-12" for="maintenance-message"><span class="form-label d-block">通知正文</span><textarea class="form-control" id="maintenance-message" rows="5" maxlength="5000" required placeholder="说明维护原因、可能影响和用户需要注意的事项。"></textarea></label>
|
||||
<label class="col-lg-4" for="maintenance-starts"><span class="form-label d-block">维护开始(浏览器本地时间)</span><input class="form-control" id="maintenance-starts" type="datetime-local" required></label>
|
||||
<label class="col-lg-4" for="maintenance-ends"><span class="form-label d-block">维护结束(浏览器本地时间)</span><input class="form-control" id="maintenance-ends" type="datetime-local" required></label>
|
||||
<label class="col-lg-4" for="maintenance-scheduled"><span class="form-label d-block">计划发送(浏览器本地时间)</span><input class="form-control" id="maintenance-scheduled" type="datetime-local" required></label>
|
||||
</div>
|
||||
<p class="alert alert-light border mt-3 mb-0" id="maintenance-utc-confirmation">请选择维护窗口和发送时间。</p>
|
||||
<div class="admin-form-actions mt-3"><button class="btn btn-light" id="maintenance-preview" type="button"><i class="mdi mdi-account-search-outline me-1"></i>预览受众</button><button class="btn btn-primary" id="maintenance-schedule" type="submit" disabled><i class="mdi mdi-send-clock-outline me-1"></i>确认并调度发送</button></div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="card mb-3" id="maintenance-preview-card" aria-labelledby="maintenance-preview-title" hidden>
|
||||
<div class="card-header"><h2 class="h5 card-title mb-1" id="maintenance-preview-title">受众预览</h2><p class="text-muted fs-13 mb-0" id="maintenance-preview-summary"></p></div>
|
||||
<div class="card-body"><div class="table-responsive"><table class="table table-hover align-middle mb-0"><thead><tr><th>实例</th><th>宿主机</th><th>公网 IPv4</th><th>公网 IPv6</th></tr></thead><tbody id="maintenance-preview-instances"></tbody></table></div></div>
|
||||
</section>
|
||||
|
||||
<section class="card" aria-labelledby="maintenance-list-title">
|
||||
<div class="card-header d-flex justify-content-between align-items-center gap-3 flex-wrap">
|
||||
<div><h2 class="h5 card-title mb-1" id="maintenance-list-title">通知记录</h2><p class="text-muted fs-13 mb-0">邮件已交给服务商不代表用户一定收件;效果未知的投递不会自动重发。</p></div>
|
||||
<label class="d-flex align-items-center gap-2 mb-0" for="maintenance-status-filter"><span class="text-muted text-nowrap">状态</span><select class="form-select" id="maintenance-status-filter"><option value="">全部</option><option value="scheduled">待发送</option><option value="sending">发送中</option><option value="completed">已完成</option><option value="attention">需核对</option><option value="cancelled">已取消</option></select></label>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive"><table class="table table-hover align-middle mb-0"><thead><tr><th>主题与范围</th><th>维护窗口</th><th>受众</th><th>状态</th><th>操作</th></tr></thead><tbody id="maintenance-notice-list"></tbody></table></div>
|
||||
<nav class="admin-user-pagination mt-3" id="maintenance-pagination" aria-label="维护通知分页" hidden><button class="btn btn-light" id="maintenance-previous" type="button">上一页</button><span id="maintenance-page-label"></span><button class="btn btn-light" id="maintenance-next" type="button">下一页</button></nav>
|
||||
</div>
|
||||
</section>
|
||||
<noscript><p class="alert alert-info mt-3">启用 JavaScript 后可预览受众、调度通知并查看投递详情。</p></noscript>
|
||||
</main>
|
||||
|
||||
<dialog data-admin-instance-drawer id="maintenance-detail" aria-labelledby="maintenance-detail-title">
|
||||
<header class="admin-instance-drawer-header"><div><p class="text-muted fs-13 mb-1">维护通知详情</p><h2 class="h4 fw-semibold mb-0" id="maintenance-detail-title">通知</h2></div><button class="admin-modal-close position-static flex-shrink-0" id="maintenance-detail-close" type="button" aria-label="关闭详情"><i class="mdi mdi-close" aria-hidden="true"></i></button></header>
|
||||
<div class="admin-instance-drawer-body"><p class="alert alert-info" id="maintenance-detail-state" role="status" aria-live="polite">正在读取通知详情…</p><div id="maintenance-detail-body"></div></div>
|
||||
<footer class="admin-instance-drawer-footer"><span class="text-muted fs-12">取消只影响尚未领取的邮件;已进入发送中的投递仍会收敛为已发送或效果未知。</span><button class="btn btn-outline-danger" id="maintenance-detail-cancel" type="button" hidden>取消尚未发送的邮件</button></footer>
|
||||
</dialog>
|
||||
<script id="admin-maintenance-notice-bootstrap" type="application/json">{$maintenance_notice_bootstrap_json|default:'null' nofilter}</script>
|
||||
<script type="module" src="/cloud/admin-maintenance-notices.js?v={$venix_asset_version}"></script>
|
||||
{include file='admin/static_footer.tpl'}
|
||||
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026110504' scope='global'}
|
||||
{assign var=venix_asset_version value='2026110601' scope='global'}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
const source = await readFile(
|
||||
new URL('../public/cloud/admin-maintenance-notices.js', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
|
||||
assert.match(source, /state\.preview = null;[\s\S]*maintenance-schedule/,
|
||||
'Changing the scope must invalidate the reviewed audience.');
|
||||
assert.match(source, /maintenance_starts_at: starts, maintenance_ends_at: ends, scheduled_at: scheduled/,
|
||||
'Browser-local inputs must be converted to epoch seconds for UTC delivery.');
|
||||
assert.match(source, /audience_digest: state\.preview\.audience_digest/,
|
||||
'Scheduling must send the reviewed audience digest.');
|
||||
assert.match(source, /if \(!error\?\.mutationMayHaveApplied\) return false;[\s\S]*state\.mutationLocked = true/,
|
||||
'An uncertain write must lock the composer instead of replaying it.');
|
||||
assert.match(source, /VenixAdminDangerDialog\.confirm/,
|
||||
'Cancellation must use the shared administrator danger dialog.');
|
||||
assert.doesNotMatch(source, /\bfetch\s*\(|innerHTML|window\.confirm/,
|
||||
'The page must not bypass the request runtime or safe DOM rendering.');
|
||||
|
||||
console.log('Maintenance notice browser behavior checks passed.');
|
||||
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
$root = dirname(__DIR__);
|
||||
$read = static function (string $path) use ($root): string {
|
||||
$source = file_get_contents($root . '/' . $path);
|
||||
if (!is_string($source)) {
|
||||
throw new RuntimeException('Unable to read ' . $path);
|
||||
}
|
||||
return $source;
|
||||
};
|
||||
$assert = static function (bool $condition, string $message): void {
|
||||
if (!$condition) {
|
||||
throw new RuntimeException($message);
|
||||
}
|
||||
};
|
||||
|
||||
$routes = $read('config/routes.php');
|
||||
$controller = $read('app/Controllers/Admin/CloudPageController.php');
|
||||
$service = $read('app/Services/Cloud/CloudMaintenanceNoticeService.php');
|
||||
$template = $read('resources/views/venix/admin/cloud/maintenance_notices.tpl');
|
||||
$sidebar = $read('resources/views/venix/admin/static_header.tpl');
|
||||
$script = $read('public/cloud/admin-maintenance-notices.js');
|
||||
|
||||
$assert(str_contains($routes,
|
||||
"'/maintenance-notices',\n 'App\\Controllers\\Admin\\CloudPageController:maintenanceNotices'")
|
||||
&& str_contains($controller, 'public function maintenanceNotices(')
|
||||
&& str_contains($controller, "'private, no-store'")
|
||||
&& str_contains($controller, 'JSON_HEX_TAG | JSON_HEX_AMP')
|
||||
&& str_contains($controller, "'can_manage' => (bool)"),
|
||||
'The administrator page route lost authorization or private bootstrap boundaries.');
|
||||
$assert(str_contains($service, 'public function catalog(): array')
|
||||
&& str_contains($service, 'public function prefill(')
|
||||
&& str_contains($service, "hash_equals((string) \$pool['pool_key'], \$poolKey)")
|
||||
&& str_contains($service, "'state' => (string) \$pool->state"),
|
||||
'Audience shortcuts must resolve through the full server-owned catalog.');
|
||||
$assert(str_contains($template, 'data-admin-maintenance-notices')
|
||||
&& str_contains($template, 'data-can-manage=')
|
||||
&& str_contains($template, '<fieldset {if !$admin_can_manage|default:false}disabled{/if}>')
|
||||
&& str_contains($template, 'admin-maintenance-notice-bootstrap')
|
||||
&& str_contains($template, ' nofilter}</script>')
|
||||
&& str_contains($template,
|
||||
'/cloud/admin-maintenance-notices.js?v={$venix_asset_version}')
|
||||
&& str_contains($sidebar, 'href="/admin/maintenance-notices"'),
|
||||
'Maintenance notice page or navigation contracts are incomplete.');
|
||||
$assert(str_contains($script, 'window.VenixAdminRequestRuntime.create')
|
||||
&& str_contains($script, 'window.VenixAdminDangerDialog.confirm')
|
||||
&& str_contains($script, 'mutationMayHaveApplied')
|
||||
&& str_contains($script, 'state.mutationLocked = true')
|
||||
&& str_contains($script, 'audience_digest: state.preview.audience_digest')
|
||||
&& str_contains($script, 'textContent')
|
||||
&& !str_contains($script, 'window.confirm')
|
||||
&& !str_contains($script, 'innerHTML')
|
||||
&& !preg_match('/\bfetch\s*\(/', $script),
|
||||
'Browser actions must use the shared runtime and safe DOM rendering.');
|
||||
|
||||
echo "Maintenance notice administrator page contracts passed.\n";
|
||||
Loading…
Reference in New Issue