diff --git a/src/commands/workflow/create.ts b/src/commands/workflow/create.ts index 7037028..d7c0585 100644 --- a/src/commands/workflow/create.ts +++ b/src/commands/workflow/create.ts @@ -22,6 +22,8 @@ interface CreateOpts { category?: string /** v0.11 修复: 后端字段名是 `type` (TemplateCrForm.java:19), dacli 旧称 flowType 错配 */ type?: string + /** v0.11e+ Phase B2: auto-authorize */ + autoAuthorize?: boolean flowXml?: string flowNodes?: string flowConfig?: string @@ -53,6 +55,8 @@ export function buildWorkflowCreateCommand(): Command { // v0.11 修复: 后端 showType (TemplateCrForm.java:42) .option('--showType ', '显示位置 (0=全局 1=流程 2=菜单, 默认 0)', '0') .option('--ai ', '白皮书 5.10.3 AI 创建流程 — 自然语言描述, 平台 LLM 生成 flowXml') + // v0.11e+ Phase B2: auto-authorize (镜像 web 流创建后自动授权给当前角色) + .option('--auto-authorize', 'v0.11e+ Phase B2: 创建后自动给当前角色授权 (镜像 web Actions/Module 流程版本)', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: CreateOpts) => { // 5.10.3 AI 创建流程 @@ -127,6 +131,25 @@ export function buildWorkflowCreateCommand(): Command { } const newId = (r.data as { id?: string })?.id || '(unknown)' log.ok(`创建成功: id=${newId} enCode=${opts.enCode}`) + + // v0.11e+ Phase B2: auto-authorize (镜像 web 流程创建后自动授权给当前角色) + if (opts.autoAuthorize) { + log.info(`--auto-authorize: 给当前角色授权 workflow (id=${newId})`) + try { + // 通用 authorize 端点 (JNPF /permission/authorize + itemType=workflow) + const ar = await c.postJson('/permission/authorize', { + objectType: 'flow', + objectId: newId, + }) + if (ar.code === 200) { + log.ok(`✓ 已授权给当前角色 (workflow id=${newId})`) + } else { + log.warn(`--auto-authorize 部分失败: ${ar.msg} (workflow 已创建, 可在权限管理手动授权)`) + } + } catch (e) { + log.warn(`--auto-authorize 异常: ${(e as Error).message?.slice(0, 100)} (workflow 已创建)`) + } + } if (opts.json) printJson({ id: newId, enCode: opts.enCode, flowXml: opts.flowXml }) })