API - minor refactoring
This commit is contained in:
parent
c4d19089e4
commit
1697f6051f
@ -8,15 +8,22 @@ from fittrackee.responses import HttpResponse
|
|||||||
from .utils import verify_user
|
from .utils import verify_user
|
||||||
|
|
||||||
|
|
||||||
|
def verify_auth_user(
|
||||||
|
f: Callable, verify_admin: bool, *args: Any, **kwargs: Any
|
||||||
|
) -> Union[Callable, HttpResponse]:
|
||||||
|
response_object, user = verify_user(request, verify_admin=verify_admin)
|
||||||
|
if response_object:
|
||||||
|
return response_object
|
||||||
|
return f(user, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def authenticate(f: Callable) -> Callable:
|
def authenticate(f: Callable) -> Callable:
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated_function(
|
def decorated_function(
|
||||||
*args: Any, **kwargs: Any
|
*args: Any, **kwargs: Any
|
||||||
) -> Union[Callable, HttpResponse]:
|
) -> Union[Callable, HttpResponse]:
|
||||||
response_object, user = verify_user(request, verify_admin=False)
|
verify_admin = False
|
||||||
if response_object:
|
return verify_auth_user(f, verify_admin, *args, **kwargs)
|
||||||
return response_object
|
|
||||||
return f(user, *args, **kwargs)
|
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
|
||||||
@ -26,9 +33,7 @@ def authenticate_as_admin(f: Callable) -> Callable:
|
|||||||
def decorated_function(
|
def decorated_function(
|
||||||
*args: Any, **kwargs: Any
|
*args: Any, **kwargs: Any
|
||||||
) -> Union[Callable, HttpResponse]:
|
) -> Union[Callable, HttpResponse]:
|
||||||
response_object, user = verify_user(request, verify_admin=True)
|
verify_admin = True
|
||||||
if response_object:
|
return verify_auth_user(f, verify_admin, *args, **kwargs)
|
||||||
return response_object
|
|
||||||
return f(user, *args, **kwargs)
|
|
||||||
|
|
||||||
return decorated_function
|
return decorated_function
|
||||||
|
Loading…
Reference in New Issue
Block a user