mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-14 01:41:22 -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):
|
def register_menu(menu):
|
||||||
if not (isinstance(menu, PluginMenu) or callable(menu)):
|
if not isinstance(menu, PluginMenu):
|
||||||
raise TypeError(_(
|
raise TypeError(_("{item} must be an instance of netbox.plugins.PluginMenuItem").format(item=menu))
|
||||||
"{item} must be an instance of netbox.plugins.PluginMenu "
|
|
||||||
"or a callable returning such an instance").format(item=menu)
|
|
||||||
)
|
|
||||||
registry['plugins']['menus'].append(menu)
|
registry['plugins']['menus'].append(menu)
|
||||||
|
|
||||||
|
|
||||||
@ -59,17 +56,15 @@ def register_menu_items(section_name, class_list):
|
|||||||
"""
|
"""
|
||||||
# Validation
|
# Validation
|
||||||
for menu_link in class_list:
|
for menu_link in class_list:
|
||||||
if not (isinstance(menu_link, PluginMenuItem) or callable(menu_link)):
|
if not isinstance(menu_link, PluginMenuItem):
|
||||||
raise TypeError(_(
|
raise TypeError(_("{menu_link} must be an instance of netbox.plugins.PluginMenuItem").format(
|
||||||
"{menu_link} must be an instance of netbox.plugins.PluginMenuItem "
|
menu_link=menu_link
|
||||||
"or a callable returning such an instance").format(menu_link=menu_link)
|
))
|
||||||
)
|
|
||||||
for button in menu_link.buttons:
|
for button in menu_link.buttons:
|
||||||
if not (isinstance(button, PluginMenuButton) or callable(button)):
|
if not isinstance(button, PluginMenuButton):
|
||||||
raise TypeError(_(
|
raise TypeError(_("{button} must be an instance of netbox.plugins.PluginMenuButton").format(
|
||||||
"{button} must be an instance of netbox.plugins.PluginMenuButton "
|
button=button
|
||||||
"or a callable returning such an instance").format(button=button)
|
))
|
||||||
)
|
|
||||||
|
|
||||||
registry['plugins']['menu_items'][section_name] = class_list
|
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
|
# Construct the navigation menu based upon the current user's permissions
|
||||||
for menu in MENUS:
|
for menu in MENUS:
|
||||||
if callable(menu):
|
|
||||||
menu = menu()
|
|
||||||
groups = []
|
groups = []
|
||||||
for group in menu.groups:
|
for group in menu.groups:
|
||||||
items = []
|
items = []
|
||||||
for item in group.items:
|
for item in group.items:
|
||||||
if callable(item):
|
|
||||||
item = item()
|
|
||||||
if getattr(item, 'auth_required', False) and not user.is_authenticated:
|
if getattr(item, 'auth_required', False) and not user.is_authenticated:
|
||||||
continue
|
continue
|
||||||
if not user.has_perms(item.permissions):
|
if not user.has_perms(item.permissions):
|
||||||
@ -37,9 +33,7 @@ def nav(context):
|
|||||||
if item.staff_only and not user.is_staff:
|
if item.staff_only and not user.is_staff:
|
||||||
continue
|
continue
|
||||||
buttons = [
|
buttons = [
|
||||||
button for button in [
|
button for button in item.buttons if user.has_perms(button.permissions)
|
||||||
button() if callable(button) else button for button in item.buttons
|
|
||||||
] if user.has_perms(button.permissions)
|
|
||||||
]
|
]
|
||||||
items.append((item, buttons))
|
items.append((item, buttons))
|
||||||
if items:
|
if items:
|
||||||
|
Loading…
Reference in New Issue
Block a user