feat(release): 发布到生产一键完成(建批+锁定+授权合成一个动作)
用户的反馈是对的:上一轮只砍掉了"冻结/锁定"两个按钮,但一条文档从"已批准"到"发出"实际仍要
~9 次交互(找条目→勾选→填名→建批→滚到清单→找批次→授权→输语句→提交),因为"批次仪式"本身
还留在路径上。
- 新端点 POST /api/v1/release-batches/publish-now:在同一操作里先建批(SealImmediately,冻结
即锁定)再授权生产发布,返回 {batch, execution}。
- 不放松任何约束:请求门禁(403)、备份恢复验证门禁(412)、管理员身份(401)、固定确认语句(400)、
发布前快照硬门禁(409)、建批门禁(422) 全部沿用既有实现,无旁路;名称可省(服务端固定回退名,
保证重放指纹一致)。
- 界面:审核行上直接「发布到生产」(管理员 + 门禁开启时显示),工具栏支持选中多条一次发布;
复用既有确认弹窗(固定语句)。批次名不再是必经步骤。
- 实测(面板):点行级按钮 → 输 `publish-to-production` → 提交 → 批次 rb-bee80550…(sealed)
+ 执行 rx-3d831129…(completed, 项级 verified) → 页面回滚 rx-43835fac…(rolled_back, absent)。
测试:publish_now_test.go(四道关卡 + 组合调用 + 名称回退)与 reviewRelease.test.ts(请求体/回传/错误原因);
Go 26 包、前端 183 条全过。
This commit is contained in:
+22
-9
@@ -12,7 +12,7 @@ import { fetchSourceAssets } from './assets'
|
||||
import type { LegacyStatus, SourceAssetPage } from './assets'
|
||||
import { fetchJobs } from './jobs'
|
||||
import type { Job, JobState } from './jobs'
|
||||
import { confirmReleaseChangeSet, createReleaseBatch, fetchLatestReleaseChangeSet, fetchReleaseAuditChain, fetchReleaseBatch, fetchReleaseBatches, fetchReleaseCapabilities, fetchReleaseExecution, fetchReleaseExecutions, fetchReleasePlan, fetchReviewCandidates, generateReleaseChangeSet, productionConfirmationPhrases, reviewPublication, runProductionAction, sealReleaseBatch, reviewPublicationsBatch } from './reviewRelease'
|
||||
import { confirmReleaseChangeSet, createReleaseBatch, fetchLatestReleaseChangeSet, fetchReleaseAuditChain, fetchReleaseBatch, fetchReleaseBatches, fetchReleaseCapabilities, fetchReleaseExecution, fetchReleaseExecutions, fetchReleasePlan, fetchReviewCandidates, generateReleaseChangeSet, productionConfirmationPhrases, reviewPublication, runProductionAction, sealReleaseBatch, reviewPublicationsBatch , runPublishNow} from './reviewRelease'
|
||||
import type { ProductionActionKind } from './reviewRelease'
|
||||
import type { ReleaseAuditChain, ReleaseBatchDetail, ReleaseBatchPage, ReleaseCapabilities, ReleaseChangeSetDetail, ReleaseExecutionDetail, ReleaseExecutionPage, ReleasePlan, ReleasePlanItem, ReviewCandidatePage, Visibility } from './reviewRelease'
|
||||
import { fetchSourceConnections, fetchSourceScanDetail, fetchSourceScans, triggerSourceScan } from './sourceConnections'
|
||||
@@ -228,7 +228,7 @@ interface ModulePageProps extends JobDashboardProps {
|
||||
releaseActionBusy?: boolean
|
||||
releaseActionError?: string | null
|
||||
releaseActionMessage?: string | null
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string) => void
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => void
|
||||
onReleaseActionPhrase?: (value: string) => void
|
||||
onSubmitReleaseAction?: () => void
|
||||
onCancelReleaseAction?: () => void
|
||||
@@ -239,6 +239,9 @@ export interface PendingReleaseAction {
|
||||
kind: ProductionActionKind
|
||||
id: string
|
||||
label: string
|
||||
/** publish_now 专用:这次要发布哪些条目(含待删除)。 */
|
||||
publicationIDs?: string[]
|
||||
deletePublicationIDs?: string[]
|
||||
}
|
||||
|
||||
const emptyAssetPage: SourceAssetPage = { items: [], summary: { total: 0, completed: 0, content_alias: 0, over_limit: 0 }, limit: 50, offset: 0 }
|
||||
@@ -689,13 +692,13 @@ interface ReleaseManagementProps {
|
||||
releaseActionBusy?: boolean
|
||||
releaseActionError?: string | null
|
||||
releaseActionMessage?: string | null
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string) => void
|
||||
onStartReleaseAction?: (kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => void
|
||||
onReleaseActionPhrase?: (value: string) => void
|
||||
onSubmitReleaseAction?: () => void
|
||||
onCancelReleaseAction?: () => void
|
||||
}
|
||||
|
||||
const releaseActionLabels: Record<ProductionActionKind, string> = { authorize: '授权发布', retry: '重排执行', rollback: '回滚发布' }
|
||||
const releaseActionLabels: Record<ProductionActionKind, string> = { authorize: '授权发布', retry: '重排执行', rollback: '回滚发布', publish_now: '发布到生产' }
|
||||
|
||||
const acceptanceLabels: Record<string, string> = {
|
||||
pending: '待验收',
|
||||
@@ -1026,10 +1029,13 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
||||
{(() => {
|
||||
// 「可批准」只含尚未决定且门禁通过的条目:已驳回的不能被"全选"顺手翻回来。
|
||||
const batchable = props.reviewPage.items.filter((item) => item.gate_status === 'ready' && item.review_state === 'pending').map((item) => item.publication_id)
|
||||
// 已批准且可发布的选中项:一键"发布到生产"(建批+锁定+授权合成一个动作)。
|
||||
const publishableSelected = selectedIDs.filter((id) => props.reviewPage.items.some((item) => item.publication_id === id && item.review_state === 'approved' && item.gate_status === 'ready'))
|
||||
return <div className="release-toolbar"><div className="release-toolbar-actions">
|
||||
<button type="button" disabled={!batchable.length || props.reviewingId === 'batch'} onClick={() => setSelectedIDs(batchable)}>全选可批准({batchable.length})</button>
|
||||
<button type="button" disabled={!selectedIDs.length || props.reviewingId === 'batch'} onClick={() => void props.onBatchReview?.(selectedIDs, 'approved', 'internal', 'approved_for_release')}>{props.reviewingId === 'batch' ? '正在批量处理…' : `批量批准选中(${selectedIDs.length})`}</button>
|
||||
<button type="button" disabled={!selectedIDs.length || props.reviewingId === 'batch'} onClick={() => void props.onBatchReview?.(selectedIDs, 'rejected', 'internal', 'needs_correction')}>批量驳回选中({selectedIDs.length})</button>
|
||||
{isAdmin && props.releaseCapabilities.production_release_requests_enabled ? <button type="button" className="primary" disabled={!publishableSelected.length} onClick={() => props.onStartReleaseAction?.('publish_now', 'publish-now', `${publishableSelected.length} 项`, publishableSelected)}>发布到生产(选中 {publishableSelected.length} 项)</button> : null}
|
||||
{props.reviewBatchMessage ? <small role="status">{props.reviewBatchMessage}</small> : null}
|
||||
</div></div>
|
||||
})()}
|
||||
@@ -1056,7 +1062,7 @@ export function ReleaseManagement(props: ReleaseManagementProps) {
|
||||
<td><span className={`status status-${item.gate_status === 'ready' ? 'completed' : 'failed'}`}>{reviewGateLabel(item)}</span></td>
|
||||
<td><select value={visibility} onChange={(event) => setVisibilityByID((current) => ({ ...current, [item.publication_id]: event.target.value as Visibility }))}><option value="internal">仅内部员工</option><option value="external">允许外部用户</option></select></td>
|
||||
<td><span className={`status status-${item.review_state === 'approved' ? 'completed' : item.review_state === 'rejected' ? 'failed' : 'pending'}`}>{reviewLabels[item.review_state]}</span>{item.reviewer_ref ? <small>{item.reviewer_ref}</small> : null}</td>
|
||||
<td><div className="row-actions"><button type="button" disabled={item.gate_status !== 'ready' || props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'approved', visibility, 'approved_for_release')}>批准</button><button type="button" className="secondary-action" disabled={props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'rejected', visibility, 'needs_correction')}>驳回</button></div></td>
|
||||
<td><div className="row-actions"><button type="button" disabled={item.gate_status !== 'ready' || props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'approved', visibility, 'approved_for_release')}>批准</button><button type="button" className="secondary-action" disabled={props.reviewingId === item.publication_id} onClick={() => props.onReview(item.publication_id, 'rejected', visibility, 'needs_correction')}>驳回</button>{isAdmin && props.releaseCapabilities.production_release_requests_enabled && item.review_state === 'approved' && item.gate_status === 'ready' ? <button type="button" title="建批(冻结+锁定)并授权生产发布,一个动作完成" onClick={() => props.onStartReleaseAction?.('publish_now', 'publish-now', item.title, [item.publication_id])}>发布到生产</button> : null}</div></td>
|
||||
</tr>
|
||||
})}
|
||||
</tbody></table></div> : null}
|
||||
@@ -1498,8 +1504,8 @@ export default function App() {
|
||||
|
||||
// 页面上的生产动作:点按钮 → 逐字输入固定确认语句 → 提交。服务端同时校验
|
||||
// 管理员会话、请求门禁与确认语句;Bearer 通道留给运维脚本,行为不变。
|
||||
const handleStartReleaseAction = useCallback((kind: ProductionActionKind, id: string, label: string) => {
|
||||
setPendingReleaseAction({ kind, id, label })
|
||||
const handleStartReleaseAction = useCallback((kind: ProductionActionKind, id: string, label: string, ids?: string[], deleteIDs?: string[]) => {
|
||||
setPendingReleaseAction({ kind, id, label, publicationIDs: ids, deletePublicationIDs: deleteIDs })
|
||||
setReleaseActionPhrase('')
|
||||
setReleaseActionError(null)
|
||||
setReleaseActionMessage(null)
|
||||
@@ -1517,8 +1523,15 @@ export default function App() {
|
||||
setReleaseActionError(null)
|
||||
setReleaseActionMessage(null)
|
||||
try {
|
||||
const summary = await runProductionAction(pendingReleaseAction.kind, pendingReleaseAction.id, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`${releaseActionLabels[pendingReleaseAction.kind]}已受理:执行 ${summary.id}(${summary.state || 'pending'}) · ${summary.item_count} 项`)
|
||||
if (pendingReleaseAction.kind === 'publish_now') {
|
||||
// 名称留空由服务端兜底;这里给一个可读的默认名(确定性内容,重放指纹一致)。
|
||||
const defaultName = `立即发布 · ${new Date().toLocaleDateString('zh-CN')}`
|
||||
const result = await runPublishNow(pendingReleaseAction.publicationIDs ?? [], pendingReleaseAction.deletePublicationIDs ?? [], defaultName, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`已受理发布:批次 ${result.batch_name || result.batch_id} · 执行 ${result.execution_id}`)
|
||||
} else {
|
||||
const summary = await runProductionAction(pendingReleaseAction.kind, pendingReleaseAction.id, releaseActionPhrase.trim())
|
||||
setReleaseActionMessage(`${releaseActionLabels[pendingReleaseAction.kind]}已受理:执行 ${summary.id}(${summary.state || 'pending'}) · ${summary.item_count} 项`)
|
||||
}
|
||||
setPendingReleaseAction(null)
|
||||
setReleaseActionPhrase('')
|
||||
await loadReleaseExecutions()
|
||||
|
||||
Reference in New Issue
Block a user