diff --git a/docs/plugins/development.md b/docs/plugins/development.md index b48a329fb..402c047e6 100644 --- a/docs/plugins/development.md +++ b/docs/plugins/development.md @@ -305,17 +305,16 @@ A `PluginMenuItem` has the following attributes: * `link` - The name of the URL path to which this menu item links * `link_text` - The text presented to the user -* `permission` - The name of the permission required to display this link (optional) +* `permissions` - A list of permissions required to display this link (optional) * `buttons` - An iterable of PluginMenuButton instances to display (optional) - A `PluginMenuButton` has the following attributes: * `link` - The name of the URL path to which this button links * `title` - The tooltip text (displayed when the mouse hovers over the button) * `icon_class` - Button icon CSS class * `color` - One of the choices provided by `ButtonColorChoices` (optional) -* `permission` - The name of the permission required to display this button (optional) +* `permissions` - A list of permissions required to display this button (optional) ## Extending Core Templates diff --git a/netbox/extras/plugins/__init__.py b/netbox/extras/plugins/__init__.py index dbfee45e4..bcd57d767 100644 --- a/netbox/extras/plugins/__init__.py +++ b/netbox/extras/plugins/__init__.py @@ -160,13 +160,17 @@ class PluginMenuItem: Links are specified as Django reverse URL strings. Buttons are each specified as a list of PluginMenuButton instances. """ - def __init__(self, link, link_text, permission=None, buttons=None): + permissions = [] + buttons = [] + + def __init__(self, link, link_text, permissions=None, buttons=None): self.link = link self.link_text = link_text - self.permission = permission - if buttons is None: - self.buttons = [] - else: + if permissions is not None: + if type(permissions) not in (list, tuple): + raise TypeError("Permissions must be passed as a tuple or list.") + self.permissions = permissions + if buttons is not None: self.buttons = buttons @@ -176,13 +180,16 @@ class PluginMenuButton: ButtonColorChoices. """ color = ButtonColorChoices.DEFAULT + permissions = [] - def __init__(self, link, title, icon_class, color=None, permission=None): + def __init__(self, link, title, icon_class, color=None, permissions=None): self.link = link self.title = title self.icon_class = icon_class - self.permission = permission - + if permissions is not None: + if type(permissions) not in (list, tuple): + raise TypeError("Permissions must be passed as a tuple or list.") + self.permissions = permissions if color is not None: self.color = color diff --git a/netbox/templates/inc/plugin_menu_items.html b/netbox/templates/inc/plugin_menu_items.html index 5639d39c7..0ba10bd20 100644 --- a/netbox/templates/inc/plugin_menu_items.html +++ b/netbox/templates/inc/plugin_menu_items.html @@ -1,25 +1,22 @@ +{% load helpers %}