auto(284e8d004cbb): session end @ 2026-07-01T15:35:22 (+4f)
This commit is contained in:
1 parent
aa5ea93ec7
commit
66d697a85d
4 files changed
+66
-36
No files matched your search
+29
-13
@@ -1,14 +1,19 @@
|
||||
/**
|
||||
* commands/role/assign.ts — 角色赋权
|
||||
*
|
||||
* API: POST /api/permission/RoleRelation/addRoles (给用户加角色)
|
||||
* POST /api/permission/RoleRelation/deleteRoles (给用户删角色)
|
||||
* PUT /api/permission/Role/{id} (改 role 的 organizeIds/positionIds/userIds)
|
||||
* v0.14+ webapi 化 (webapi/permission/roleRelation.ts addRoles + removeRoles)
|
||||
* 替代 v0.10/v0.13 直接 c.postJson
|
||||
*
|
||||
* 注: roleRelation 不是 webapi/role.ts 暴露的, 镜像源在
|
||||
* web/apps/jnpf-web-apps-main/src/api/permission/roleRelation.ts
|
||||
* (addRoles / removeRoles 函数). 这里直接用 loadWebModule dynamic import,
|
||||
* 复用 webapi/_loader.ts 的 shim 机制.
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { loadWebModule } from '../../webapi/_loader.ts'
|
||||
|
||||
interface AssignOpts {
|
||||
roleId: string
|
||||
@@ -16,9 +21,21 @@ interface AssignOpts {
|
||||
action?: 'add' | 'remove'
|
||||
}
|
||||
|
||||
const ROLE_RELATION_SRC = '/home/ubuntu/ccWorkDir/web/apps/jnpf-web-apps-main/src/api/permission/roleRelation.ts'
|
||||
|
||||
let roleRelationMod: any = null
|
||||
|
||||
async function loadRoleRelation(client: JnpfClient) {
|
||||
if (roleRelationMod) return roleRelationMod
|
||||
const { initDefHttpShim } = await import('../../webapi/_defhttp_shim.ts')
|
||||
initDefHttpShim(client)
|
||||
roleRelationMod = await loadWebModule(ROLE_RELATION_SRC)
|
||||
return roleRelationMod
|
||||
}
|
||||
|
||||
export function buildRoleAssignCommand(): Command {
|
||||
const cmd = new Command('assign')
|
||||
.description('给角色赋用户 (或从角色删用户)')
|
||||
.description('给角色赋用户 (或从角色删用户, v0.14+ webapi)')
|
||||
.requiredOption('--roleId <id>', '角色 id')
|
||||
.option('--userIds <ids>', '用户 id 列表 (逗号分隔)')
|
||||
.option('--action <a>', 'add=加用户, remove=删用户', 'add')
|
||||
@@ -32,12 +49,10 @@ export function buildRoleAssignCommand(): Command {
|
||||
process.exit(2)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
const path =
|
||||
opts.action === 'add'
|
||||
? '/permission/RoleRelation/addRoles'
|
||||
: '/permission/RoleRelation/deleteRoles'
|
||||
const rr = await loadRoleRelation(c)
|
||||
const userIds = opts.userIds.split(',').map((s) => s.trim()).filter(Boolean)
|
||||
const r = await c.postJson(path, { roleId: opts.roleId, userIds })
|
||||
const fn = opts.action === 'add' ? rr.addRoles : rr.removeRoles
|
||||
const r = (await fn({ roleId: opts.roleId, userIds })) as { code?: number; msg?: string }
|
||||
if (r.code !== 200) {
|
||||
log.error(`role assign 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
@@ -45,15 +60,16 @@ export function buildRoleAssignCommand(): Command {
|
||||
log.info(`✓ 角色 id=${opts.roleId} ${opts.action} ${userIds.length} 个用户 OK`)
|
||||
})
|
||||
installAiHelpHook(cmd, {
|
||||
purpose: '给角色赋用户 (或从角色删用户)',
|
||||
purpose: '给角色赋用户 (或从角色删用户, v0.14+ webapi 镜像 web roleRelation.ts addRoles/removeRoles)',
|
||||
required: { '--roleId': '角色 id', '--userIds': '用户 id 列表' },
|
||||
optional: { '--action': 'add/remove' },
|
||||
example: 'dacli role assign --roleId=123 --userIds=456,789 --action=add',
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/role/Form.vue',
|
||||
api: 'POST /api/permission/RoleRelation/addRoles',
|
||||
ref: 'doc/v0.8-endpoints.md §2.1',
|
||||
api: 'POST /api/permission/RoleRelation/addRoles | /deleteRoles',
|
||||
ref: 'web/.../api/permission/roleRelation.ts addRoles() / removeRoles()',
|
||||
},
|
||||
notes: ['v0.14+ 改用 webapi 镜像 (动态加载 roleRelation.ts, 复用 _loader.ts shim)'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
+18
-12
@@ -1,7 +1,8 @@
|
||||
/**
|
||||
* commands/role/create.ts — 新建角色
|
||||
*
|
||||
* API: POST /api/permission/Role
|
||||
* v0.14+ webapi 化 (loadRole.create + loadRole.getRoleList for step machine)
|
||||
* 替代 v0.10/v0.13 直接 c.postJson / c.get
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
@@ -9,6 +10,7 @@ import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { validateRoleCreate } from './_validate.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
import { initWebapi, loadRole } from '../../webapi/role.ts'
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
@@ -20,7 +22,7 @@ interface CreateOpts {
|
||||
|
||||
export function buildRoleCreateCommand(): Command {
|
||||
const cmd = new Command('create')
|
||||
.description('新建角色 (P1 权限三角核心)')
|
||||
.description('新建角色 (P1 权限三角核心, v0.14+ webapi)')
|
||||
.requiredOption('--fullName <name>', '角色名称')
|
||||
.requiredOption('--enCode <code>', '角色编码')
|
||||
.option('--type <t>', '角色类型: 0=全局 1=业务', '0')
|
||||
@@ -29,6 +31,7 @@ export function buildRoleCreateCommand(): Command {
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initWebapi(c)
|
||||
|
||||
// v0.11d+ Phase 3.4: step machine 校验 (镜像 web role/Form.vue + 后端 RoleController.create)
|
||||
// 跑 3 step 校验, 失败 → exit 1
|
||||
@@ -53,7 +56,7 @@ export function buildRoleCreateCommand(): Command {
|
||||
positionIds: [],
|
||||
userIds: userIdsArray,
|
||||
}
|
||||
const r = await c.postJson<{ id?: string }>('/permission/Role', body)
|
||||
const r = (await loadRole.create(body)) as { code?: number; msg?: string; data?: { id?: string } }
|
||||
if (r.code !== 200) {
|
||||
log.error(`role create 失败 (code=${r.code}): ${r.msg}`)
|
||||
// v0.11e+ Phase A1: 后端错误增强 — 自动从 msg 提取 ErrorCode
|
||||
@@ -63,10 +66,10 @@ export function buildRoleCreateCommand(): Command {
|
||||
}
|
||||
let id = r.data?.id
|
||||
if (!id) {
|
||||
const listR = await c.get<{ list: { id: string; enCode: string; fullName: string }[] }>(
|
||||
'/permission/Role',
|
||||
{ keyword: opts.enCode, pageSize: '50' },
|
||||
)
|
||||
const listR = (await loadRole.getRoleList({
|
||||
keyword: opts.enCode,
|
||||
pageSize: '50',
|
||||
})) as { data?: { list?: { id: string; enCode: string; fullName: string }[] } }
|
||||
const found = (listR.data?.list || []).find(
|
||||
(d) => d.enCode === opts.enCode || d.fullName === opts.fullName,
|
||||
)
|
||||
@@ -86,13 +89,14 @@ export function buildRoleCreateCommand(): Command {
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/role/Form.vue (后端: jnpf/.../RoleController.java:124-161)',
|
||||
api: 'POST /api/permission/Role',
|
||||
ref: 'doc/v0.8-endpoints.md §2.1',
|
||||
ref: 'web/.../api/permission/role.ts create()',
|
||||
},
|
||||
notes: [
|
||||
'v0.11d+ step machine (镜像 web role/Form.vue:33-108 schemas + 后端 RoleController.create L124-161):',
|
||||
' step 0 基础信息: fullName 必填 + enCode 正则 + type ∈ {0,1} + enabledMark + sortCode',
|
||||
' step 1 约束: isCondition + constraintType + 联动校验 (互斥/基数/先决互斥)',
|
||||
' step 2 唯一性 (BS-47): enCode 全平台唯一 (EXIST002) + fullName 按 type 分类 (EXIST001)',
|
||||
'v0.14+ 改用 webapi 镜像 (loadRole.create + loadRole.getRoleList for step machine)',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
@@ -105,9 +109,11 @@ export function buildRoleCreateCommand(): Command {
|
||||
* 镜像原型:
|
||||
* - web permission/role/Form.vue:33-108 schemas (fullName/enCode/isCondition/constraintType/...)
|
||||
* - 后端 RoleController.java:124-161 create (EXIST001/002 + 约束判断)
|
||||
*
|
||||
* v0.14+ webapi 化: 用 loadRole.getRoleList 拉已存在 role
|
||||
*/
|
||||
async function runRoleStepMachine(
|
||||
c: JnpfClient,
|
||||
_c: JnpfClient,
|
||||
opts: {
|
||||
fullName?: string
|
||||
enCode?: string
|
||||
@@ -119,10 +125,10 @@ async function runRoleStepMachine(
|
||||
// 1. 拉已存在 role (供 step 2 唯一性预校验, BS-47)
|
||||
let existingRoles: Array<{ fullName?: string; enCode?: string; type?: number | string }> = []
|
||||
try {
|
||||
const r = await c.get<{ data?: { list?: Array<any> } }>('/permission/Role', {
|
||||
const r = (await loadRole.getRoleList({
|
||||
currentPage: 1,
|
||||
pageSize: 1000,
|
||||
})
|
||||
})) as { data?: { list?: Array<any> } }
|
||||
const list = (r.data as { list?: Array<any> })?.list || []
|
||||
existingRoles = list.map((role: any) => ({
|
||||
fullName: role.fullName,
|
||||
@@ -153,4 +159,4 @@ async function runRoleStepMachine(
|
||||
}
|
||||
|
||||
log.info(`✓ step machine 校验通过 (3/3): enCode=${opts.enCode}`)
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* commands/role/delete.ts — 删除角色
|
||||
*
|
||||
* API: DELETE /api/permission/Role/{id}
|
||||
* v0.14+ webapi 化 (loadRole.delRole)
|
||||
* 替代 v0.10/v0.13 直接 c.del
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log } from '../../core/log.ts'
|
||||
import { initWebapi, loadRole } from '../../webapi/role.ts'
|
||||
|
||||
interface DeleteOpts {
|
||||
id: string
|
||||
@@ -15,7 +17,7 @@ interface DeleteOpts {
|
||||
|
||||
export function buildRoleDeleteCommand(): Command {
|
||||
const cmd = new Command('delete')
|
||||
.description('删除角色 (非系统内置)')
|
||||
.description('删除角色 (非系统内置, v0.14+ webapi)')
|
||||
.requiredOption('--id <id>', '角色 id')
|
||||
.option('--yes', '跳过确认', false)
|
||||
.action(async (opts: DeleteOpts) => {
|
||||
@@ -24,7 +26,8 @@ export function buildRoleDeleteCommand(): Command {
|
||||
process.exit(2)
|
||||
}
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.del(`/permission/Role/${opts.id}`)
|
||||
await initWebapi(c)
|
||||
const r = (await loadRole.delRole(opts.id)) as { code?: number; msg?: string }
|
||||
if (r.code !== 200) {
|
||||
log.error(`role delete 失败: ${r.msg}`)
|
||||
process.exit(1)
|
||||
@@ -38,8 +41,9 @@ export function buildRoleDeleteCommand(): Command {
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/role/index.vue',
|
||||
api: 'DELETE /api/permission/Role/{id}',
|
||||
ref: 'doc/v0.8-endpoints.md §2.1',
|
||||
ref: 'web/.../api/permission/role.ts delRole()',
|
||||
},
|
||||
notes: ['v0.14+ 改用 webapi 镜像 (loadRole.delRole)'],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,14 @@
|
||||
/**
|
||||
* commands/role/list.ts — 角色列表
|
||||
*
|
||||
* API: GET /api/permission/Role
|
||||
* v0.14+ webapi 化 (loadRole.getRoleList)
|
||||
* 替代 v0.10/v0.13 直接 c.get
|
||||
*/
|
||||
import { Command } from 'commander'
|
||||
import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi, loadRole } from '../../webapi/role.ts'
|
||||
|
||||
interface RoleItem {
|
||||
id?: string
|
||||
@@ -24,16 +26,17 @@ interface ListOpts {
|
||||
|
||||
export function buildRoleListCommand(): Command {
|
||||
const cmd = new Command('list')
|
||||
.description('列出角色 (权限载体, P1 权限三角核心)')
|
||||
.description('列出角色 (权限载体, P1 权限三角核心, v0.14+ webapi)')
|
||||
.option('--keyword <k>', '按名称/编码模糊搜索')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: ListOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
const r = await c.get<{ list: RoleItem[] }>('/permission/Role', {
|
||||
await initWebapi(c)
|
||||
const r = (await loadRole.getRoleList({
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})
|
||||
})) as { code?: number; msg?: string; data?: { list?: RoleItem[] } }
|
||||
if (r.code !== 200) {
|
||||
log.error(`role list 失败 (code=${r.code}): ${r.msg}`)
|
||||
process.exit(1)
|
||||
@@ -62,12 +65,13 @@ export function buildRoleListCommand(): Command {
|
||||
source: {
|
||||
web: 'web/apps/jnpf-web-apps-main/src/views/permission/role/index.vue',
|
||||
api: 'GET /api/permission/Role',
|
||||
ref: 'doc/v0.8-endpoints.md §2.1',
|
||||
ref: 'web/.../api/permission/role.ts getRoleList()',
|
||||
},
|
||||
notes: [
|
||||
'**决策 7**: 角色是权限三角的 1 号, 先建角色再赋权',
|
||||
'**反模式**: 系统内置角色 (isSystem=1) 不可删改',
|
||||
'v0.14+ 改用 webapi 镜像 (loadRole.getRoleList)',
|
||||
],
|
||||
})
|
||||
return cmd
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user