feat: add read-only permission snapshot CLI

This commit is contained in:
gitea committed 2026-09-05 20:45:34 +08:00
1 parent 43d923f567
commit acd187b616
10 files changed
+79

No files matched your search

+2
View File
@@ -41,6 +41,7 @@ metadata:
| 单据附件 / 发票原件标准列表 | `hose bill attachments <单号|ID>` | [references/bill.md](references/bill.md) |
| 系统/自定义档案维度与档案项 | `hose dimension list`, `hose dimension items <维度>` | [references/dimension.md](references/dimension.md) |
| 企业角色、角色组与角色成员 | `hose role list`, `hose role groups`, `hose role members <角色>` | [references/role.md](references/role.md) |
| 角色权限只读快照 | `hose permission get` | [references/role.md](references/role.md) |
| 单据 Web 详情直达链接生成 | `hose bill link <单号|ID>` | [references/bill.md](references/bill.md) |
| 单据实体模型与字段元数据查询 | `hose bill schema` | [references/bill.md](references/bill.md) |
| 企业通讯录检索 / 员工档案 / 防爆保护 | `hose contact search`, `hose contact list`, `hose contact get` | [references/contact.md](references/contact.md) |
@@ -88,6 +89,7 @@ hose dimension items 项目 # 查看项目、成本中
hose role list # 查看企业角色定义
hose role groups # 查看角色组及其角色
hose role members 财务主管 # 查看指定角色成员
hose permission get # 查看角色权限开关(只读)
hose bill schema # 查询单据实体元数据字典
# 4. 待办与消息
+7
View File
@@ -11,3 +11,10 @@ hose role members CODE15 --json
```
接口来自系统配置 → 角色页面:角色定义列表、角色组及指定角色成员。成员查询支持角色 ID、编码或名称。
权限页的角色权限快照:
```bash
hose permission get
hose permission get --json
```
+16
View File
@@ -0,0 +1,16 @@
import { printJson, printTable } from "../printer.js";
import type { CliParsedArgs, CliResult, CliRuntime } from "../types.js";
import { createEkbClient } from "../../core/auth/ekb.js";
import { getPermissions } from "../../domains/permission/tools.js";
export async function handlePermissionCommand(parsed: CliParsedArgs, runtime: CliRuntime): Promise<CliResult> {
const corp = runtime.selectedCorp;
if (!corp) throw new Error("未指定或未找到有效企业。请通过 --corp=<id> 指定企业,或运行 hose auth login 登录。");
const action = parsed.action?.toLowerCase() || "get";
if (!["get", "list", "show"].includes(action)) throw new Error(`未知 permission 子命令: ${action}。支持: get`);
const client = await createEkbClient(corp);
const report = await getPermissions(client, corp.corpId || corp.id);
if (runtime.jsonMode) return { stdout: printJson({ corpId: corp.corpId || corp.id, corpName: corp.name, ...report }, runtime.outputOptions), stderr: "", exitCode: 0 };
const rows = report.permissions.map((item) => [item.name, item.auth ? "启用" : "停用"]);
return { stdout: `====== 角色权限快照 (权限模型: ${report.type || "-"}) ======\n${rows.length ? printTable(["权限", "状态"], rows) : "暂无权限项"}\n`, stderr: "", exitCode: 0 };
}
+2
View File
@@ -126,6 +126,7 @@ export function printHelp(): string {
platform 自建应用管理 (list)
dimension 系统/自定义档案维度 (list, items <维度>)
role 角色定义与成员 (list, groups, members <角色>)
permission 权限模型快照 (get)
skill Agent Skill 管理 (install, status, dump)
probe 连通性诊断 (probe [corpId])
update 版本自更新与发布记录 (update, update check, update --changelog)
@@ -173,6 +174,7 @@ export function printHelp(): string {
hose-use role list # 查看企业角色定义
hose-use role groups # 查看角色组及其角色
hose-use role members 财务主管 # 查看指定角色成员
hose-use permission get # 查看角色权限开关
hose-use bill link CL20260901001 # 获取单据 Web 详情直达免密跳转链接
hose-use bill list --json -o /tmp/bills.json # 导出单据报文到本地磁盘并防爆
hose-use bill get n0GMIM0dkQmKbS # 根据单号精准查询单据结构化详情
+4
View File
@@ -20,6 +20,7 @@ import { handleTaskCommand } from "./commands/task.js";
import { handleMessageCommand } from "./commands/message.js";
import { handleDimensionCommand } from "./commands/dimension.js";
import { handleRoleCommand } from "./commands/role.js";
import { handlePermissionCommand } from "./commands/permission.js";
import type { CliResult, CliRunOptions } from "./types.js";
const STANDING_COMMANDS = new Set(["http", "server", "web", "mcp"]);
@@ -151,6 +152,9 @@ async function dispatchCli(
case "role":
case "roles":
return await handleRoleCommand(parsed, runtime);
case "permission":
case "permissions":
return await handlePermissionCommand(parsed, runtime);
case "message":
case "messages":
case "notify":
@@ -0,0 +1,7 @@
# Permission Domain
权限域当前提供系统配置 → 权限页面的角色模型权限快照,只读查询:
- `GET /api/glue/v1/organization/permissions/query?model=ROLE&corpId=...`
CLI 入口为 `hose permission get`(也支持 `hose permissions get`)。写入权限仍需通过 Web 端明确操作,CLI 不提供写操作。
+9
View File
@@ -0,0 +1,9 @@
import { z } from "zod";
import type { KyInstance } from "ky";
import { PermissionReportSchema, type PermissionReport } from "./types.js";
export async function getRolePermissions(client: KyInstance, corpId: string): Promise<PermissionReport> {
const response = await client.get("api/glue/v1/organization/permissions/query", { searchParams: { model: "ROLE", corpId } });
const json = (await response.json()) as { value?: unknown };
return PermissionReportSchema.parse(json.value ?? {});
}
+10
View File
@@ -0,0 +1,10 @@
import { describe, expect, it } from "bun:test";
import { getPermissions } from "./tools.js";
describe("Permission Domain - 角色权限", () => {
it("parses the role permission snapshot", async () => {
const client = { get: async () => new Response(JSON.stringify({ value: { type: "FREEDOM", permissions: [{ name: "CREATE", auth: true }, { name: "EDIT", auth: false }] } })) } as any;
const result = await getPermissions(client, "corp-1");
expect(result.type).toBe("FREEDOM"); expect(result.permissions).toHaveLength(2); expect(result.permissions[0]?.auth).toBe(true);
});
});
+16
View File
@@ -0,0 +1,16 @@
import { z } from "zod";
import type { KyInstance } from "ky";
import { getRolePermissions } from "./api.js";
export async function getPermissions(client: KyInstance, corpId: string) { return getRolePermissions(client, corpId); }
export const permissionTools = [{
name: "permission_role_get",
description: "读取当前企业角色模型的权限开关(只读)",
parameters: z.object({}),
handler: async ({ corpContext }: any) => {
const corp = corpContext.getCurrent(); if (!corp) throw new Error("未配置活跃企业上下文");
const client = await import("../../core/auth/ekb.js").then((m) => m.createEkbClient(corp));
return getPermissions(client, corp.corpId || corp.id);
},
}];
+6
View File
@@ -0,0 +1,6 @@
import { z } from "zod";
export const PermissionEntrySchema = z.object({ name: z.string(), auth: z.boolean().default(false) });
export const PermissionReportSchema = z.object({ type: z.string().default(""), permissions: z.array(PermissionEntrySchema).default([]) });
export type PermissionEntry = z.infer<typeof PermissionEntrySchema>;
export type PermissionReport = z.infer<typeof PermissionReportSchema>;