feat(xugu): add visual user and privilege management
This commit is contained in:
1 parent
4949cce746
commit
ad221eeb88
14 files changed
+2500
-3
No files matched your search
@@ -2577,6 +2577,45 @@ describe("connectionStore metadata loading", () => {
|
||||
expect(store.isTreeNodeChildrenLoaded(test1Id)).toBe(true);
|
||||
});
|
||||
|
||||
it("adds the Xugu user-permissions utility only to Xugu connection roots", async () => {
|
||||
const listDatabases = vi.fn().mockResolvedValue([{ name: "testdb", comment: null }]);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
|
||||
listDatabases,
|
||||
loadSchemaCache: vi.fn().mockResolvedValue(null),
|
||||
saveSchemaCache: vi.fn().mockResolvedValue(undefined),
|
||||
saveConnections: vi.fn().mockResolvedValue(undefined),
|
||||
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
const xugu = xuguConnection();
|
||||
const mysql = mysqlConnection();
|
||||
store.connections = [xugu, mysql];
|
||||
store.connectedIds = new Set([xugu.id, mysql.id]);
|
||||
store.treeNodes = [xugu, mysql].map((connection) => ({
|
||||
id: connection.id,
|
||||
label: connection.name,
|
||||
type: "connection" as const,
|
||||
connectionId: connection.id,
|
||||
isExpanded: false,
|
||||
children: [],
|
||||
}));
|
||||
|
||||
await store.loadDatabases(xugu.id, { connectedOnly: true });
|
||||
await store.loadDatabases(mysql.id, { connectedOnly: true });
|
||||
|
||||
const xuguRoot = store.treeNodes.find((node) => node.connectionId === xugu.id)!;
|
||||
const mysqlRoot = store.treeNodes.find((node) => node.connectionId === mysql.id)!;
|
||||
expect(xuguRoot.children?.filter((node) => node.type === "xugu-user-admin")).toHaveLength(1);
|
||||
expect(mysqlRoot.children?.some((node) => node.type === "xugu-user-admin")).toBe(false);
|
||||
expect(mysqlRoot.children?.some((node) => node.type === "user-admin")).toBe(true);
|
||||
}, 15000);
|
||||
|
||||
it("clears connection loading after disconnect even when metadata apply is skipped", async () => {
|
||||
let resolveDatabases!: (value: { name: string; comment: null }[]) => void;
|
||||
const listDatabases = vi.fn(
|
||||
|
||||
@@ -1823,7 +1823,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
// as metadata children, withConnectionUtilityNodes would keep the old copies
|
||||
// AND append fresh ones on every useCachedChildren pass, duplicating the
|
||||
// 用户/角色 menus once per refresh cycle.
|
||||
return node.type === "oracle-db-links" || node.type === "user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "group-tablespaces" || node.type === "saved-sql-root";
|
||||
return node.type === "oracle-db-links" || node.type === "user-admin" || node.type === "xugu-user-admin" || node.type === "dameng-users" || node.type === "dameng-roles" || node.type === "dameng-job-admin" || node.type === "group-tablespaces" || node.type === "saved-sql-root";
|
||||
}
|
||||
|
||||
function connectionMetadataChildren(children: TreeNode[] | undefined): TreeNode[] {
|
||||
@@ -2091,6 +2091,20 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
};
|
||||
}
|
||||
|
||||
function buildXuguUserAdminNode(connectionId: string, existingConnectionNode?: TreeNode): TreeNode | undefined {
|
||||
const config = getConfig(connectionId);
|
||||
if (effectiveDatabaseTypeForConnection(config) !== "xugu") return undefined;
|
||||
const existing = existingConnectionNode?.children?.find((child) => child.type === "xugu-user-admin");
|
||||
return {
|
||||
id: `${connectionId}:__xugu_user_admin`,
|
||||
label: "tree.xuguUserPermissions",
|
||||
type: "xugu-user-admin",
|
||||
connectionId,
|
||||
database: config?.database || "",
|
||||
isExpanded: existing?.isExpanded ?? false,
|
||||
};
|
||||
}
|
||||
|
||||
function buildDamengUserNode(connectionId: string, existingConnectionNode?: TreeNode): TreeNode | undefined {
|
||||
const config = getConfig(connectionId);
|
||||
if (effectiveDatabaseTypeForConnection(config) !== "dameng") return undefined;
|
||||
@@ -2199,11 +2213,12 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
function withConnectionUtilityNodes(connectionId: string, children: TreeNode[], existingConnectionNode?: TreeNode): TreeNode[] {
|
||||
const nonUtilityChildren = connectionMetadataChildren(children);
|
||||
const userAdminNode = buildUserAdminNode(connectionId, existingConnectionNode);
|
||||
const xuguUserAdminNode = buildXuguUserAdminNode(connectionId, existingConnectionNode);
|
||||
const damengUserNode = buildDamengUserNode(connectionId, existingConnectionNode);
|
||||
const damengRoleNode = buildDamengRoleNode(connectionId, existingConnectionNode);
|
||||
const damengJobAdminNode = buildDamengJobAdminNode(connectionId, existingConnectionNode);
|
||||
const xuguTablespacesNode = buildXuguTablespacesNode(connectionId, existingConnectionNode);
|
||||
return [...nonUtilityChildren, buildOracleDatabaseLinksNode(connectionId, existingConnectionNode), userAdminNode, damengUserNode, damengRoleNode, damengJobAdminNode, xuguTablespacesNode].filter(Boolean) as TreeNode[];
|
||||
return [...nonUtilityChildren, buildOracleDatabaseLinksNode(connectionId, existingConnectionNode), userAdminNode, xuguUserAdminNode, damengUserNode, damengRoleNode, damengJobAdminNode, xuguTablespacesNode].filter(Boolean) as TreeNode[];
|
||||
}
|
||||
|
||||
function withSavedSqlRoot(connectionId: string, children: TreeNode[], existingConnectionNode?: TreeNode): TreeNode[] {
|
||||
|
||||
@@ -3370,6 +3370,29 @@ export const useQueryStore = defineStore("query", () => {
|
||||
return registerOpenTab(tab);
|
||||
}
|
||||
|
||||
function openXuguUserAdmin(connectionId: string) {
|
||||
const existing = tabs.value.find((tab) => tab.mode === "xugu-users" && tab.connectionId === connectionId);
|
||||
if (existing) {
|
||||
switchTab(existing.id);
|
||||
return existing.id;
|
||||
}
|
||||
|
||||
const conn = useConnectionStore().getConfig(connectionId);
|
||||
const id = uuid();
|
||||
const tab: QueryTab = {
|
||||
id,
|
||||
title: t("xuguUserPermissions.title"),
|
||||
connectionId,
|
||||
database: conn?.database || "",
|
||||
sql: "",
|
||||
isExecuting: false,
|
||||
isCancelling: false,
|
||||
isExplaining: false,
|
||||
mode: "xugu-users",
|
||||
};
|
||||
return registerOpenTab(tab);
|
||||
}
|
||||
|
||||
function openProcessList(connectionId: string) {
|
||||
const existing = tabs.value.find((tab) => tab.mode === "processlist" && tab.connectionId === connectionId);
|
||||
if (existing) {
|
||||
@@ -9435,6 +9458,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
openMongoGridFs,
|
||||
openMongoBucket,
|
||||
openUserAdmin,
|
||||
openXuguUserAdmin,
|
||||
openProcessList,
|
||||
openSqlServerActivityTrace,
|
||||
openMysqlDashboard,
|
||||
|
||||
Reference in new issue
Block a user