Skip to content

Commit

Permalink
fix(): fix permissions check within dynamic menu
Browse files Browse the repository at this point in the history
  • Loading branch information
weareoutman committed Oct 8, 2023
1 parent 47ef7fa commit d7a0e71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/brick-kit/src/internal/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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);
});
Expand Down
4 changes: 4 additions & 0 deletions packages/brick-kit/src/internal/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,10 @@ async function loadDynamicMenuItems(
};
}
}

const usedActions = scanPermissionActionsInAny(menu.itemsResolve);
await validatePermissions(usedActions);

await _internalApiGetResolver().resolveOne(
"reference",
{
Expand Down

0 comments on commit d7a0e71

Please sign in to comment.