policies/expression: add pb_log function to debug
This commit is contained in:
parent
74ddf70cb7
commit
776ad3cfbf
|
@ -46,6 +46,11 @@ class Evaluator:
|
|||
"""Check if `user` is member of group with name `group_name`"""
|
||||
return user.groups.filter(name=group_name).exists()
|
||||
|
||||
@staticmethod
|
||||
def jinja2_log(message, **kwargs):
|
||||
"""Output debug log to console"""
|
||||
return LOGGER.debug("Expression log", _m=message, **kwargs)
|
||||
|
||||
def _get_expression_context(
|
||||
self, request: PolicyRequest, **kwargs
|
||||
) -> Dict[str, Any]:
|
||||
|
@ -53,6 +58,7 @@ class Evaluator:
|
|||
# update passbook/policies/expression/templates/policy/expression/form.html
|
||||
# update docs/policies/expression/index.md
|
||||
kwargs["pb_is_group_member"] = Evaluator.jinja2_func_is_group_member
|
||||
kwargs["pb_log"] = Evaluator.jinja2_log
|
||||
kwargs["pb_logger"] = get_logger()
|
||||
if request.http_request:
|
||||
kwargs["pb_is_sso_flow"] = request.http_request.session.get(
|
||||
|
@ -88,7 +94,7 @@ class Evaluator:
|
|||
if isinstance(result, (list, tuple)) and len(result) == 2:
|
||||
return PolicyResult(*result)
|
||||
if result:
|
||||
return PolicyResult(result)
|
||||
return PolicyResult(bool(result))
|
||||
return PolicyResult(False)
|
||||
except UndefinedError as exc:
|
||||
return PolicyResult(False, str(exc))
|
||||
|
|
Reference in a new issue