diff --git a/docs/policies/expression/index.md b/docs/policies/expression/index.md index 418c4b9eb..2bf6b2fb0 100644 --- a/docs/policies/expression/index.md +++ b/docs/policies/expression/index.md @@ -10,6 +10,7 @@ The following objects are passed into the variable: - `request.user`: The current User, which the Policy is applied against. ([ref](../../property-mappings/reference/user-object.md)) - `request.http_request`: The Django HTTP Request, as documented [here](https://docs.djangoproject.com/en/3.0/ref/request-response/#httprequest-objects). - `request.obj`: A Django Model instance. This is only set if the Policy is ran against an object. +- `pb_flow_plan`: Current Plan if Policy is called while a flow is active. - `pb_is_sso_flow`: Boolean which is true if request was initiated by authenticating through an external Provider. - `pb_is_group_member(user, group_name)`: Function which checks if `user` is member of a Group with Name `gorup_name`. - `pb_logger`: Standard Python Logger Object, which can be used to debug expressions. diff --git a/passbook/core/templatetags/passbook_user_settings.py b/passbook/core/templatetags/passbook_user_settings.py index b00f827f0..7c0287eec 100644 --- a/passbook/core/templatetags/passbook_user_settings.py +++ b/passbook/core/templatetags/passbook_user_settings.py @@ -23,7 +23,6 @@ def user_stages(context: RequestContext) -> List[UIUserSettings]: if not user_settings: continue matching_stages.append(user_settings) - print(matching_stages) return matching_stages diff --git a/passbook/flows/tests/test_misc.py b/passbook/flows/tests/test_misc.py index 2fb773ee1..40e4bc0ea 100644 --- a/passbook/flows/tests/test_misc.py +++ b/passbook/flows/tests/test_misc.py @@ -17,6 +17,7 @@ class TestFlowsMisc(TestCase): """Test that stage serializer returns the correct type""" obj = DummyStage() self.assertEqual(StageSerializer().get_type(obj), "dummy") + self.assertEqual(StageSerializer().get_verbose_name(obj), "Dummy Stage") def test_api_viewset(self): """Test that stage serializer returns the correct type""" diff --git a/passbook/policies/expression/evaluator.py b/passbook/policies/expression/evaluator.py index b50b663fc..6e10ea313 100644 --- a/passbook/policies/expression/evaluator.py +++ b/passbook/policies/expression/evaluator.py @@ -9,6 +9,7 @@ from jinja2.nativetypes import NativeEnvironment from structlog import get_logger from passbook.flows.planner import PLAN_CONTEXT_SSO +from passbook.flows.views import SESSION_KEY_PLAN from passbook.lib.utils.http import get_client_ip from passbook.policies.types import PolicyRequest, PolicyResult @@ -54,13 +55,14 @@ class Evaluator: kwargs["pb_is_group_member"] = Evaluator.jinja2_func_is_group_member kwargs["pb_logger"] = get_logger() if request.http_request: - # TODO: Get access to current plan kwargs["pb_is_sso_flow"] = request.http_request.session.get( PLAN_CONTEXT_SSO, False ) kwargs["pb_client_ip"] = ( get_client_ip(request.http_request) or "255.255.255.255" ) + if SESSION_KEY_PLAN in request.http_request.session: + kwargs["pb_flow_plan"] = request.http_request.session[SESSION_KEY_PLAN] return kwargs def evaluate(self, expression_source: str, request: PolicyRequest) -> PolicyResult: diff --git a/passbook/policies/expression/templates/policy/expression/form.html b/passbook/policies/expression/templates/policy/expression/form.html index b8c50910d..14bfa626e 100644 --- a/passbook/policies/expression/templates/policy/expression/form.html +++ b/passbook/policies/expression/templates/policy/expression/form.html @@ -13,6 +13,7 @@
  • request.user: Passbook User Object (Reference)
  • request.http_request: Django HTTP Request Object (Reference)
  • request.obj: Model the Policy is run against.
  • +
  • pb_flow_plan: Current Plan if Policy is called while a flow is active.
  • pb_is_sso_flow: Boolean which is true if request was initiated by authenticating through an external Provider.
  • pb_is_group_member(user, group_name): Function which checks if user is member of a Group with Name group_name.
  • pb_logger: Standard Python Logger Object, which can be used to debug expressions.
  • diff --git a/passbook/providers/oidc/signals.py b/passbook/providers/oidc/signals.py index 0281464ff..a74550388 100644 --- a/passbook/providers/oidc/signals.py +++ b/passbook/providers/oidc/signals.py @@ -13,4 +13,3 @@ def on_application_save(sender, instance: Application, **_): if isinstance(instance.provider, OpenIDProvider): instance.provider.oidc_client.require_consent = not instance.skip_authorization instance.provider.oidc_client.save() - print("updating skip_authz")