def req(wrapped, instance, args, kwargs):
     if not can(*permissions):
         # redirect browsers, but just return 403 to REST clients
         if util.is_browser():
             return current_app.login_manager.unauthorized()
         else:
             abort(403)
     return wrapped(*args, **kwargs)
Example #2
0
 def req(wrapped, instance, args, kwargs):
     if not can(*permissions):
         # redirect browsers when the user is not logged in, but
         # just return 403 to REST clients
         if util.is_browser() and current_user.is_anonymous():
             return current_app.login_manager.unauthorized()
         else:
             abort(403)
     return wrapped(*args, **kwargs)
Example #3
0
 def req(wrapped, instance, args, kwargs):
     if not can(*permissions):
         # redirect browsers when the user is not logged in, but
         # just return 403 to REST clients
         if util.is_browser() and current_user.is_anonymous:
             return current_app.login_manager.unauthorized()
         else:
             abort(403)
     return wrapped(*args, **kwargs)
Example #4
0
def test_is_browser(app):
    for is_browser, headers in [
        (True, [('Accept', 'text/html')]),
        (False, [('Accept', 'application/json')]),
        (False, []),
        (True, [('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]),
        # It'd be simpler if these were True, but it doesn't really matter -- they're static
        (False, [('Accept', 'text/css,*/*;q=0.1')]),
        (False, [('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5')]),
    ]:
        with app.test_request_context(headers=headers):
            eq_(util.is_browser(), is_browser,
                "%s should %sbe a browser" % (headers, '' if is_browser else 'not '))
Example #5
0
def test_is_browser(app):
    for is_browser, headers in [
        (True, [('Accept', 'text/html')]),
        (False, [('Accept', 'application/json')]),
        (False, []),
        (True, [
            ('Accept',
             'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
        ]),
            # It'd be simpler if these were True, but it doesn't really matter -- they're static
        (False, [('Accept', 'text/css,*/*;q=0.1')]),
        (False, [('Accept', 'image/png,image/*;q=0.8,*/*;q=0.5')]),
    ]:
        with app.test_request_context(headers=headers):
            eq_(
                util.is_browser(), is_browser, "%s should %sbe a browser" %
                (headers, '' if is_browser else 'not '))
Example #6
0
def _get_handler():
    """Get an appropriate handler based on the request"""
    return HtmlHandler() if util.is_browser() else JsonHandler()
Example #7
0
def _get_handler():
    """Get an appropriate handler based on the request"""
    return HtmlHandler() if util.is_browser() else JsonHandler()