Skip to content

Commit

Permalink
✨ feat(menu): improve menu permission logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thrownullexception committed Sep 22, 2023
1 parent b7a5989 commit 0d64886
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => ({
Expand All @@ -21,7 +21,7 @@ describe("pages/admin/settings/menu-entities", () => {
it("should display only active entities with correct state", async () => {
render(
<ApplicationRoot>
<MenuEntitiesSettings />
<MenuSettings />
</ApplicationRoot>
);

Expand All @@ -48,7 +48,7 @@ describe("pages/admin/settings/menu-entities", () => {
it("should toggle menu state successfully", async () => {
render(
<ApplicationRoot>
<MenuEntitiesSettings />
<MenuSettings />
</ApplicationRoot>
);

Expand Down Expand Up @@ -80,7 +80,7 @@ describe("pages/admin/settings/menu-entities", () => {
it("should display updated entities state", async () => {
render(
<ApplicationRoot>
<MenuEntitiesSettings />
<MenuSettings />
</ApplicationRoot>
);

Expand Down
14 changes: 3 additions & 11 deletions src/backend/menu/menu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -208,8 +200,8 @@ export class NavigationMenuApiService implements IApplicationService {
userPermissions
);

if (isMenuAllowed) {
return true;
if (typeof isMenuAllowed === "boolean") {
return isMenuAllowed;
}

switch (menuItem.type) {
Expand Down
4 changes: 2 additions & 2 deletions src/backend/menu/portal/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export const portalCheckIfIsMenuAllowed = async (
menuItem: INavigationMenuItem,
userRole: string,
userPermissions: string[]
) => {
): Promise<boolean | undefined> => {
noop(menuItem, userRole, userPermissions);
return false;
return undefined;
};

export const getPortalMenuItems = (
Expand Down

0 comments on commit 0d64886

Please sign in to comment.