修改后台菜单逻辑,默认显示用户全部可见菜单
This commit is contained in:
@@ -25,7 +25,34 @@ async def public_list_menu_configs(
|
||||
)
|
||||
.order_by(MenuConfig.sort_order)
|
||||
)
|
||||
menus = result.scalars().all()
|
||||
all_menus = result.scalars().all()
|
||||
|
||||
# Filter menus based on user permissions
|
||||
# If user has allowed_menus set, show only those menus
|
||||
# Otherwise, show all default menus (is_default=True)
|
||||
user_allowed_paths = set(current_user.allowed_menus or [])
|
||||
|
||||
if user_allowed_paths:
|
||||
# User has explicit menu permissions - show only allowed menus
|
||||
allowed_ids = set()
|
||||
for menu in all_menus:
|
||||
if menu.path in user_allowed_paths:
|
||||
allowed_ids.add(menu.id)
|
||||
if menu.parent_id:
|
||||
allowed_ids.add(menu.parent_id)
|
||||
|
||||
menus = [m for m in all_menus if m.id in allowed_ids]
|
||||
else:
|
||||
# No explicit permissions - show default menus
|
||||
default_ids = set()
|
||||
for menu in all_menus:
|
||||
if menu.is_default:
|
||||
default_ids.add(menu.id)
|
||||
if menu.parent_id:
|
||||
default_ids.add(menu.parent_id)
|
||||
|
||||
menus = [m for m in all_menus if m.id in default_ids]
|
||||
|
||||
return [
|
||||
{
|
||||
"id": m.id, "label": m.label, "path": m.path, "icon": m.icon,
|
||||
|
||||
Reference in New Issue
Block a user