mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 09:35:44 +00:00
fix: the position based gl gate on sidbear
This commit is contained in:
@@ -40,8 +40,6 @@ import type { SidebarItem, SidebarSection } from "./types";
|
|||||||
import {
|
import {
|
||||||
FREIGHT_PERMS,
|
FREIGHT_PERMS,
|
||||||
hasPermission as hasFreightPermission,
|
hasPermission as hasFreightPermission,
|
||||||
isDjiboutiGl,
|
|
||||||
isEthiopianGl,
|
|
||||||
isSuperAdmin,
|
isSuperAdmin,
|
||||||
} from "@/lib/permissions";
|
} from "@/lib/permissions";
|
||||||
import { getCategorySidebarChildren } from "@/pages/ruleEngine/config/resources";
|
import { getCategorySidebarChildren } from "@/pages/ruleEngine/config/resources";
|
||||||
@@ -554,38 +552,10 @@ export const buildSidebarSections = (demoItems: SidebarItem[]): SidebarSection[]
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/** Hrefs of the two document-clearance menu items (stable identifiers). */
|
|
||||||
export const ET_CLEARANCE_HREF = "/dashboard/contracts/clearance";
|
|
||||||
export const DJ_CLEARANCE_HREF = "/dashboard/gl-djibouti/clearance";
|
|
||||||
|
|
||||||
// Routes a GL officer may reach beyond their clearance hub. Path B booking is
|
|
||||||
// part of their job (create/rebook under a cleared contract, then view that
|
|
||||||
// booking's clearance), but those routes live outside the clearance prefix —
|
|
||||||
// without this allowlist the single-prefix lock bounces them out of their own
|
|
||||||
// workflow. Matched against location.pathname (no query string).
|
|
||||||
export const GL_WORKFLOW_PATH_PATTERNS: RegExp[] = [
|
|
||||||
/^\/dashboard\/contracts\/[^/]+\/create-booking(\/|$)/,
|
|
||||||
/^\/dashboard\/bookings\/[^/]+\/clearance(\/|$)/,
|
|
||||||
// The ET hub's rows open the shipment clearance detail at this URL.
|
|
||||||
/^\/dashboard\/clearance\/[^/]+(\/|$)/,
|
|
||||||
];
|
|
||||||
|
|
||||||
const isEtClearanceItem = (item: SidebarItem): boolean =>
|
|
||||||
item.href === ET_CLEARANCE_HREF;
|
|
||||||
const isDjClearanceItem = (item: SidebarItem): boolean =>
|
|
||||||
item.href === DJ_CLEARANCE_HREF;
|
|
||||||
const isClearanceItem = (item: SidebarItem): boolean =>
|
|
||||||
isEtClearanceItem(item) || isDjClearanceItem(item);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep only items the user is permitted to see; drop now-empty sections.
|
* Keep only items the user is permitted to see; drop now-empty sections.
|
||||||
*
|
* Super Admin sees everything; everyone else is filtered purely by each
|
||||||
* Position-scoped visibility (super_admin sees everything):
|
* item's `permission` field (OR across the array when one is given).
|
||||||
* - Super Admin → sees all items (all permissions pass, all tabs visible)
|
|
||||||
* - Ethiopian GL → sees ONLY the ET document-clearance page.
|
|
||||||
* - Djibouti GL → sees ONLY the DJ clearance page.
|
|
||||||
* - Everyone else → sees everything they have permission for, EXCEPT the two
|
|
||||||
* clearance pages (those are GL-only).
|
|
||||||
*/
|
*/
|
||||||
export const filterSidebarByPermission = (
|
export const filterSidebarByPermission = (
|
||||||
sections: SidebarSection[],
|
sections: SidebarSection[],
|
||||||
@@ -594,9 +564,6 @@ export const filterSidebarByPermission = (
|
|||||||
// Superadmin sees every section and item — no permission filtering.
|
// Superadmin sees every section and item — no permission filtering.
|
||||||
if (isSuperAdmin(user)) return sections;
|
if (isSuperAdmin(user)) return sections;
|
||||||
|
|
||||||
const etGl = isEthiopianGl(user);
|
|
||||||
const djGl = isDjiboutiGl(user);
|
|
||||||
|
|
||||||
const permissionAllowed = (item: SidebarItem): boolean => {
|
const permissionAllowed = (item: SidebarItem): boolean => {
|
||||||
if (!item.permission) return true;
|
if (!item.permission) return true;
|
||||||
const keys = Array.isArray(item.permission)
|
const keys = Array.isArray(item.permission)
|
||||||
@@ -616,14 +583,6 @@ export const filterSidebarByPermission = (
|
|||||||
: item,
|
: item,
|
||||||
)
|
)
|
||||||
.filter((item) => {
|
.filter((item) => {
|
||||||
if (etGl || djGl) {
|
|
||||||
// GL positions are locked to their single clearance page (parents
|
|
||||||
// survive only as the path to that page).
|
|
||||||
const isTarget = etGl ? isEtClearanceItem : isDjClearanceItem;
|
|
||||||
return isTarget(item) || (item.children?.length ?? 0) > 0;
|
|
||||||
}
|
|
||||||
// Everyone else: hide the GL-only clearance pages entirely.
|
|
||||||
if (isClearanceItem(item)) return false;
|
|
||||||
if (!permissionAllowed(item)) return false;
|
if (!permissionAllowed(item)) return false;
|
||||||
if (item.children) return item.children.length > 0;
|
if (item.children) return item.children.length > 0;
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user