feat(user): 新增 auth-list 命令 (admin 查 7 类权限)

This commit is contained in:
ssw committed 2026-06-15 10:27:36 +08:00
1 parent cee851841c
commit aa50ffcd08
1 file changed
+99 -7
+99 -7
View File
@@ -1,16 +1,108 @@
/**
* commands/user/auth-list.ts — 占位, Task 17 实现
* commands/user/auth-list.ts — admin 查用户具体权限
*
* API: GET /api/permission/Users/Authorize?userId={uid}&objectId={objId}&objectType={type}
*
* 返回: {module:[], button:[], column:[], form:[], resource:[], flow:[], print:[]}
* web 端触发: Authorize.vue getAuthData(objectId, objectType) → 7 个 tab
*/
import { Command } from 'commander'
import { log } from '../../core/log.ts'
import { JnpfClient } from '../../core/client.ts'
import { installAiHelpHook } from '../../core/help.ts'
import { log, printJson } from '../../core/log.ts'
interface AuthItem {
id?: string
fullName?: string
enCode?: string
parentId?: string
}
interface AuthListResp {
module?: AuthItem[]
button?: AuthItem[]
column?: AuthItem[]
form?: AuthItem[]
resource?: AuthItem[]
flow?: AuthItem[]
print?: AuthItem[]
}
interface AuthListOpts {
userId: string
objectId: string
objectType: string
json?: boolean
}
export function buildUserAuthListCommand(): Command {
const cmd = new Command('auth-list').description('TODO: implement in Task 17')
cmd.action(async () => {
log.warn('TODO: implement in Task 17')
process.exit(1)
const cmd = new Command('auth-list')
.description('查用户具体权限 (admin 操作, 7 类权限列表)')
.requiredOption('--userId <uid>', '用户 id')
.requiredOption('--objectId <id>', 'object id (从 auth-groups 拿)')
.requiredOption('--objectType <t>', 'object 类型: role | position | organize', (v) => {
if (!['role', 'position', 'organize'].includes(v)) {
throw new Error('objectType 必须是 role/position/organize')
}
return v
})
.option('--json', '原始 JSON 输出 (含 7 类全部)', false)
.action(async (opts: AuthListOpts) => {
const c = await JnpfClient.fromToken()
const r = await c.get<AuthListResp>('/permission/Users/Authorize', {
userId: opts.userId,
objectId: opts.objectId,
objectType: opts.objectType,
})
if (r.code !== 200) {
log.error(`user auth-list 失败 (code=${r.code}): ${r.msg}`)
process.exit(1)
}
const data = r.data || {}
if (opts.json) {
printJson(data)
return
}
const cats: Array<keyof AuthListResp> = ['module', 'button', 'column', 'form', 'resource', 'flow', 'print']
const catNames: Record<keyof AuthListResp, string> = {
module: '菜单',
button: '按钮',
column: '列表',
form: '表单',
resource: '数据',
flow: '流程',
print: '打印',
}
log.info(`用户 id=${opts.userId} 在 ${opts.objectType}=${opts.objectId} 下的权限:`)
for (const cat of cats) {
const list = data[cat] || []
console.log(`\n--- ${catNames[cat]} (${list.length}) ---`)
if (!list.length) {
console.log(' (无)')
continue
}
for (const it of list) {
console.log(` ${it.id} ${it.fullName}${it.enCode ? ` (${it.enCode})` : ''}`)
}
}
})
installAiHelpHook(cmd, {
purpose: '查用户具体权限 (admin 操作, 7 类: 菜单/按钮/列表/表单/数据/流程/打印)',
required: {
'--userId': '用户 id',
'--objectId': 'object id (从 auth-groups 拿)',
'--objectType': 'role | position | organize',
},
optional: { '--json': '原始 JSON 输出 (含 7 类全部)' },
example: 'dacli user auth-list --userId=uid --objectId=roleId --objectType=role',
source: {
web: 'web/apps/jnpf-web-apps-main/src/views/_core/profile/components/Authorize.vue',
api: 'GET /api/permission/Users/Authorize',
},
notes: [
'**两段式**: 先 auth-groups 拿 objectId, 再 auth-list 查具体权限',
'**7 类**: module/button/column/form/resource/flow/print',
],
})
installAiHelpHook(cmd, { purpose: 'TODO' })
return cmd
}