You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
736 B
JavaScript

1 year ago
export const filterOpenMenu = (user, item) => {
const isAdmin = user.role === null
1 year ago
if ('items' in item) {
let items = []
if (isAdmin) {
items = item.items
} else {
items = item.items.filter((item) =>
user.role.permissions.find((p) => p.name === item.permission)
? item
: null
)
1 year ago
}
if (items.length > 0) {
let activeItem = items.map((item) => route().current(item.active))
1 year ago
item.open = activeItem.includes(true)
item.items = items.filter((item) => (item.show ? item : null))
1 year ago
return item
}
}
if (isAdmin) {
return item
}
}