Example #1
0
def before_app_request():
    user_id = session.get('user_id', 0)
    g.user = User.query.filter(User.id == user_id).first()
    g.menu_entries['auth'] = {
        'title': 'Log in' if g.user is None else 'Log out',
        'icon': 'sign-in' if g.user is None else 'sign-out',
        'route': 'auth.login' if g.user is None else 'auth.logout'
    }
    if g.user is not None:
        g.menu_entries['account'] = {
            'title': 'Manage account',
            'icon': 'user',
            'route': 'auth.manage'
        }
    g.menu_entries['config'] = get_menu_entries(g.user,
                                                'Platform mgmt',
                                                'cog',
                                                all_entries=[{
                                                    'title':
                                                    'User manager',
                                                    'icon':
                                                    'users',
                                                    'route':
                                                    'auth.users',
                                                    'access': [Role.admin]
                                                }])
Example #2
0
def before_request():
    g.menu_entries['support'] = get_menu_entries(
        g.user, 'About & Help', 'question', '', [
            {'title': 'About', 'icon': 'info', 'route': 'support.about'},
            {'title': 'Support', 'icon': 'support', 'route':
                'support.support'}
        ]
    )
Example #3
0
def before_request():
    g.menu_entries['honeypot'] = get_menu_entries(
        g.user, 'Honeypot instances', 'rocket', '', [
            {'title': 'Profile mgmt', 'icon': 'bookmark', 'route':
                'honeypot.profiles'},
            {'title': 'Honeypot mgmt', 'icon': 'rocket', 'route':
                'honeypot.manage'}
        ]
    )
Example #4
0
    def test_get_menu_entries_with_no_permissions(self,
                                                  mock_permissible_entries,
                                                  mock_user):
        """
        Passing a menu entry to get_menu_entries() when user is not
        allowed to access any route. This should return an empty dictionary.
        """

        mu = mock_user.return_value
        mu.can_access_route.return_value = False

        def side_effect(*args):
            return args[
                1]  # Return second argument : entry (dict) assuming user can access all entries

        mock_permissible_entries.side_effect = side_effect
        entries = get_menu_entries(
            mu, 'Configuration', 'cog', '', [{
                'title':
                'Notif. services',
                'icon':
                'bell-o',
                'route':
                'config.notifications',
                'entries': [{
                    'title':
                    'Notif. services',
                    'icon':
                    'bell-o',
                    'route':
                    'config.notifications',
                    'entries': [{
                        'title':
                        'Honeypot services',
                        'icon':
                        'sliders',
                        'route':
                        'config.services',
                        'entries': [{
                            'title': 'Profile mgmt',
                            'icon': 'bookmark',
                            'route': 'honeypot.profiles'
                        }]
                    }]
                }]
            }, {
                'title': 'Data processing',
                'icon': 'exchange',
                'route': 'config.data_processing'
            }, {
                'title': 'Honeypot services',
                'icon': 'sliders',
                'route': 'config.services'
            }])
        correct_entries = {}
        self.assertDictEqual(entries, correct_entries)
        mock_permissible_entries.assert_not_called()
Example #5
0
def before_request():
    g.menu_entries['honeypot'] = get_menu_entries(
        g.user, 'Honeypot instances', 'rocket', '', [
            {'title': 'Profile mgmt', 'icon': 'bookmark', 'route':
                'honeypot.profiles'},
            {'title': 'Honeypot mgmt', 'icon': 'rocket', 'route':
                'honeypot.manage'}
        ]
    )
Example #6
0
def before_app_request():
    """
    Function that organize menu content such as Platform management
    """
    config_entries = get_menu_entries(
        g.user, 'Platform mgmt', 'cog', [], '', [
            {'title': 'Maintenance', 'icon': 'wrench', 'route':
                'ci.show_maintenance', 'access': [Role.admin]}
        ]
    )
    if 'config' in g.menu_entries and 'entries' in config_entries:
        g.menu_entries['config']['entries'] = \
            config_entries['entries'] + g.menu_entries['config']['entries']
    else:
        g.menu_entries['config'] = config_entries
Example #7
0
def before_app_request():
    g.menu_entries['upload'] = {
        'title': 'Upload',
        'icon': 'upload',
        'route': 'upload.index'
    }
    config_entries = get_menu_entries(
        g.user, 'Platform mgmt', 'cog', all_entries=[
            {'title': 'Upload manager', 'icon': 'upload', 'route':
                'upload.index_admin', 'access': [Role.admin]}
        ]
    )
    if 'config' in g.menu_entries and 'entries' in config_entries:
        g.menu_entries['config']['entries'] = config_entries['entries'] + g.menu_entries['config']['entries']
    else:
        g.menu_entries['config'] = config_entries
Example #8
0
def before_request():
    entries = get_menu_entries(
        g.user, 'Configuration', 'cog', '', [
            {'title': 'Notif. services', 'icon': 'bell-o', 'route':
                'config.notifications'},
            {'title': 'Data processing', 'icon': 'exchange', 'route':
                'config.data_processing'},
            {'title': 'Honeypot services', 'icon': 'sliders', 'route':
                'config.services'}
        ]
    )
    if 'config' in g.menu_entries and 'entries' in entries:
        g.menu_entries['config']['entries'] = entries['entries'] + \
            g.menu_entries['config']['entries']
    else:
        g.menu_entries['config'] = entries
Example #9
0
def before_request():
    entries = get_menu_entries(
        g.user, 'Configuration', 'cog', '', [
            {'title': 'Notif. services', 'icon': 'bell-o', 'route':
                'config.notifications'},
            {'title': 'Data processing', 'icon': 'exchange', 'route':
                'config.data_processing'},
            {'title': 'Honeypot services', 'icon': 'sliders', 'route':
                'config.services'}
        ]
    )
    if 'config' in g.menu_entries and 'entries' in entries:
        g.menu_entries['config']['entries'] = entries['entries'] + \
            g.menu_entries['config']['entries']
    else:
        g.menu_entries['config'] = entries
def before_app_request():
    user_id = session.get('user_id', 0)
    g.user = User.query.filter(User.id == user_id).first()
    g.menu_entries['auth'] = {
        'title': 'Log in' if g.user is None else 'Log out',
        'icon': 'sign-in' if g.user is None else 'sign-out',
        'route': 'auth.login' if g.user is None else 'auth.logout'
    }
    if g.user is not None:
        g.menu_entries['account'] = {
            'title': 'Manage account',
            'icon': 'user',
            'route': 'auth.manage'
        }
    g.menu_entries['config'] = get_menu_entries(
        g.user, 'Platform mgmt', 'cog',
        all_entries=[{'title': 'User manager', 'icon': 'users', 'route': 'auth.users', 'access': [Role.admin]}]
    )
Example #11
0
def before_app_request():
    user_id = session.get('user_id', 0)
    g.user = User.query.filter(User.id == user_id).first()
    g.menu_entries['auth'] = {
        'title': 'Log in' if g.user is None else 'Log out',
        'icon': 'sign-in' if g.user is None else 'sign-out',
        'route': 'auth.login' if g.user is None else 'auth.logout'
    }
    g.menu_entries['account'] = {
        'title': 'Manage account',
        'icon': 'user',
        'route': 'auth.manage'
    }
    g.menu_entries['config'] = get_menu_entries(
        g.user, 'Configuration', 'cog', '', [
            {'title': 'User manager', 'icon': 'users', 'route':
                'auth.users'},
            {'title': 'Access manager', 'icon': 'check', 'route':
                'auth.access'}
        ]
    )
Example #12
0
def before_app_request():
    user_id = session.get('user_id', 0)
    g.user = User.query.filter(User.id == user_id).first()
    g.menu_entries['auth'] = {
        'title': 'Log in' if g.user is None else 'Log out',
        'icon': 'sign-in' if g.user is None else 'sign-out',
        'route': 'auth.login' if g.user is None else 'auth.logout'
    }
    g.menu_entries['account'] = {
        'title': 'Manage account',
        'icon': 'user',
        'route': 'auth.manage'
    }
    g.menu_entries['config'] = get_menu_entries(g.user, 'Configuration', 'cog',
                                                '', [{
                                                    'title': 'User manager',
                                                    'icon': 'users',
                                                    'route': 'auth.users'
                                                }, {
                                                    'title': 'Access manager',
                                                    'icon': 'check',
                                                    'route': 'auth.access'
                                                }])
Example #13
0
def before_request():
    g.menu_entries['report'] = get_menu_entries(
        g.user, 'Dashboard', 'dashboard', 'report.dashboard')
Example #14
0
def before_request():
    g.menu_entries['report'] = get_menu_entries(g.user, 'Dashboard',
                                                'dashboard',
                                                'report.dashboard')
Example #15
0
    def test_get_menu_entries_with_simple_entries(self,
                                                  mock_permissible_entries,
                                                  mock_user):
        """
        Passing a menu entry to get_menu_entries() when all the
        routes are accessible (simulating admin)
        and verifying against correct menu structure by mocking get_permissible_entries()
        and testing that it is called properly
        """

        mu = mock_user.return_value
        mu.can_access_route.return_value = True  # Assuming all routes can be accessed by the user

        def side_effect(*args):
            return args[
                1]  # Return second argument : entry (dict) assuming user can access all entries

        mock_permissible_entries.side_effect = side_effect
        entries = get_menu_entries(
            mu, 'Configuration', 'cog', '', [{
                'title':
                'Notif. services',
                'icon':
                'bell-o',
                'route':
                'config.notifications',
                'entries': [{
                    'title':
                    'Notif. services',
                    'icon':
                    'bell-o',
                    'route':
                    'config.notifications',
                    'entries': [{
                        'title':
                        'Honeypot services',
                        'icon':
                        'sliders',
                        'route':
                        'config.services',
                        'entries': [{
                            'title': 'Profile mgmt',
                            'icon': 'bookmark',
                            'route': 'honeypot.profiles'
                        }]
                    }]
                }]
            }, {
                'title': 'Data processing',
                'icon': 'exchange',
                'route': 'config.data_processing'
            }, {
                'title': 'Honeypot services',
                'icon': 'sliders',
                'route': 'config.services'
            }])
        correct_entries = {
            'entries': [{
                'title':
                'Notif. services',
                'route':
                'config.notifications',
                'entries': [{
                    'title':
                    'Notif. services',
                    'route':
                    'config.notifications',
                    'entries': [{
                        'title':
                        'Honeypot services',
                        'route':
                        'config.services',
                        'entries': [{
                            'title': 'Profile mgmt',
                            'route': 'honeypot.profiles',
                            'icon': 'bookmark'
                        }],
                        'icon':
                        'sliders'
                    }],
                    'icon':
                    'bell-o'
                }],
                'icon':
                'bell-o'
            }, {
                'route': 'config.data_processing',
                'title': 'Data processing',
                'icon': 'exchange'
            }, {
                'route': 'config.services',
                'title': 'Honeypot services',
                'icon': 'sliders'
            }],
            'icon':
            'cog',
            'title':
            'Configuration'
        }
        calls = [
            call(
                mu, {
                    'route':
                    'config.notifications',
                    'icon':
                    'bell-o',
                    'entries': [{
                        'route':
                        'config.notifications',
                        'icon':
                        'bell-o',
                        'entries': [{
                            'route':
                            'config.services',
                            'icon':
                            'sliders',
                            'entries': [{
                                'route': 'honeypot.profiles',
                                'icon': 'bookmark',
                                'title': 'Profile mgmt'
                            }],
                            'title':
                            'Honeypot services'
                        }],
                        'title':
                        'Notif. services'
                    }],
                    'title':
                    'Notif. services'
                }),
            call(
                mu, {
                    'route': 'config.data_processing',
                    'icon': 'exchange',
                    'title': 'Data processing'
                }),
            call(
                mu, {
                    'route': 'config.services',
                    'icon': 'sliders',
                    'title': 'Honeypot services'
                })
        ]

        self.assertDictEqual(entries, correct_entries)
        mock_permissible_entries.assert_has_calls(
            calls)  # Check that mocked function correctly called