Răsfoiți Sursa

Fixes #5046: Disabled plugin menu items are no longer clickable

Jeremy Stretch 5 ani în urmă
părinte
comite
78d104e60c

+ 3 - 0
docs/plugins/development.md

@@ -328,6 +328,9 @@ A `PluginMenuButton` has the following attributes:
 * `color` - One of the choices provided by `ButtonColorChoices` (optional)
 * `permissions` - A list of permissions required to display this button (optional)
 
+!!! note
+    Any buttons associated within a menu item will be shown only if the user has permission to view the link, regardless of what permissions are set on the buttons.
+
 ## Extending Core Templates
 
 Plugins can inject custom content into certain areas of the detail views of applicable models. This is accomplished by subclassing `PluginTemplateExtension`, designating a particular NetBox model, and defining the desired methods to render custom content. Four methods are available:

+ 1 - 0
docs/release-notes/version-2.9.md

@@ -10,6 +10,7 @@
 
 ### Bug Fixes
 
+* [#5046](https://github.com/netbox-community/netbox/issues/5046) - Disabled plugin menu items are no longer clickable
 * [#5063](https://github.com/netbox-community/netbox/issues/5063) - Fix "add device" link in rack elevations for opposite side of half-depth devices
 * [#5074](https://github.com/netbox-community/netbox/issues/5074) - Fix inclusion of VC member interfaces when viewing VC master
 * [#5078](https://github.com/netbox-community/netbox/issues/5078) - Fix assignment of existing IP addresses to interfaces via web UI

+ 16 - 12
netbox/templates/inc/plugin_menu_items.html

@@ -5,18 +5,22 @@
         {% for section_name, menu_items in registry.plugin_menu_items.items %}
             <li class="dropdown-header">{{ section_name }}</li>
             {% for menu_item in menu_items %}
-                <li{% if menu_item.permissions and not request.user|has_perms:menu_item.permissions %} class="disabled"{% endif %}>
-                    {% if menu_item.buttons %}
-                        <div class="buttons pull-right">
-                            {% for button in menu_item.buttons %}
-                                {% if not button.permissions or request.user|has_perms:button.permissions %}
-                                    <a href="{% url button.link %}" class="btn btn-xs btn-{{ button.color }}" title="{{ button.title }}"><i class="{{ button.icon_class }}"></i></a>
-                                {% endif %}
-                            {% endfor %}
-                        </div>
-                    {% endif %}
-                    <a href="{% url menu_item.link %}">{{ menu_item.link_text }}</a>
-                </li>
+                {% if not menu_item.permissions or request.user|has_perms:menu_item.permissions %}
+                    <li>
+                        {% if menu_item.buttons %}
+                            <div class="buttons pull-right">
+                                {% for button in menu_item.buttons %}
+                                    {% if not button.permissions or request.user|has_perms:button.permissions %}
+                                        <a href="{% url button.link %}" class="btn btn-xs btn-{{ button.color }}" title="{{ button.title }}"><i class="{{ button.icon_class }}"></i></a>
+                                    {% endif %}
+                                {% endfor %}
+                            </div>
+                        {% endif %}
+                        <a href="{% url menu_item.link %}">{{ menu_item.link_text }}</a>
+                    </li>
+                {% else %}
+                    <li class="disabled"><a href="#">{{ menu_item.link_text }}</a></li>
+                {% endif %}
             {% endfor %}
             {% if not forloop.last %}
                 <li class="divider"></li>