Exemplo n.º 1
0
        def wrapper(*args, **kwargs):
            auth_groups = AUTH_MAP.get(endpoint)

            if config.LOGIN['enabled'] and \
                    not current_user.has_groups(auth_groups):
                # TODO rase exception here
                return no_permission()

            return func(*args, **kwargs)
Exemplo n.º 2
0
def auth_init(app):
    # TODO 考虑统一抽出deco view的规则
    endpoint_list = filter(
        lambda endpoint: endpoint in AUTH_MAP.keys(),
        app.view_functions.keys()
    )

    endpoint_list_hr = filter(
        lambda endpoint: endpoint in AUTH_MAP_HR.keys(),
        app.view_functions.keys()
    )

    # add login deco for each view_func
    for ep in endpoint_list:
        app.view_functions[ep] = auth(ep)(app.view_functions[ep])

    for ep in endpoint_list_hr:
        app.view_functions[ep] = auth_hr(ep)(app.view_functions[ep])