feat: add read-only permission snapshot CLI
This commit is contained in:
1 parent
43d923f567
commit
acd187b616
10 files changed
+79
No files matched your search
@@ -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 不提供写操作。
|
||||
@@ -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 ?? {});
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
@@ -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);
|
||||
},
|
||||
}];
|
||||
@@ -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>;
|
||||
Reference in new issue
Block a user