P2-4 修复: portal setDefault id 数字校验 (2026-07-02)

FINDING-P5: setDefault 缺 id 数字校验
  - 用户误传 --portalId=portal.fullName (字符串)
  - 走 resolveMenuIdFromPortal → loadMenu.getMenuList 拉全部菜单
  - 客户端 filter moduleId='portal.fullName' (永真不匹配)
  - 返 'BS-110 无法解析 menuId' 误导, 浪费 1 次 menu list API

修复:
- 入口加 /^\d{10,30}$/ 校验 (JNPF id 是 Long 雪花, 18-19 位)
- 不合法直接 exit 1, 提示 '用 dacli portal list 查 id'
- --menuId 同样校验

审计: dacli/docs/cmd-review/v0.14-rollout-audit-2026-07-02.md §3.1 P5
This commit is contained in:
ssw committed 2026-07-02 12:36:49 +08:00
1 parent 65b192b5f1
commit 33219644fd
1 file changed
+13
+13
View File
@@ -79,6 +79,19 @@ export function buildPortalSetDefaultCommand(): Command {
process.exit(1)
}
// v0.15+ (P2-4): id 数字校验, 输错字符串 (如 fullName) → 直接 exit 1, 避免走 resolveMenuIdFromPortal 浪费 API
const idRegex = /^\d{10,30}$/ // JNPF id 是 Long 雪花, 通常 18-19 位数字
if (opts.portalId && !idRegex.test(opts.portalId)) {
log.error(`--portalId "${opts.portalId}" 不是合法 JNPF id (期望纯数字 10-30 位, 如 842332446711088325)`)
log.error('提示: 用 `dacli portal list` 查 id, 别传 fullName/enCode')
process.exit(1)
}
if (opts.menuId && !idRegex.test(opts.menuId)) {
log.error(`--menuId "${opts.menuId}" 不是合法 JNPF id (期望纯数字 10-30 位)`)
log.error('提示: 用 `dacli menu list` 查 id')
process.exit(1)
}
const c = await JnpfClient.fromToken()
await initPortalWebapi(c)
await initMenuWebapi(c) // v0.15+: portalId 路径走 menu list 找 moduleId