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