This commit is contained in:
2026-06-26 09:20:50 +08:00
parent 4efb360b93
commit 6fcc3f8a0c
4 changed files with 26 additions and 45 deletions
+17 -22
View File
@@ -28,30 +28,25 @@ async def public_list_menu_configs(
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)
# Show default menus + user-specific allowed menus (merged)
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]
# Start with default menus
allowed_ids = set()
for menu in all_menus:
if menu.is_default:
allowed_ids.add(menu.id)
if menu.parent_id:
allowed_ids.add(menu.parent_id)
# Add user-specific allowed menus (merge with defaults)
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]
return [
{