mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-13 08:44:51 -06:00
Back out support for callables but keep alternate prerendered url param
This commit is contained in:
parent
aa4533e331
commit
7338898ccb
@ -45,11 +45,8 @@ def register_template_extensions(class_list):
|
||||
|
||||
|
||||
def register_menu(menu):
|
||||
if not (isinstance(menu, PluginMenu) or callable(menu)):
|
||||
raise TypeError(_(
|
||||
"{item} must be an instance of netbox.plugins.PluginMenu "
|
||||
"or a callable returning such an instance").format(item=menu)
|
||||
)
|
||||
if not isinstance(menu, PluginMenu):
|
||||
raise TypeError(_("{item} must be an instance of netbox.plugins.PluginMenuItem").format(item=menu))
|
||||
registry['plugins']['menus'].append(menu)
|
||||
|
||||
|
||||
@ -59,17 +56,15 @@ def register_menu_items(section_name, class_list):
|
||||
"""
|
||||
# Validation
|
||||
for menu_link in class_list:
|
||||
if not (isinstance(menu_link, PluginMenuItem) or callable(menu_link)):
|
||||
raise TypeError(_(
|
||||
"{menu_link} must be an instance of netbox.plugins.PluginMenuItem "
|
||||
"or a callable returning such an instance").format(menu_link=menu_link)
|
||||
)
|
||||
if not isinstance(menu_link, PluginMenuItem):
|
||||
raise TypeError(_("{menu_link} must be an instance of netbox.plugins.PluginMenuItem").format(
|
||||
menu_link=menu_link
|
||||
))
|
||||
for button in menu_link.buttons:
|
||||
if not (isinstance(button, PluginMenuButton) or callable(button)):
|
||||
raise TypeError(_(
|
||||
"{button} must be an instance of netbox.plugins.PluginMenuButton "
|
||||
"or a callable returning such an instance").format(button=button)
|
||||
)
|
||||
if not isinstance(button, PluginMenuButton):
|
||||
raise TypeError(_("{button} must be an instance of netbox.plugins.PluginMenuButton").format(
|
||||
button=button
|
||||
))
|
||||
|
||||
registry['plugins']['menu_items'][section_name] = class_list
|
||||
|
||||
|
@ -22,14 +22,10 @@ def nav(context):
|
||||
|
||||
# Construct the navigation menu based upon the current user's permissions
|
||||
for menu in MENUS:
|
||||
if callable(menu):
|
||||
menu = menu()
|
||||
groups = []
|
||||
for group in menu.groups:
|
||||
items = []
|
||||
for item in group.items:
|
||||
if callable(item):
|
||||
item = item()
|
||||
if getattr(item, 'auth_required', False) and not user.is_authenticated:
|
||||
continue
|
||||
if not user.has_perms(item.permissions):
|
||||
@ -37,9 +33,7 @@ def nav(context):
|
||||
if item.staff_only and not user.is_staff:
|
||||
continue
|
||||
buttons = [
|
||||
button for button in [
|
||||
button() if callable(button) else button for button in item.buttons
|
||||
] if user.has_perms(button.permissions)
|
||||
button for button in item.buttons if user.has_perms(button.permissions)
|
||||
]
|
||||
items.append((item, buttons))
|
||||
if items:
|
||||
|
Loading…
Reference in New Issue
Block a user