mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 00:15:17 -06:00
Closes #13638: Add optional staff_only attribute to MenuItem
This commit is contained in:
parent
272d2c54d4
commit
d0b1facfd8
@ -64,12 +64,13 @@ item1 = PluginMenuItem(
|
|||||||
|
|
||||||
A `PluginMenuItem` has the following attributes:
|
A `PluginMenuItem` has the following attributes:
|
||||||
|
|
||||||
| Attribute | Required | Description |
|
| Attribute | Required | Description |
|
||||||
|---------------|----------|------------------------------------------------------|
|
|---------------|----------|----------------------------------------------------------------------------------------------------------|
|
||||||
| `link` | Yes | Name of the URL path to which this menu item links |
|
| `link` | Yes | Name of the URL path to which this menu item links |
|
||||||
| `link_text` | Yes | The text presented to the user |
|
| `link_text` | Yes | The text presented to the user |
|
||||||
| `permissions` | - | A list of permissions required to display this link |
|
| `permissions` | - | A list of permissions required to display this link |
|
||||||
| `buttons` | - | An iterable of PluginMenuButton instances to include |
|
| `staff_only` | - | Display only for users who have `is_staff` set to true (any specified permissions will also be required) |
|
||||||
|
| `buttons` | - | An iterable of PluginMenuButton instances to include |
|
||||||
|
|
||||||
## Menu Buttons
|
## Menu Buttons
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ class MenuItem:
|
|||||||
link: str
|
link: str
|
||||||
link_text: str
|
link_text: str
|
||||||
permissions: Optional[Sequence[str]] = ()
|
permissions: Optional[Sequence[str]] = ()
|
||||||
|
staff_only: Optional[bool] = False
|
||||||
buttons: Optional[Sequence[MenuItemButton]] = ()
|
buttons: Optional[Sequence[MenuItemButton]] = ()
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,11 +26,14 @@ def nav(context: Context) -> Dict:
|
|||||||
for group in menu.groups:
|
for group in menu.groups:
|
||||||
items = []
|
items = []
|
||||||
for item in group.items:
|
for item in group.items:
|
||||||
if user.has_perms(item.permissions):
|
if not user.has_perms(item.permissions):
|
||||||
buttons = [
|
continue
|
||||||
button for button in item.buttons if user.has_perms(button.permissions)
|
if item.staff_only and not user.is_staff:
|
||||||
]
|
continue
|
||||||
items.append((item, buttons))
|
buttons = [
|
||||||
|
button for button in item.buttons if user.has_perms(button.permissions)
|
||||||
|
]
|
||||||
|
items.append((item, buttons))
|
||||||
if items:
|
if items:
|
||||||
groups.append((group, items))
|
groups.append((group, items))
|
||||||
if groups:
|
if groups:
|
||||||
|
Loading…
Reference in New Issue
Block a user