feat(frontend): added in checks for links inside the module
This commit is contained in:
@@ -20,7 +20,12 @@ export function AppSidebar() {
|
|||||||
<SidebarContent>
|
<SidebarContent>
|
||||||
<Header />
|
<Header />
|
||||||
{moduleActive("production") && <ProductionSideBar />}
|
{moduleActive("production") && <ProductionSideBar />}
|
||||||
{moduleActive("logistics") && hasAccess(user, "logistics", modules) && <LogisticsSideBar />}
|
{moduleActive("logistics") && (
|
||||||
|
<LogisticsSideBar
|
||||||
|
user={user}
|
||||||
|
moduleID={modules.filter((n) => n.name === "logistics")[0].module_id as string}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{moduleActive("forklift") && hasAccess(user, "forklift", modules) && <ForkliftSideBar />}
|
{moduleActive("forklift") && hasAccess(user, "forklift", modules) && <ForkliftSideBar />}
|
||||||
{moduleActive("eom") && hasAccess(user, "eom", modules) && <EomSideBar />}
|
{moduleActive("eom") && hasAccess(user, "eom", modules) && <EomSideBar />}
|
||||||
{moduleActive("quality") && hasAccess(user, "quality", modules) && <QualitySideBar />}
|
{moduleActive("quality") && hasAccess(user, "quality", modules) && <QualitySideBar />}
|
||||||
|
|||||||
@@ -7,35 +7,45 @@ import {
|
|||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
SidebarMenuItem,
|
SidebarMenuItem,
|
||||||
} from "../../ui/sidebar";
|
} from "../../ui/sidebar";
|
||||||
|
import {hasPageAccess} from "@/utils/userAccess";
|
||||||
|
import {User} from "@/types/users";
|
||||||
|
// this will need to be moved to a links section the db to make it more easy to remove and add
|
||||||
const items = [
|
const items = [
|
||||||
{
|
{
|
||||||
title: "Silo Adjustments",
|
title: "Silo Adjustments",
|
||||||
url: "#",
|
url: "#",
|
||||||
icon: Cylinder,
|
icon: Cylinder,
|
||||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
module: "logistics",
|
||||||
|
active: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Bulk orders",
|
title: "Bulk orders",
|
||||||
url: "#",
|
url: "#",
|
||||||
icon: Truck,
|
icon: Truck,
|
||||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
module: "logistics",
|
||||||
|
active: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Forecast",
|
title: "Forecast",
|
||||||
url: "#",
|
url: "#",
|
||||||
icon: Truck,
|
icon: Truck,
|
||||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
module: "logistics",
|
||||||
|
active: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: "Ocme cycle counts",
|
title: "Ocme cycle counts",
|
||||||
url: "#",
|
url: "#",
|
||||||
icon: Package,
|
icon: Package,
|
||||||
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
role: ["technician", "supervisor", "manager", "admin", "systemAdmin"],
|
||||||
|
module: "logistics",
|
||||||
|
active: false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function LogisticsSideBar() {
|
export function LogisticsSideBar({user, moduleID}: {user: User | null; moduleID: string}) {
|
||||||
return (
|
return (
|
||||||
<SidebarGroup>
|
<SidebarGroup>
|
||||||
<SidebarGroupLabel>Logistics</SidebarGroupLabel>
|
<SidebarGroupLabel>Logistics</SidebarGroupLabel>
|
||||||
@@ -43,12 +53,16 @@ export function LogisticsSideBar() {
|
|||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{items.map((item) => (
|
{items.map((item) => (
|
||||||
<SidebarMenuItem key={item.title}>
|
<SidebarMenuItem key={item.title}>
|
||||||
|
<>
|
||||||
|
{hasPageAccess(user, item.role, moduleID) && item.active && (
|
||||||
<SidebarMenuButton asChild>
|
<SidebarMenuButton asChild>
|
||||||
<a href={item.url}>
|
<a href={item.url}>
|
||||||
<item.icon />
|
<item.icon />
|
||||||
<span>{item.title}</span>
|
<span>{item.title}</span>
|
||||||
</a>
|
</a>
|
||||||
</SidebarMenuButton>
|
</SidebarMenuButton>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
</SidebarMenuItem>
|
</SidebarMenuItem>
|
||||||
))}
|
))}
|
||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
|
|||||||
@@ -23,7 +23,10 @@ import { Route as EomEomImport } from './routes/_eom/eom'
|
|||||||
import { Route as AuthProfileImport } from './routes/_auth/profile'
|
import { Route as AuthProfileImport } from './routes/_auth/profile'
|
||||||
import { Route as AdminSettingsImport } from './routes/_admin/settings'
|
import { Route as AdminSettingsImport } from './routes/_admin/settings'
|
||||||
import { Route as AdminModulesImport } from './routes/_admin/modules'
|
import { Route as AdminModulesImport } from './routes/_admin/modules'
|
||||||
|
import { Route as logisticsMaterialHelperIndexImport } from './routes/(logistics)/materialHelper/index'
|
||||||
import { Route as EomArticleAvImport } from './routes/_eom/article/$av'
|
import { Route as EomArticleAvImport } from './routes/_eom/article/$av'
|
||||||
|
import { Route as logisticsMaterialHelperSiloLinkIndexImport } from './routes/(logistics)/materialHelper/siloLink/index'
|
||||||
|
import { Route as logisticsMaterialHelperConsumptionIndexImport } from './routes/(logistics)/materialHelper/consumption/index'
|
||||||
|
|
||||||
// Create/Update Routes
|
// Create/Update Routes
|
||||||
|
|
||||||
@@ -96,12 +99,33 @@ const AdminModulesRoute = AdminModulesImport.update({
|
|||||||
getParentRoute: () => AdminRoute,
|
getParentRoute: () => AdminRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
|
const logisticsMaterialHelperIndexRoute =
|
||||||
|
logisticsMaterialHelperIndexImport.update({
|
||||||
|
id: '/(logistics)/materialHelper/',
|
||||||
|
path: '/materialHelper/',
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
const EomArticleAvRoute = EomArticleAvImport.update({
|
const EomArticleAvRoute = EomArticleAvImport.update({
|
||||||
id: '/article/$av',
|
id: '/article/$av',
|
||||||
path: '/article/$av',
|
path: '/article/$av',
|
||||||
getParentRoute: () => EomRoute,
|
getParentRoute: () => EomRoute,
|
||||||
} as any)
|
} as any)
|
||||||
|
|
||||||
|
const logisticsMaterialHelperSiloLinkIndexRoute =
|
||||||
|
logisticsMaterialHelperSiloLinkIndexImport.update({
|
||||||
|
id: '/(logistics)/materialHelper/siloLink/',
|
||||||
|
path: '/materialHelper/siloLink/',
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
const logisticsMaterialHelperConsumptionIndexRoute =
|
||||||
|
logisticsMaterialHelperConsumptionIndexImport.update({
|
||||||
|
id: '/(logistics)/materialHelper/consumption/',
|
||||||
|
path: '/materialHelper/consumption/',
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
} as any)
|
||||||
|
|
||||||
// Populate the FileRoutesByPath interface
|
// Populate the FileRoutesByPath interface
|
||||||
|
|
||||||
declare module '@tanstack/react-router' {
|
declare module '@tanstack/react-router' {
|
||||||
@@ -197,6 +221,27 @@ declare module '@tanstack/react-router' {
|
|||||||
preLoaderRoute: typeof EomArticleAvImport
|
preLoaderRoute: typeof EomArticleAvImport
|
||||||
parentRoute: typeof EomImport
|
parentRoute: typeof EomImport
|
||||||
}
|
}
|
||||||
|
'/(logistics)/materialHelper/': {
|
||||||
|
id: '/(logistics)/materialHelper/'
|
||||||
|
path: '/materialHelper'
|
||||||
|
fullPath: '/materialHelper'
|
||||||
|
preLoaderRoute: typeof logisticsMaterialHelperIndexImport
|
||||||
|
parentRoute: typeof rootRoute
|
||||||
|
}
|
||||||
|
'/(logistics)/materialHelper/consumption/': {
|
||||||
|
id: '/(logistics)/materialHelper/consumption/'
|
||||||
|
path: '/materialHelper/consumption'
|
||||||
|
fullPath: '/materialHelper/consumption'
|
||||||
|
preLoaderRoute: typeof logisticsMaterialHelperConsumptionIndexImport
|
||||||
|
parentRoute: typeof rootRoute
|
||||||
|
}
|
||||||
|
'/(logistics)/materialHelper/siloLink/': {
|
||||||
|
id: '/(logistics)/materialHelper/siloLink/'
|
||||||
|
path: '/materialHelper/siloLink'
|
||||||
|
fullPath: '/materialHelper/siloLink'
|
||||||
|
preLoaderRoute: typeof logisticsMaterialHelperSiloLinkIndexImport
|
||||||
|
parentRoute: typeof rootRoute
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +293,9 @@ export interface FileRoutesByFullPath {
|
|||||||
'/ocp/lots': typeof OcpLotsRoute
|
'/ocp/lots': typeof OcpLotsRoute
|
||||||
'/ocp': typeof OcpIndexRoute
|
'/ocp': typeof OcpIndexRoute
|
||||||
'/article/$av': typeof EomArticleAvRoute
|
'/article/$av': typeof EomArticleAvRoute
|
||||||
|
'/materialHelper': typeof logisticsMaterialHelperIndexRoute
|
||||||
|
'/materialHelper/consumption': typeof logisticsMaterialHelperConsumptionIndexRoute
|
||||||
|
'/materialHelper/siloLink': typeof logisticsMaterialHelperSiloLinkIndexRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRoutesByTo {
|
export interface FileRoutesByTo {
|
||||||
@@ -262,6 +310,9 @@ export interface FileRoutesByTo {
|
|||||||
'/ocp/lots': typeof OcpLotsRoute
|
'/ocp/lots': typeof OcpLotsRoute
|
||||||
'/ocp': typeof OcpIndexRoute
|
'/ocp': typeof OcpIndexRoute
|
||||||
'/article/$av': typeof EomArticleAvRoute
|
'/article/$av': typeof EomArticleAvRoute
|
||||||
|
'/materialHelper': typeof logisticsMaterialHelperIndexRoute
|
||||||
|
'/materialHelper/consumption': typeof logisticsMaterialHelperConsumptionIndexRoute
|
||||||
|
'/materialHelper/siloLink': typeof logisticsMaterialHelperSiloLinkIndexRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRoutesById {
|
export interface FileRoutesById {
|
||||||
@@ -279,6 +330,9 @@ export interface FileRoutesById {
|
|||||||
'/ocp/lots': typeof OcpLotsRoute
|
'/ocp/lots': typeof OcpLotsRoute
|
||||||
'/ocp/': typeof OcpIndexRoute
|
'/ocp/': typeof OcpIndexRoute
|
||||||
'/_eom/article/$av': typeof EomArticleAvRoute
|
'/_eom/article/$av': typeof EomArticleAvRoute
|
||||||
|
'/(logistics)/materialHelper/': typeof logisticsMaterialHelperIndexRoute
|
||||||
|
'/(logistics)/materialHelper/consumption/': typeof logisticsMaterialHelperConsumptionIndexRoute
|
||||||
|
'/(logistics)/materialHelper/siloLink/': typeof logisticsMaterialHelperSiloLinkIndexRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileRouteTypes {
|
export interface FileRouteTypes {
|
||||||
@@ -295,6 +349,9 @@ export interface FileRouteTypes {
|
|||||||
| '/ocp/lots'
|
| '/ocp/lots'
|
||||||
| '/ocp'
|
| '/ocp'
|
||||||
| '/article/$av'
|
| '/article/$av'
|
||||||
|
| '/materialHelper'
|
||||||
|
| '/materialHelper/consumption'
|
||||||
|
| '/materialHelper/siloLink'
|
||||||
fileRoutesByTo: FileRoutesByTo
|
fileRoutesByTo: FileRoutesByTo
|
||||||
to:
|
to:
|
||||||
| '/'
|
| '/'
|
||||||
@@ -308,6 +365,9 @@ export interface FileRouteTypes {
|
|||||||
| '/ocp/lots'
|
| '/ocp/lots'
|
||||||
| '/ocp'
|
| '/ocp'
|
||||||
| '/article/$av'
|
| '/article/$av'
|
||||||
|
| '/materialHelper'
|
||||||
|
| '/materialHelper/consumption'
|
||||||
|
| '/materialHelper/siloLink'
|
||||||
id:
|
id:
|
||||||
| '__root__'
|
| '__root__'
|
||||||
| '/'
|
| '/'
|
||||||
@@ -323,6 +383,9 @@ export interface FileRouteTypes {
|
|||||||
| '/ocp/lots'
|
| '/ocp/lots'
|
||||||
| '/ocp/'
|
| '/ocp/'
|
||||||
| '/_eom/article/$av'
|
| '/_eom/article/$av'
|
||||||
|
| '/(logistics)/materialHelper/'
|
||||||
|
| '/(logistics)/materialHelper/consumption/'
|
||||||
|
| '/(logistics)/materialHelper/siloLink/'
|
||||||
fileRoutesById: FileRoutesById
|
fileRoutesById: FileRoutesById
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,6 +398,9 @@ export interface RootRouteChildren {
|
|||||||
LoginRoute: typeof LoginRoute
|
LoginRoute: typeof LoginRoute
|
||||||
OcpLotsRoute: typeof OcpLotsRoute
|
OcpLotsRoute: typeof OcpLotsRoute
|
||||||
OcpIndexRoute: typeof OcpIndexRoute
|
OcpIndexRoute: typeof OcpIndexRoute
|
||||||
|
logisticsMaterialHelperIndexRoute: typeof logisticsMaterialHelperIndexRoute
|
||||||
|
logisticsMaterialHelperConsumptionIndexRoute: typeof logisticsMaterialHelperConsumptionIndexRoute
|
||||||
|
logisticsMaterialHelperSiloLinkIndexRoute: typeof logisticsMaterialHelperSiloLinkIndexRoute
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootRouteChildren: RootRouteChildren = {
|
const rootRouteChildren: RootRouteChildren = {
|
||||||
@@ -346,6 +412,11 @@ const rootRouteChildren: RootRouteChildren = {
|
|||||||
LoginRoute: LoginRoute,
|
LoginRoute: LoginRoute,
|
||||||
OcpLotsRoute: OcpLotsRoute,
|
OcpLotsRoute: OcpLotsRoute,
|
||||||
OcpIndexRoute: OcpIndexRoute,
|
OcpIndexRoute: OcpIndexRoute,
|
||||||
|
logisticsMaterialHelperIndexRoute: logisticsMaterialHelperIndexRoute,
|
||||||
|
logisticsMaterialHelperConsumptionIndexRoute:
|
||||||
|
logisticsMaterialHelperConsumptionIndexRoute,
|
||||||
|
logisticsMaterialHelperSiloLinkIndexRoute:
|
||||||
|
logisticsMaterialHelperSiloLinkIndexRoute,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const routeTree = rootRoute
|
export const routeTree = rootRoute
|
||||||
@@ -365,7 +436,10 @@ export const routeTree = rootRoute
|
|||||||
"/about",
|
"/about",
|
||||||
"/login",
|
"/login",
|
||||||
"/ocp/lots",
|
"/ocp/lots",
|
||||||
"/ocp/"
|
"/ocp/",
|
||||||
|
"/(logistics)/materialHelper/",
|
||||||
|
"/(logistics)/materialHelper/consumption/",
|
||||||
|
"/(logistics)/materialHelper/siloLink/"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"/": {
|
"/": {
|
||||||
@@ -422,6 +496,15 @@ export const routeTree = rootRoute
|
|||||||
"/_eom/article/$av": {
|
"/_eom/article/$av": {
|
||||||
"filePath": "_eom/article/$av.tsx",
|
"filePath": "_eom/article/$av.tsx",
|
||||||
"parent": "/_eom"
|
"parent": "/_eom"
|
||||||
|
},
|
||||||
|
"/(logistics)/materialHelper/": {
|
||||||
|
"filePath": "(logistics)/materialHelper/index.tsx"
|
||||||
|
},
|
||||||
|
"/(logistics)/materialHelper/consumption/": {
|
||||||
|
"filePath": "(logistics)/materialHelper/consumption/index.tsx"
|
||||||
|
},
|
||||||
|
"/(logistics)/materialHelper/siloLink/": {
|
||||||
|
"filePath": "(logistics)/materialHelper/siloLink/index.tsx"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
import {Modules} from "@/types/modules";
|
import {Modules} from "@/types/modules";
|
||||||
|
import {User} from "@/types/users";
|
||||||
type User = {
|
|
||||||
user_id: string;
|
|
||||||
email: string;
|
|
||||||
username: string;
|
|
||||||
roles: Roles[];
|
|
||||||
role: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
interface Roles {
|
|
||||||
role: string;
|
|
||||||
module_id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
// user will need access to the module.
|
// user will need access to the module.
|
||||||
// users role will determine there visual access
|
// users role will determine there visual access
|
||||||
@@ -23,3 +11,16 @@ export function hasAccess(user: User | null, moduleName: string | null, modules:
|
|||||||
|
|
||||||
return user?.roles.find((role) => role.module_id === filteredModule[0].module_id) ? true : false;
|
return user?.roles.find((role) => role.module_id === filteredModule[0].module_id) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function hasPageAccess(user: User | null, role: any, module_id: string): boolean {
|
||||||
|
if (!user) return false;
|
||||||
|
|
||||||
|
// get only the module in the user profile
|
||||||
|
const userRole = user?.roles.filter((role) => role.module_id === module_id);
|
||||||
|
|
||||||
|
if (role.includes(userRole[0].role)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user