Skip to content

Commit

Permalink
[fix] Registered menu group in connection app openwisp#512
Browse files Browse the repository at this point in the history
  • Loading branch information
niteshsinha17 committed Aug 18, 2021
1 parent d1b79e4 commit 651d8ab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 19 deletions.
24 changes: 9 additions & 15 deletions openwisp_controller/config/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ def connect_signals(self):
)

def register_menu_groups(self):
register_menu_group(
position=20,
config={
'label': 'Devices',
'model': get_model_name('config', 'Device'),
'name': 'changelist',
'icon': 'ow-device',
},
)
register_menu_group(
position=30,
config={
Expand All @@ -103,12 +112,6 @@ def register_menu_groups(self):
'name': 'changelist',
'icon': 'ow-vpn',
},
3: {
'label': 'Access Credentials',
'model': get_model_name('connection', 'Credentials'),
'name': 'changelist',
'icon': 'ow-access-credential',
},
4: {
'label': 'Device Groups',
'model': get_model_name('config', 'DeviceGroup'),
Expand All @@ -119,15 +122,6 @@ def register_menu_groups(self):
'icon': 'ow-config',
},
)
register_menu_group(
position=20,
config={
'label': 'Devices',
'model': get_model_name('config', 'Device'),
'name': 'changelist',
'icon': 'ow-device',
},
)

def register_notification_types(self):
register_notification_type(
Expand Down
4 changes: 2 additions & 2 deletions openwisp_controller/config/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,11 +1255,11 @@ def test_organization_filter(self):
def test_admin_menu_groups(self):
# Test menu group (openwisp-utils menu group) for Device Group, Template
# and Vpn models
self.client.force_login(self._get_admin())
models = ['devicegroup', 'template', 'vpn']
self.client.force_login(self._get_admin())
response = self.client.get(reverse('admin:index'))
for model in models:
with self.subTest(f'test_admin_group_for_{model}_model'):
with self.subTest(f'test_menu_group_for_{model}_model'):
url = reverse(f'admin:{self.app_label}_{model}_changelist')
self.assertContains(response, f'<a class="mg-link" href="{url}">')
with self.subTest('test_configuration_group_is_registered'):
Expand Down
17 changes: 16 additions & 1 deletion openwisp_controller/connection/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from django.utils.translation import ugettext_lazy as _
from openwisp_notifications.signals import notify
from openwisp_notifications.types import register_notification_type
from swapper import load_model
from swapper import get_model_name, load_model

from openwisp_utils.admin_theme.menu import register_menu_subitem

from ..config.signals import config_modified
from .signals import is_working_changed
Expand All @@ -28,6 +30,7 @@ def ready(self):
"""
self.register_notification_types()
self.notification_cache_update()
self.register_menu_groups()

Config = load_model('config', 'Config')
Credentials = load_model('connection', 'Credentials')
Expand Down Expand Up @@ -161,3 +164,15 @@ def notification_cache_update(self):
signal=is_working_changed,
dispatch_uid='notification_device_cache_invalidation',
)

def register_menu_groups(self):
register_menu_subitem(
group_position=30,
item_position=3,
config={
'label': _('Access Credentials'),
'model': get_model_name('connection', 'Credentials'),
'name': 'changelist',
'icon': 'ow-access-credential',
},
)
2 changes: 1 addition & 1 deletion openwisp_controller/connection/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_admin_menu_groups(self):
models = ['credentials']
response = self.client.get(reverse('admin:index'))
for model in models:
with self.subTest(f'test_admin_group_for_{model}_model'):
with self.subTest(f'test_menu_group_for_{model}_model'):
url = reverse(f'admin:{self.app_label}_{model}_changelist')
self.assertContains(response, f'<a class="mg-link" href="{url}">')

Expand Down

0 comments on commit 651d8ab

Please sign in to comment.