mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-25 08:46:10 -06:00
Create menu items manually for users & groups to accomodate proxy models
This commit is contained in:
parent
6a5c44f237
commit
d8ad97e4b8
@ -60,25 +60,17 @@ class Menu:
|
||||
# Utility functions
|
||||
#
|
||||
|
||||
def get_model_item(app_label, model_name, label, actions=('add', 'import'), permission_app_label=None, permission_model_name=None):
|
||||
if not permission_app_label:
|
||||
permission_app_label = app_label
|
||||
if not permission_model_name:
|
||||
permission_model_name = model_name
|
||||
def get_model_item(app_label, model_name, label, actions=('add', 'import')):
|
||||
return MenuItem(
|
||||
link=f'{app_label}:{model_name}_list',
|
||||
link_text=label,
|
||||
permissions=[f'{permission_app_label}.view_{permission_model_name}'],
|
||||
buttons=get_model_buttons(app_label, model_name, actions, permission_app_label, permission_model_name)
|
||||
permissions=[f'{app_label}.view_{model_name}'],
|
||||
buttons=get_model_buttons(app_label, model_name, actions)
|
||||
)
|
||||
|
||||
|
||||
def get_model_buttons(app_label, model_name, actions=('add', 'import'), permission_app_label=None, permission_model_name=None):
|
||||
def get_model_buttons(app_label, model_name, actions=('add', 'import')):
|
||||
buttons = []
|
||||
if not permission_app_label:
|
||||
permission_app_label = app_label
|
||||
if not permission_model_name:
|
||||
permission_model_name = model_name
|
||||
|
||||
if 'add' in actions:
|
||||
buttons.append(
|
||||
@ -86,7 +78,7 @@ def get_model_buttons(app_label, model_name, actions=('add', 'import'), permissi
|
||||
link=f'{app_label}:{model_name}_add',
|
||||
title='Add',
|
||||
icon_class='mdi mdi-plus-thick',
|
||||
permissions=[f'{permission_app_label}.add_{permission_model_name}'],
|
||||
permissions=[f'{app_label}.add_{model_name}'],
|
||||
color=ButtonColorChoices.GREEN
|
||||
)
|
||||
)
|
||||
@ -96,7 +88,7 @@ def get_model_buttons(app_label, model_name, actions=('add', 'import'), permissi
|
||||
link=f'{app_label}:{model_name}_import',
|
||||
title='Import',
|
||||
icon_class='mdi mdi-upload',
|
||||
permissions=[f'{permission_app_label}.add_{permission_model_name}'],
|
||||
permissions=[f'{app_label}.add_{model_name}'],
|
||||
color=ButtonColorChoices.CYAN
|
||||
)
|
||||
)
|
||||
|
@ -1,6 +1,7 @@
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from netbox.registry import registry
|
||||
from utilities.choices import ButtonColorChoices
|
||||
from . import *
|
||||
|
||||
#
|
||||
@ -354,8 +355,36 @@ ADMIN_MENU = Menu(
|
||||
MenuGroup(
|
||||
label=_('Users'),
|
||||
items=(
|
||||
get_model_item('users', 'netboxuser', _('Users'), actions=['add'], permission_app_label='auth', permission_model_name='users'),
|
||||
get_model_item('users', 'netboxgroup', _('Groups'), actions=['add'], permission_app_label='auth', permission_model_name='groups'),
|
||||
# Proxy model for auth.User
|
||||
MenuItem(
|
||||
link=f'users:netboxuser_list',
|
||||
link_text=_('Users'),
|
||||
permissions=[f'auth.view_user'],
|
||||
buttons=(
|
||||
MenuItemButton(
|
||||
link=f'users:netboxuser_add',
|
||||
title='Add',
|
||||
icon_class='mdi mdi-plus-thick',
|
||||
permissions=[f'auth.add_user'],
|
||||
color=ButtonColorChoices.GREEN
|
||||
),
|
||||
)
|
||||
),
|
||||
# Proxy model for auth.Group
|
||||
MenuItem(
|
||||
link=f'users:netboxgroup_list',
|
||||
link_text=_('Groups'),
|
||||
permissions=[f'auth.view_group'],
|
||||
buttons=(
|
||||
MenuItemButton(
|
||||
link=f'users:netboxgroup_add',
|
||||
title='Add',
|
||||
icon_class='mdi mdi-plus-thick',
|
||||
permissions=[f'auth.add_group'],
|
||||
color=ButtonColorChoices.GREEN
|
||||
),
|
||||
)
|
||||
),
|
||||
get_model_item('users', 'objectpermission', _('Permissions'), actions=['add']),
|
||||
),
|
||||
),
|
||||
|
Loading…
Reference in New Issue
Block a user