fix: apply pr review

This commit is contained in:
Med Marrouchi 2025-01-20 14:43:11 +01:00 committed by GitHub
parent 20c9a76915
commit ffd4aae3e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View File

@ -14,7 +14,12 @@ import { PermissionAction } from "@/types/permission.types";
import { useHasPermission } from "./useHasPermission"; import { useHasPermission } from "./useHasPermission";
// Helper function to check permissions for a menu item /**
* Helper function to check permissions for a menu item
* @param menuItem - The menu item
* @param hasPermission - Callback function
* @returns True if hasPermission() is true for all required permissions.
*/
const isMenuItemAllowed = ( const isMenuItemAllowed = (
menuItem: MenuItem, menuItem: MenuItem,
hasPermission: (entityType: EntityType, action: PermissionAction) => boolean, hasPermission: (entityType: EntityType, action: PermissionAction) => boolean,
@ -30,6 +35,12 @@ const isMenuItemAllowed = (
) )
); );
}; };
/**
* Filters menu items based on user permissions.
* @param menuItems - The list of menu items to filter.
* @returns A filtered list of menu items that the user is allowed to access.
*/
const filterMenuItems = ( const filterMenuItems = (
menuItems: MenuItem[], menuItems: MenuItem[],
hasPermission: (entityType: EntityType, action: PermissionAction) => boolean, hasPermission: (entityType: EntityType, action: PermissionAction) => boolean,

View File

@ -19,7 +19,7 @@ export const useHasPermission = () => {
(type: EntityType, action: PermissionAction) => { (type: EntityType, action: PermissionAction) => {
const allowedActions = getAllowedActions(type); const allowedActions = getAllowedActions(type);
return allowedActions?.includes(action) ? true : false; return !!allowedActions && allowedActions?.includes(action);
}, },
[getAllowedActions], [getAllowedActions],
); );