diff --git a/passbook/policies/expression/evaluator.py b/passbook/policies/expression/evaluator.py index 6e10ea313..38c730c55 100644 --- a/passbook/policies/expression/evaluator.py +++ b/passbook/policies/expression/evaluator.py @@ -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))