From d7a0e7191c939f226c9df959ced4a7b5cefc5247 Mon Sep 17 00:00:00 2001 From: weareoutman Date: Sun, 8 Oct 2023 12:01:49 +0800 Subject: [PATCH] fix(): fix permissions check within dynamic menu --- packages/brick-kit/src/internal/menu.spec.ts | 4 +++- packages/brick-kit/src/internal/menu.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/brick-kit/src/internal/menu.spec.ts b/packages/brick-kit/src/internal/menu.spec.ts index 4d271beaf9..8d934c1d3c 100644 --- a/packages/brick-kit/src/internal/menu.spec.ts +++ b/packages/brick-kit/src/internal/menu.spec.ts @@ -366,7 +366,7 @@ const mockMenuList: any[] = [ title: "Menu i", dynamicItems: true, itemsResolve: { - args: ["<% PATH.objectId %>"], + args: ["<% PATH.objectId %>", "<% PERMISSIONS.check('x:y') %>"], useProvider: "my.fake-provider", }, items: [ @@ -472,6 +472,8 @@ describe("fetchMenuById", () => { it("menu should not cache cache", async () => { await fetchMenuById("menu-i", fakeKernel); expect(InstanceApi_postSearch).toHaveBeenCalledTimes(1); + expect(validatePermissions).toBeCalledTimes(1); + expect(validatePermissions).toBeCalledWith(["x:y"]); await fetchMenuById("menu-i", fakeKernel); expect(InstanceApi_postSearch).toHaveBeenCalledTimes(2); }); diff --git a/packages/brick-kit/src/internal/menu.ts b/packages/brick-kit/src/internal/menu.ts index e56714685d..8fe7cd9a6c 100644 --- a/packages/brick-kit/src/internal/menu.ts +++ b/packages/brick-kit/src/internal/menu.ts @@ -302,6 +302,10 @@ async function loadDynamicMenuItems( }; } } + + const usedActions = scanPermissionActionsInAny(menu.itemsResolve); + await validatePermissions(usedActions); + await _internalApiGetResolver().resolveOne( "reference", {