Navigation

class keg_auth.libs.navigation.NavItem(*args, nav_group=None, icon_class=None, class_=None, code=None)

Defines a menu item or structure of a menu.

Example:

my_menu = NavItem(
    NavItem(
        'Admin',
        NavItem('Users', NavURL('auth.user:list')),
        NavItem('Groups', NavURL('auth.group:list')),
        nav_group='admin',
        icon_class='fas fa-briefcase',
        class_='my-menu-group'
    ),
    NavItem(
        'Reports',
        NavItem('Frequency', NavURL('frequency-report'), code='frequency'),
        NavItem('Financial', NavURL('money-report', requires_permissions='secret-perm'))
    )
)
clear_authorization(session_key)

Reset cached authorization in this and all subnodes for the given session key.

has_current_route

Returns true if current request matches this nav node.

is_permitted

Compute/cache authorization from permission conditions, and return bool.

node_type

Return type NavItemType indicating whether this node is at the end of the structure.

permitted_sub_nodes

Return list of subnodes accessible to current user.

class keg_auth.libs.navigation.NavURL(route_string, *args, **kwargs)

Wraps url_for with permission-checking to determine if user should see a route.

Endpoint is checked for user/permission requirements. - method/class/blueprint permissions from decorators (preferred in most cases) - requires_permissions kwarg specifies conditions and disregards the decorators - requires_anonymous kwarg forces nav for only unauthenticated users

Note that permission requirements are checked at all levels of the view hierarchy as needed: method, class, and blueprint.

is_permitted

Check permitted status of this route for the current user