mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 10:35:37 +00:00
fix: apply pr review
This commit is contained in:
parent
20c9a76915
commit
ffd4aae3e0
@ -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,
|
||||||
|
@ -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],
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user