stages/prompt: fix type in Prompt not having enum set

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-11-01 20:42:45 +01:00
parent 73d991e75a
commit af83308fd4
4 changed files with 24 additions and 18 deletions

View File

@ -176,6 +176,7 @@ SPECTACULAR_SETTINGS = {
"FlowDesignationEnum": "authentik.flows.models.FlowDesignation",
"PolicyEngineMode": "authentik.policies.models.PolicyEngineMode",
"ProxyMode": "authentik.providers.proxy.models.ProxyMode",
"PromptTypeEnum": "authentik.stages.prompt.models.FieldTypes",
},
"ENUM_ADD_EXPLICIT_BLANK_NULL_CHOICE": False,
"POSTPROCESSING_HOOKS": [

View File

@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponse
from django.http.request import QueryDict
from django.utils.translation import gettext_lazy as _
from guardian.shortcuts import get_anonymous_user
from rest_framework.fields import BooleanField, CharField, IntegerField
from rest_framework.fields import BooleanField, CharField, ChoiceField, IntegerField
from rest_framework.serializers import ValidationError
from structlog.stdlib import get_logger
@ -31,7 +31,7 @@ class StagePromptSerializer(PassiveSerializer):
field_key = CharField()
label = CharField(allow_blank=True)
type = CharField()
type = ChoiceField(choices=FieldTypes.choices)
required = BooleanField()
placeholder = CharField(allow_blank=True)
order = IntegerField()

View File

@ -29646,7 +29646,7 @@ components:
label:
type: string
type:
type: string
$ref: '#/components/schemas/PromptTypeEnum'
required:
type: boolean
placeholder:

View File

@ -13,7 +13,12 @@ import PFLogin from "@patternfly/patternfly/components/Login/login.css";
import PFTitle from "@patternfly/patternfly/components/Title/title.css";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
import { PromptChallenge, PromptChallengeResponseRequest, StagePrompt } from "@goauthentik/api";
import {
PromptChallenge,
PromptChallengeResponseRequest,
PromptTypeEnum,
StagePrompt,
} from "@goauthentik/api";
import "../../../elements/Divider";
import "../../../elements/EmptyState";
@ -28,7 +33,7 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
renderPromptInner(prompt: StagePrompt): string {
switch (prompt.type) {
case "text":
case PromptTypeEnum.Text:
return `<input
type="text"
name="${prompt.fieldKey}"
@ -37,7 +42,7 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
class="pf-c-form-control"
?required=${prompt.required}
value="">`;
case "username":
case PromptTypeEnum.Username:
return `<input
type="text"
name="${prompt.fieldKey}"
@ -46,7 +51,7 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
class="pf-c-form-control"
?required=${prompt.required}
value="">`;
case "email":
case PromptTypeEnum.Email:
return `<input
type="email"
name="${prompt.fieldKey}"
@ -54,7 +59,7 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
class="pf-c-form-control"
?required=${prompt.required}
value="">`;
case "password":
case PromptTypeEnum.Password:
return `<input
type="password"
name="${prompt.fieldKey}"
@ -62,37 +67,37 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
autocomplete="new-password"
class="pf-c-form-control"
?required=${prompt.required}>`;
case "number":
case PromptTypeEnum.Number:
return `<input
type="number"
name="${prompt.fieldKey}"
placeholder="${prompt.placeholder}"
class="pf-c-form-control"
?required=${prompt.required}>`;
case "date":
case PromptTypeEnum.Date:
return `<input
type="date"
name="${prompt.fieldKey}"
placeholder="${prompt.placeholder}"
class="pf-c-form-control"
?required=${prompt.required}>`;
case "date-time":
case PromptTypeEnum.DateTime:
return `<input
type="datetime"
name="${prompt.fieldKey}"
placeholder="${prompt.placeholder}"
class="pf-c-form-control"
?required=${prompt.required}>`;
case "separator":
case PromptTypeEnum.Separator:
return `<ak-divider>${prompt.placeholder}</ak-divider>`;
case "hidden":
case PromptTypeEnum.Hidden:
return `<input
type="hidden"
name="${prompt.fieldKey}"
value="${prompt.placeholder}"
class="pf-c-form-control"
?required=${prompt.required}>`;
case "static":
case PromptTypeEnum.Static:
return `<p>${prompt.placeholder}</p>`;
}
return "";
@ -114,7 +119,7 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
>
${this.challenge.fields.map((prompt) => {
// Checkbox is rendered differently
if (prompt.type === "checkbox") {
if (prompt.type === PromptTypeEnum.Checkbox) {
return html`<div class="pf-c-check">
<input
type="checkbox"
@ -132,9 +137,9 @@ export class PromptStage extends BaseStage<PromptChallenge, PromptChallengeRespo
}
// Special types that aren't rendered in a wrapper
if (
prompt.type === "static" ||
prompt.type === "hidden" ||
prompt.type === "separator"
prompt.type === PromptTypeEnum.Static ||
prompt.type === PromptTypeEnum.Hidden ||
prompt.type === PromptTypeEnum.Separator
) {
return unsafeHTML(this.renderPromptInner(prompt));
}