only pass one func to exception kwarg in access decorator
This commit is contained in:
@@ -8,11 +8,7 @@ from atst.domain.task_orders import TaskOrders
|
||||
from atst.domain.exceptions import UnauthorizedError
|
||||
|
||||
|
||||
def evaluate_exceptions(user, exceptions, **kwargs):
|
||||
return True if True in [exc(user, **kwargs) for exc in exceptions] else False
|
||||
|
||||
|
||||
def check_access(permission, message, exceptions, *args, **kwargs):
|
||||
def check_access(permission, message, exception, *args, **kwargs):
|
||||
access_args = {"message": message}
|
||||
|
||||
if "portfolio_id" in kwargs:
|
||||
@@ -23,9 +19,7 @@ def check_access(permission, message, exceptions, *args, **kwargs):
|
||||
task_order = TaskOrders.get(kwargs["task_order_id"])
|
||||
access_args["portfolio"] = task_order.portfolio
|
||||
|
||||
if exceptions and evaluate_exceptions(
|
||||
g.current_user, exceptions, **access_args, **kwargs
|
||||
):
|
||||
if exception is not None and exception(g.current_user, **access_args, **kwargs):
|
||||
return True
|
||||
|
||||
user_can_access(g.current_user, permission, **access_args)
|
||||
@@ -33,12 +27,12 @@ def check_access(permission, message, exceptions, *args, **kwargs):
|
||||
return True
|
||||
|
||||
|
||||
def user_can_access_decorator(permission, message=None, exceptions=None):
|
||||
def user_can_access_decorator(permission, message=None, exception=None):
|
||||
def decorator(f):
|
||||
@wraps(f)
|
||||
def decorated_function(*args, **kwargs):
|
||||
try:
|
||||
check_access(permission, message, exceptions, *args, **kwargs)
|
||||
check_access(permission, message, exception, *args, **kwargs)
|
||||
app.logger.info(
|
||||
"[access] User {} accessed {}".format(
|
||||
g.current_user.id, g.current_user.dod_id, request.path
|
||||
|
||||
Reference in New Issue
Block a user