From 0d648862a51a6dc7617dc23dd81bbe2dda0d39c8 Mon Sep 17 00:00:00 2001 From: Ayobami Akingbade Date: Fri, 22 Sep 2023 19:02:38 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(menu):=20improve=20menu=20perm?= =?UTF-8?q?ission=20logic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{menu-entities.spec.tsx => menu.spec.tsx} | 10 +++++----- src/backend/menu/menu.service.ts | 14 +++----------- src/backend/menu/portal/main.ts | 4 ++-- 3 files changed, 10 insertions(+), 18 deletions(-) rename src/__tests__/admin/settings/{menu-entities.spec.tsx => menu.spec.tsx} (91%) diff --git a/src/__tests__/admin/settings/menu-entities.spec.tsx b/src/__tests__/admin/settings/menu.spec.tsx similarity index 91% rename from src/__tests__/admin/settings/menu-entities.spec.tsx rename to src/__tests__/admin/settings/menu.spec.tsx index 5da1c74f1..978015f05 100644 --- a/src/__tests__/admin/settings/menu-entities.spec.tsx +++ b/src/__tests__/admin/settings/menu.spec.tsx @@ -3,13 +3,13 @@ import React from "react"; import { render, screen, waitFor } from "@testing-library/react"; import { ApplicationRoot } from "frontend/components/ApplicationRoot"; import userEvent from "@testing-library/user-event"; -import MenuEntitiesSettings from "pages/admin/settings/menu-entities"; +import MenuSettings from "pages/admin/settings/menu"; import { setupApiHandlers } from "__tests__/_/setupApihandlers"; setupApiHandlers(); -describe("pages/admin/settings/menu-entities", () => { +describe("pages/admin/settings/menu", () => { beforeAll(() => { const useRouter = jest.spyOn(require("next/router"), "useRouter"); useRouter.mockImplementation(() => ({ @@ -21,7 +21,7 @@ describe("pages/admin/settings/menu-entities", () => { it("should display only active entities with correct state", async () => { render( - + ); @@ -48,7 +48,7 @@ describe("pages/admin/settings/menu-entities", () => { it("should toggle menu state successfully", async () => { render( - + ); @@ -80,7 +80,7 @@ describe("pages/admin/settings/menu-entities", () => { it("should display updated entities state", async () => { render( - + ); diff --git a/src/backend/menu/menu.service.ts b/src/backend/menu/menu.service.ts index 911aa64fe..c1c22bfb2 100644 --- a/src/backend/menu/menu.service.ts +++ b/src/backend/menu/menu.service.ts @@ -66,14 +66,6 @@ export class NavigationMenuApiService implements IApplicationService { type: NavigationMenuItemType.System, link: SystemLinks.Home, }, - // { - // id: nanoid(), - // title: "Dashboards", - // icon: "PieChart", - // type: NavigationMenuItemType.System, - // link: SystemLinks.AllDashboards, - // children: [], - // }, ]); const entitiesToShow = await this.getUserMenuEntities(); @@ -90,7 +82,7 @@ export class NavigationMenuApiService implements IApplicationService { entitiesToShow.forEach((entity) => { navItems.push({ id: nanoid(), - title: userFriendlyCase(entity.label), // get the current label + title: userFriendlyCase(entity.label), // TODO get the current label icon: "File", type: NavigationMenuItemType.Entities, link: entity.value, @@ -208,8 +200,8 @@ export class NavigationMenuApiService implements IApplicationService { userPermissions ); - if (isMenuAllowed) { - return true; + if (typeof isMenuAllowed === "boolean") { + return isMenuAllowed; } switch (menuItem.type) { diff --git a/src/backend/menu/portal/main.ts b/src/backend/menu/portal/main.ts index 6bb52536b..d9946b45c 100644 --- a/src/backend/menu/portal/main.ts +++ b/src/backend/menu/portal/main.ts @@ -5,9 +5,9 @@ export const portalCheckIfIsMenuAllowed = async ( menuItem: INavigationMenuItem, userRole: string, userPermissions: string[] -) => { +): Promise => { noop(menuItem, userRole, userPermissions); - return false; + return undefined; }; export const getPortalMenuItems = (