stages/prompt: fix inconsistent policy context for validation policies

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-27 17:05:26 +02:00
parent ad4bc4083d
commit 282b364606
1 changed files with 6 additions and 2 deletions

View File

@ -53,9 +53,11 @@ class PromptChallengeResponse(ChallengeResponse):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
stage: PromptStage = kwargs.pop("stage", None) stage: PromptStage = kwargs.pop("stage", None)
plan: FlowPlan = kwargs.pop("plan", None) plan: FlowPlan = kwargs.pop("plan", None)
request: HttpRequest = kwargs.pop("request", None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.stage = stage self.stage = stage
self.plan = plan self.plan = plan
self.request = request
if not self.stage: if not self.stage:
return return
# list() is called so we only load the fields once # list() is called so we only load the fields once
@ -104,8 +106,9 @@ class PromptChallengeResponse(ChallengeResponse):
self._validate_password_fields(*[field.field_key for field in password_fields]) self._validate_password_fields(*[field.field_key for field in password_fields])
user = self.plan.context.get(PLAN_CONTEXT_PENDING_USER, get_anonymous_user()) user = self.plan.context.get(PLAN_CONTEXT_PENDING_USER, get_anonymous_user())
engine = ListPolicyEngine(self.stage.validation_policies.all(), user) engine = ListPolicyEngine(self.stage.validation_policies.all(), user, self.request)
engine.request.context = attrs engine.request.context[PLAN_CONTEXT_PROMPT] = attrs
engine.request.context.update(attrs)
engine.build() engine.build()
result = engine.result result = engine.result
if not result.passing: if not result.passing:
@ -173,6 +176,7 @@ class PromptStageView(ChallengeStageView):
return PromptChallengeResponse( return PromptChallengeResponse(
instance=None, instance=None,
data=data, data=data,
request=self.request,
stage=self.executor.current_stage, stage=self.executor.current_stage,
plan=self.executor.plan, plan=self.executor.plan,
) )