diff --git a/client/src/services/AuthService.js b/client/src/services/AuthService.js index dd165d7..8f2c95f 100644 --- a/client/src/services/AuthService.js +++ b/client/src/services/AuthService.js @@ -29,6 +29,8 @@ const getCurrentPermissions = () => { const SYSTEM_ACCESS_PERMISSION = 'System Access'; const DRIVER_BYPASS_PERMISSION = 'isDriver'; const SYSTEM_ACCESS_BYPASS_USERS = new Set(['testadmin03']); +const getPermissionSet = () => new Set(getCurrentPermissions()); +const hasRawPermission = (permissionKey) => getPermissionSet().has(permissionKey); const isSystemAccessBypassUser = () => { const user = getCurrentUser(); @@ -44,14 +46,13 @@ const isSystemAccessBypassUser = () => { }; const hasSystemAccess = () => { - return isSystemAccessBypassUser() || getCurrentPermissions().includes(SYSTEM_ACCESS_PERMISSION); + return isSystemAccessBypassUser() || hasRawPermission(SYSTEM_ACCESS_PERMISSION); }; const hasPermission = (permissionKey) => { if (!permissionKey) return false; - const permissionSet = new Set(getCurrentPermissions()); if (permissionKey === DRIVER_BYPASS_PERMISSION) { - return permissionSet.has(DRIVER_BYPASS_PERMISSION); + return hasRawPermission(DRIVER_BYPASS_PERMISSION); } if (permissionKey === SYSTEM_ACCESS_PERMISSION) { return hasSystemAccess(); @@ -59,16 +60,17 @@ const hasPermission = (permissionKey) => { if (!hasSystemAccess()) { return false; } - return permissionSet.has(permissionKey); + return hasRawPermission(permissionKey); }; const hasAnyPermission = (permissionKeys = []) => { if (!Array.isArray(permissionKeys) || permissionKeys.length === 0) return false; - const permissionSet = new Set(getCurrentPermissions()); if (!hasSystemAccess()) { - return permissionKeys.some((permissionKey) => permissionKey === DRIVER_BYPASS_PERMISSION && permissionSet.has(DRIVER_BYPASS_PERMISSION)); + return permissionKeys.some((permissionKey) => permissionKey === DRIVER_BYPASS_PERMISSION && hasRawPermission(DRIVER_BYPASS_PERMISSION)); } - return permissionKeys.some((permissionKey) => permissionSet.has(permissionKey)); + return permissionKeys + .filter((permissionKey) => permissionKey && permissionKey !== SYSTEM_ACCESS_PERMISSION) + .some((permissionKey) => hasRawPermission(permissionKey)); }; const CUSTOMER_VIEW_TAB_PERMISSION_MAP = {