feat(release): 生产授权支持页面通道(管理员会话 + 固定确认语句)

页面原本没有任何生产入口,授权/重排/回滚只能带 Bearer 调接口,实际还要 admin 会话。
现在三个端点支持两条通道,门禁语义不变:

- 运维通道:Authorization: Bearer <token>,审计记 PRODUCTION_RELEASE_AUTHORIZER_REF
- 页面通道:已认证 admin 会话 + 固定确认语句,审计记该管理员用户名
- 请求门禁 / 备份恢复门禁 / Release Worker 执行门禁三者不受影响
- 发布管理第 6–8 步加「授权发布 / 重排 / 回滚」按钮,点击需逐字输入确认语句,
  仅 admin 可见;重排沿用原执行授权人,不改写历史
- openapi 与 P6 契约同步;测试:双通道各一条 + 非 admin/错短语拒绝 + 前端按钮与确认门禁
This commit is contained in:
姚章浩
2026-10-08 17:00:49 +08:00
parent 71f6311399
commit 2de7a43286
12 changed files with 429 additions and 23 deletions
+44
View File
@@ -530,3 +530,47 @@ export async function fetchReleaseAuditChain(executionID: string, signal?: Abort
items: rows('items').map((row) => ({ publication_id: auditText(row, 'publication_id'), title: auditText(row, 'title'), action: auditText(row, 'action'), item_state: auditText(row, 'item_state'), review_id: auditText(row, 'review_id'), acceptance_run_id: auditText(row, 'acceptance_run_id'), source_item_id: auditText(row, 'source_item_id'), source_item_version_id: auditText(row, 'source_item_version_id'), production_revision: auditText(row, 'production_revision'), error_code: auditText(row, 'error_code') })),
}
}
// ——— 生产动作(授权发布 / 重排 / 回滚)———
// 页面通道:管理员会话 + 服务端逐字核对的固定确认语句。Bearer 通道仍留给运维脚本。
export type ProductionActionKind = 'authorize' | 'retry' | 'rollback'
export const productionConfirmationPhrases: Record<ProductionActionKind, string> = {
authorize: 'publish-to-production',
retry: 'retry-production-release',
rollback: 'rollback-production-release',
}
export interface ProductionActionSummary {
id: string
state: string
operation: string
item_count: number
}
const productionActionPaths: Record<ProductionActionKind, (id: string) => string> = {
authorize: (id) => `/api/v1/release-batches/${encodeURIComponent(id)}/authorize-production`,
retry: (id) => `/api/v1/release-executions/${encodeURIComponent(id)}/retry`,
rollback: (id) => `/api/v1/release-executions/${encodeURIComponent(id)}/authorize-rollback`,
}
export async function runProductionAction(kind: ProductionActionKind, id: string, confirmation: string): Promise<ProductionActionSummary> {
const response = await fetch(productionActionPaths[kind](id), {
method: 'POST',
headers: { Accept: 'application/json', 'Content-Type': 'application/json', 'Idempotency-Key': newOperationID() },
body: JSON.stringify({ confirmation }),
})
const payload: unknown = await response.json().catch(() => null)
if (!response.ok) {
const reason = isRecord(payload) && typeof payload.error === 'string' ? payload.error : `生产操作失败(HTTP ${response.status})`
throw new Error(reason)
}
if (!isRecord(payload) || !isRecord(payload.data)) throw new Error('生产操作响应无效')
const data = payload.data
return {
id: typeof data.id === 'string' ? data.id : id,
state: typeof data.state === 'string' ? data.state : '',
operation: typeof data.operation === 'string' ? data.operation : '',
item_count: typeof data.item_count === 'number' ? data.item_count : 0,
}
}