Small cleanups to the decorators file

This commit is contained in:
Joseph Schorr 2017-07-20 11:08:24 -04:00
parent 17f3de811e
commit 0531f6c749

View file

@ -1,14 +1,11 @@
""" Various decorators for endpoint and API handlers. """
from functools import wraps
from flask import abort
import features
from auth.auth_context import (get_validated_oauth_token, get_authenticated_user,
get_validated_token, get_grant_context)
from data import model # TODO: stop using model directly
from auth.auth_context import (
get_validated_oauth_token, get_authenticated_user, get_validated_token, get_grant_context)
def anon_allowed(func):
@ -25,6 +22,7 @@ def anon_protect(func):
def check_anon_protection(func):
""" Validates a method as requiring some form of valid user auth before it can be executed. """
@wraps(func)
def wrapper(*args, **kwargs):
# Skip if anonymous access is allowed.
@ -37,11 +35,13 @@ def check_anon_protection(func):
return func(*args, **kwargs)
abort(401)
return wrapper
def route_show_if(value):
""" Adds/shows the decorated route if the given value is True. """
def decorator(f):
@wraps(f)
def decorated_function(*args, **kwargs):
@ -51,4 +51,3 @@ def route_show_if(value):
return f(*args, **kwargs)
return decorated_function
return decorator