From cfb7702ce1c2500b0a1934a1e9287d3e44c84945 Mon Sep 17 00:00:00 2001 From: ssw Date: Thu, 30 Jul 2026 10:32:47 +0800 Subject: [PATCH] auto(14b5ea1b9bd9): session end @ 2026-07-30T10:32:46 (+3f) --- src/commands/workflow/_approver_resolve.ts | 31 ++++++++++------------ src/commands/workflow/index.ts | 2 ++ src/commands/workflow/launch.ts | 8 +++--- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/commands/workflow/_approver_resolve.ts b/src/commands/workflow/_approver_resolve.ts index c12abf4..8bad947 100644 --- a/src/commands/workflow/_approver_resolve.ts +++ b/src/commands/workflow/_approver_resolve.ts @@ -32,6 +32,7 @@ export interface ResolveWebapi { userName?: string account?: string userAccount?: string + userInfo?: Record } | null | undefined> } @@ -49,6 +50,16 @@ export interface ResolveResult { * 注: ${currentUser} 这种变量包装形式是合法的 getter 调用, 不在此列. */ const RESERVED = new Set(['initiator', 'any', 'starter']) +/** 镜像 web auth store 对 CurrentUser.userInfo 的解包,同时兼容历史扁平响应。 */ +export function resolveCurrentUserIdentity(me: Record): { id: string; name: string } { + const info = (me.userInfo as Record | undefined) ?? me + const id = String(info.userId || info.id || me.userId || me.id || '') + const name = id + ? String(info.realName || info.userName || info.userAccount || info.account || id) + : '' + return { id, name } +} + /** * 解析 BPMN userTask assignee 表达式. * @@ -104,23 +115,9 @@ export async function resolveApproverExpr(expr: string, ctx: ResolveCtx): Promis // // 注: dacli 端未 import web GetUserInfoModel (跨包类型解析成本高), 用 inline duck typing // + 此 audit 注释保证跟 web 端响应结构一致. - const info = (me as { userInfo?: Record }).userInfo ?? me - const id = String( - (info as Record).userId || - (info as Record).id || - (me as Record).userId || - (me as Record).id || - '', - ) - const displayName = String( - (info as Record).realName || - (info as Record).userName || - (info as Record).userAccount || - (info as Record).account || - id, - ) - if (!id) return { candidates: [], reason: 'no current user' } - return { candidates: [{ id, name: displayName }] } + const identity = resolveCurrentUserIdentity(me as Record) + if (!identity.id) return { candidates: [], reason: 'no current user' } + return { candidates: [identity] } } return { candidates: [], reason: 'unknown expression' } diff --git a/src/commands/workflow/index.ts b/src/commands/workflow/index.ts index 12f0813..f3e8166 100644 --- a/src/commands/workflow/index.ts +++ b/src/commands/workflow/index.ts @@ -16,6 +16,7 @@ import { buildWorkflowDecisionCommand } from './decision.ts' import { buildWorkflowSelectorCommand } from './selector.ts' import { buildWorkflowTasksCommand } from './tasks.ts' import { buildWorkflowSyncFormCommand } from './syncForm.ts' +import { buildWorkflowAssignApproversCommand } from './assignApprovers.ts' export function buildWorkflowCommand(): Command { const cmd = new Command('workflow').description('流程引擎 (模板 CRUD + 发起/审批 + 我的任务)') @@ -30,5 +31,6 @@ export function buildWorkflowCommand(): Command { cmd.addCommand(buildWorkflowSelectorCommand()) cmd.addCommand(buildWorkflowTasksCommand()) cmd.addCommand(buildWorkflowSyncFormCommand()) // BS-新27 (jxcj 2026-07-01): 同步 form.formData + cmd.addCommand(buildWorkflowAssignApproversCommand()) return cmd } diff --git a/src/commands/workflow/launch.ts b/src/commands/workflow/launch.ts index 1a3c2f4..72ebdd1 100644 --- a/src/commands/workflow/launch.ts +++ b/src/commands/workflow/launch.ts @@ -21,6 +21,7 @@ import { log, printJson } from '../../core/log.ts' import { setupOutputFilter, addOutputOptions, wrapCommand } from '../_output_filter.ts' // v2.1+ 输出过滤; v2.2+ wrapCommand 收口 5c import { verifyLaunched, emitVerifyFailure, type LaunchVerifyWebapi } from './_launch_verify.ts' import { initWebapi as initOperatorWebapi, loadOperator } from '../../webapi/operator.ts' // BS-新147 + v2.2+ 抽离 (替代 inline webapi) +import { resolveCurrentUserIdentity } from './_approver_resolve.ts' interface Opts { flowId: string @@ -101,10 +102,11 @@ export function buildWorkflowLaunchCommand(): Command { const meResp = await c.get<{ id?: string; userId?: string; account?: string }>( `/oauth/CurrentUser?systemCode=${encodeURIComponent(c.appCode)}&isBackend=1&_t=${Date.now()}`, ) - const meData = (meResp.data || {}) as { id?: string; userId?: string; account?: string } - const currentUserId = String(meData.userId || meData.id || meData.account || '') + const meData = (meResp.data || {}) as Record + const identity = resolveCurrentUserIdentity(meData) + const currentUserId = identity.id if (!currentUserId) { - log.warn(`verify: 当前用户 id 拿不到 (CurrentUser 返 data=${JSON.stringify(meData)}), actionable 检查会失效`) + return ctx.fail(`verify: CurrentUser 未返回 userInfo.userId`, { flowId: opts.flowId, taskId }) } // webapi 镜像 web task.ts:71-73 getFlowBeforeList (P0 严格镜像, BS-新147 修)