Exemplo n.º 1
0
 def register_menu_groups(self):
     register_menu_group(
         position=110,
         config={
             'label': 'Network Topology',
             'items': {
                 1: {
                     'label': _('Topologies'),
                     'model': get_model_name('topology', 'Topology'),
                     'name': 'changelist',
                     'icon': 'ow-topology',
                 },
                 2: {
                     'label': _('Nodes'),
                     'model': get_model_name('topology', 'Node'),
                     'name': 'changelist',
                     'icon': 'ow-node',
                 },
                 3: {
                     'label': _('Links'),
                     'model': get_model_name('topology', 'Link'),
                     'name': 'changelist',
                     'icon': 'ow-link',
                 },
             },
             'icon': 'ow-network-topology',
         },
     )
Exemplo n.º 2
0
 def regiser_menu_groups(self):
     items = {
         1: {
             'label': _('Accounting Sessions'),
             'model': get_model_name(self.label, 'RadiusAccounting'),
             'name': 'changelist',
             'icon': 'ow-radius-accounting',
         },
         2: {
             'label': _('Groups'),
             'model': get_model_name(self.label, 'RadiusGroup'),
             'name': 'changelist',
             'icon': 'ow-radius-group',
         },
         3: {
             'label': _('NAS'),
             'model': get_model_name(self.label, 'Nas'),
             'name': 'changelist',
             'icon': 'ow-radius-nas',
         },
         4: {
             'label': _('Checks'),
             'model': get_model_name(self.label, 'RadiusCheck'),
             'name': 'changelist',
             'icon': 'ow-radius-checks',
         },
         5: {
             'label': _('Replies'),
             'model': get_model_name(self.label, 'RadiusReply'),
             'name': 'changelist',
             'icon': 'ow-radius-replies',
         },
         6: {
             'label': _('Batch user Creation'),
             'model': get_model_name(self.label, 'RadiusBatch'),
             'name': 'changelist',
             'icon': 'ow-batch-creation',
         },
         7: {
             'label': _('Post Auth Log'),
             'model': get_model_name(self.label, 'RadiusPostAuth'),
             'name': 'changelist',
             'icon': 'ow-radius-post-log',
         },
     }
     if getattr(app_settings, 'DEBUG', False):
         items[8] = {
             'label': _('Radius Token'),
             'model': get_model_name(self.label, 'RadiusToken'),
             'name': 'changelist',
             'icon': 'ow-radius-token',
         }
     register_menu_group(
         position=70,
         config={
             'label': _('RADIUS'),
             'items': items,
             'icon': 'ow-radius'
         },
     )
Exemplo n.º 3
0
 def register_menu_group(self):
     items = {
         1: {
             'label': _('Users'),
             'model': settings.AUTH_USER_MODEL,
             'name': 'changelist',
             'icon': 'user',
         },
         2: {
             'label': _('Organizations'),
             'model': get_model_name(self.app_label, 'Organization'),
             'name': 'changelist',
             'icon': 'ow-org',
         },
         5: {
             'label': _('Groups & Permissions'),
             'model': get_model_name(self.app_label, 'Group'),
             'name': 'changelist',
             'icon': 'ow-permission',
         },
     }
     if app_settings.ORGANIZATION_OWNER_ADMIN:
         items[3] = {
             'label': _('Organization Owners'),
             'model': get_model_name(self.app_label, 'OrganizationOwner'),
             'name': 'changelist',
             'icon': 'ow-org-owner',
         }
     if app_settings.ORGANIZATION_USER_ADMIN:
         items[4] = {
             'label': _('Organization Users'),
             'model': get_model_name(self.app_label, 'OrganizationUser'),
             'name': 'changelist',
             'icon': 'ow-org-user',
         }
     register_menu_group(
         position=40,
         config={
             'label': _('Users & Organizations'),
             'items': items,
             'icon': 'ow-user-and-org',
         },
     )
Exemplo n.º 4
0
 def register_custom_menus(self):
     # position 10 is home
     register_menu_group(position=11,
                         config={
                             "label": "Map",
                             "url": reverse('mk-map'),
                             "icon": "mk-icon-map"
                         })
     register_menu_group(position=12,
                         config={
                             "label": "Devices",
                             "url": reverse('mk-devices'),
                             "icon": "ow-device"
                         })
     register_menu_group(position=13,
                         config={
                             "label": "Clients",
                             "url": reverse('mk-clients'),
                             "icon": "mk-icon-map"
                         })
     # Remove 'Devices' menu item
     openwisp_utils.admin_theme.menu.MENU.pop(20)
     register_menu_subitem(
         group_position=30,
         item_position=0,
         config={
             'label': 'Devices',
             'model': get_model_name('config', 'Device'),
             'name': 'changelist',
             'icon': 'ow-device',
         },
     )
Exemplo n.º 5
0
 def register_menu_groups(self):
     register_menu_group(
         position=60,
         config={
             'label': 'Cas & Certificates',
             'items': {
                 1: {
                     'label': 'Certification Authorities',
                     'model': get_model_name('django_x509', 'Ca'),
                     'name': 'changelist',
                     'icon': 'ow-ca',
                 },
                 2: {
                     'label': 'Certificates',
                     'model': get_model_name('django_x509', 'Cert'),
                     'name': 'changelist',
                     'icon': 'ow-certificate',
                 },
             },
             'icon': 'ow-cer-group',
         },
     )
Exemplo n.º 6
0
 def register_menu_groups(self):
     register_menu_group(
         position=80,
         config={
             'label': 'Monitoring',
             'items': {
                 1: {
                     'label': _('Metrics'),
                     'model': get_model_name('monitoring', 'Metric'),
                     'name': 'changelist',
                     'icon': 'ow-metrics',
                 },
                 2: {
                     'label': _('Checks'),
                     'model': get_model_name('check', 'Check'),
                     'name': 'changelist',
                     'icon': 'ow-monitoring-checks',
                 },
             },
             'icon': 'ow-monitoring',
         },
     )
Exemplo n.º 7
0
 def register_menu_groups(self):
     register_menu_group(
         position=50,
         config={
             'label': 'Geographic Info',
             'items': {
                 1: {
                     'label': 'Locations',
                     'model': get_model_name('geo', 'Location'),
                     'name': 'changelist',
                     'icon': 'ow-location',
                 },
                 2: {
                     'label': 'Floorplans',
                     'model': get_model_name('geo', 'FloorPlan'),
                     'name': 'changelist',
                     'icon': 'ow-floor',
                 },
             },
             'icon': 'ow-geo',
         },
     )
Exemplo n.º 8
0
 def register_menu_groups(self):
     register_menu_group(
         position=90,
         config={
             'label': _('Ipam'),
             'items': {
                 1: {
                     'label': _('IP Addresses'),
                     'model': get_model_name('openwisp_ipam', 'IpAddress'),
                     'name': 'changelist',
                     'icon': 'ow-ip-address',
                 },
                 2: {
                     'label': _('Subnets'),
                     'model': get_model_name('openwisp_ipam', 'Subnet'),
                     'name': 'changelist',
                     'icon': 'ow-subnet',
                 },
             },
             'icon': 'ow-ipam',
         },
     )
Exemplo n.º 9
0
 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={
             'label': 'Configurations',
             'items': {
                 1: {
                     'label': 'Templates',
                     'model': get_model_name('config', 'Template'),
                     'name': 'changelist',
                     'icon': 'ow-template',
                 },
                 2: {
                     'label': 'VPN Servers',
                     'model': get_model_name('config', 'Vpn'),
                     'name': 'changelist',
                     'icon': 'ow-vpn',
                 },
                 4: {
                     'label': 'Device Groups',
                     'model': get_model_name('config', 'DeviceGroup'),
                     'name': 'changelist',
                     'icon': 'ow-device-group',
                 },
             },
             'icon': 'ow-config',
         },
     )
Exemplo n.º 10
0
 def register_menu_groups(self):
     auth_config = {
         'label': _('Authentication And Authorization'),
         'items': {
             2: {
                 'label': 'Add user',
                 'model': 'auth.User',
                 'name': 'add',
                 'icon': 'add-user',
             },
             1: {
                 'model': 'auth.User',
                 'name': 'changelist',
                 'icon': 'user',
                 'label': _('Users'),
             },
         },
         'icon': 'auth',
     }
     docs_config = {
         'label': _('Docs'),
         'items': {
             1: {
                 'label': _('OpenWISP'),
                 'url': 'https://openwisp.org/',
                 'icon': 'link',
             }
         },
         'icon': 'docs',
     }
     register_menu_group(
         position=31,
         config={
             'model': 'test_project.Shelf',
             'name': 'changelist',
             'label': _('Shelfs'),
             'icon': 'shelf',
         },
     )
     register_menu_group(position=32, config=auth_config)
     register_menu_group(position=33, config=docs_config)
     register_menu_subitem(
         group_position=33,
         item_position=2,
         config={
             'label': _('Code'),
             'url': 'https://openwisp.org/thecode.html',
             'icon': 'code',
         },
     )
Exemplo n.º 11
0
    def test_register_menu_groups(self):

        from openwisp_utils.admin_theme.menu import MENU

        # create a menu
        model_link_config = self._get_model_link_config()
        menu_link_config = self._get_menu_link_config()
        menu_group_config = self._get_menu_group_config()
        test_menu_groups = {
            3: menu_group_config,
            2: model_link_config,
            1: menu_link_config,
        }
        # save menu order to compare
        items_order = [
            MenuLink(config=menu_link_config),
            ModelLink(config=model_link_config),
            MenuGroup(config=menu_group_config),
        ]
        user = get_user_model().objects.create_superuser(
            username='******', password='******', email='*****@*****.**')
        self.client.force_login(user)
        url = reverse('admin:index')
        for position, config in test_menu_groups.items():
            register_menu_group(position=position, config=config)

        with self.subTest('Test ordering of menu groups'):
            request = self.factory.get(url)
            request.user = user
            current_item_index = 0
            for item in MENU.values():
                item_context = item.get_context(request)
                ordered_item_context = items_order[
                    current_item_index].get_context(request)
                self.assertEqual(item_context, ordered_item_context)
                current_item_index += 1

        with self.subTest('Registering at an occupied position'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_group(position=1, config=model_link_config)

        with self.subTest('Registering with invalid position'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_group(position='invalid_position',
                                    config=menu_link_config)

        with self.subTest('Registering with invalid config'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_group(position=-1, config=[])

        with self.subTest('Registering with unknow menu group'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_group(position=-1, config={})

        with self.subTest('Model Link with invalid name'):
            _config = self._get_model_link_config(name="invalid_name")
            with self.assertRaises(NoReverseMatch):
                register_menu_group(position=-1, config=_config)
                self.client.get(url)

        with self.subTest('Model Group with invalid name in item'):
            _config = self._get_menu_group_config(
                items={1: self._get_model_link_config(name="invalid_name")})
            with self.assertRaises(NoReverseMatch):
                register_menu_group(position=-2, config=_config)
                self.client.get(url)
Exemplo n.º 12
0
    def test_register_menu_subitem(self):
        from openwisp_utils.admin_theme.menu import MENU

        config = self._get_menu_link_config()
        register_menu_group(position=100, config=self._get_menu_group_config())
        register_menu_group(position=102, config=self._get_menu_link_config())
        with self.subTest('Test menu subitem with invalid group position'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position='invalid',
                                      item_position=1,
                                      config=config)

        with self.subTest('Test menu subitem with invalid item position'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position=100,
                                      item_position='invalid',
                                      config=config)
        with self.subTest(
                'Test menu subitem with wrong group positions or config'):
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position=101,
                                      item_position=1,
                                      config=config)
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position=100,
                                      item_position=1,
                                      config=[])
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position=100,
                                      item_position=1,
                                      config=config)
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(group_position=102,
                                      item_position=1,
                                      config=config)
            with self.assertRaises(ImproperlyConfigured):
                register_menu_subitem(
                    group_position=100,
                    item_position=3,
                    config=self._get_menu_group_config(),
                )

        with self.subTest('Test menu subitem with valid data'):
            model_link_config = self._get_model_link_config()
            register_menu_subitem(group_position=100,
                                  item_position=3,
                                  config=config)
            register_menu_subitem(group_position=100,
                                  item_position=4,
                                  config=model_link_config)
            user = get_user_model().objects.create_superuser(
                username='******',
                password='******',
                email='*****@*****.**')
            url = reverse('admin:index')
            request = self.factory.get(url)
            request.user = user
            item = MenuLink(config=config)
            item_context = item.get_context(request)
            registered_item_context = MENU[100].items[3].get_context(request)
            self.assertEqual(registered_item_context, item_context)
            model_link_item = ModelLink(config=model_link_config)
            model_link_context = model_link_item.get_context(request)
            registered_model_context = MENU[100].items[4].get_context(request)
            self.assertEqual(model_link_context, registered_model_context)