diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index fe6fb51298..60bde42c69 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -13,6 +13,7 @@ from rest_framework.fields import ( EmailField, HiddenField, IntegerField, + ReadOnlyField, ) from rest_framework.serializers import BaseSerializer @@ -85,6 +86,8 @@ class Prompt(SerializerModel): "required": self.required, } + if self.type == FieldTypes.TEXT_READ_ONLY: + field_class = ReadOnlyField if self.type == FieldTypes.EMAIL: field_class = EmailField if self.type == FieldTypes.NUMBER: @@ -101,14 +104,14 @@ class Prompt(SerializerModel): if self.type == FieldTypes.DATE_TIME: field_class = DateTimeField if self.type == FieldTypes.STATIC: - kwargs["initial"] = self.placeholder + kwargs["default"] = self.placeholder kwargs["required"] = False kwargs["label"] = "" if self.type == FieldTypes.SEPARATOR: kwargs["required"] = False kwargs["label"] = "" if default: - kwargs["initial"] = default + kwargs["default"] = default return field_class(**kwargs) def save(self, *args, **kwargs): diff --git a/authentik/stages/prompt/stage.py b/authentik/stages/prompt/stage.py index 2b4d2430b7..4b23d5f18b 100644 --- a/authentik/stages/prompt/stage.py +++ b/authentik/stages/prompt/stage.py @@ -100,7 +100,8 @@ class PromptChallengeResponse(ChallengeResponse): type__in=[FieldTypes.HIDDEN, FieldTypes.STATIC, FieldTypes.TEXT_READ_ONLY] ) for static_hidden in static_hidden_fields: - attrs[static_hidden.field_key] = self.fields[static_hidden.field_key].initial + field = self.fields[static_hidden.field_key] + attrs[static_hidden.field_key] = field.default # Check if we have two password fields, and make sure they are the same password_fields: QuerySet[Prompt] = self.stage.fields.filter(type=FieldTypes.PASSWORD) @@ -165,10 +166,11 @@ class PromptStageView(ChallengeStageView): def get_challenge(self, *args, **kwargs) -> Challenge: fields = list(self.executor.current_stage.fields.all().order_by("order")) serializers = [] - context_prompt = self.executor.plan.get(PLAN_CONTEXT_PROMPT, {}) + context_prompt = self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}) for field in fields: data = StagePromptSerializer(field).data - data["placeholder"] = context_prompt.get(field.field_key) + if field.field_key in context_prompt: + data["placeholder"] = context_prompt.get(field.field_key) serializers.append(data) challenge = PromptChallenge( data={