diff --git a/authentik/stages/prompt/forms.py b/authentik/stages/prompt/forms.py deleted file mode 100644 index 9f3b22bde..000000000 --- a/authentik/stages/prompt/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Prompt forms""" -from django import forms - -from authentik.stages.prompt.models import PromptStage - - -class PromptStageForm(forms.ModelForm): - """Form to create/edit Prompt Stage instances""" - - class Meta: - - model = PromptStage - fields = ["name", "fields", "validation_policies"] - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index c5a00095f..686931103 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -3,7 +3,6 @@ from typing import Type from uuid import uuid4 from django.db import models -from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.fields import ( @@ -144,10 +143,8 @@ class PromptStage(Stage): return PromptStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.prompt.forms import PromptStageForm - - return PromptStageForm + def component(self) -> str: + return "ak-stage-prompt-form" class Meta: diff --git a/web/src/pages/stages/PromptForm.ts b/web/src/pages/stages/PromptForm.ts index 6caa3b9cf..0247cce0f 100644 --- a/web/src/pages/stages/PromptForm.ts +++ b/web/src/pages/stages/PromptForm.ts @@ -7,7 +7,7 @@ import { Form } from "../../elements/forms/Form"; import { ifDefined } from "lit-html/directives/if-defined"; import "../../elements/forms/HorizontalFormElement"; -@customElement("ak-stage-prompt-form") +@customElement("ak-prompt-form") export class PromptForm extends Form { @property({attribute: false}) diff --git a/web/src/pages/stages/PromptListPage.ts b/web/src/pages/stages/PromptListPage.ts index 525719fd3..786c4a443 100644 --- a/web/src/pages/stages/PromptListPage.ts +++ b/web/src/pages/stages/PromptListPage.ts @@ -68,8 +68,8 @@ export class PromptListPage extends TablePage { ${gettext("Update Prompt")} - - + + @@ -98,8 +98,8 @@ export class PromptListPage extends TablePage { ${gettext("Create Prompt")} - - + + diff --git a/web/src/pages/stages/prompt/PromptStageForm.ts b/web/src/pages/stages/prompt/PromptStageForm.ts new file mode 100644 index 000000000..988272e06 --- /dev/null +++ b/web/src/pages/stages/prompt/PromptStageForm.ts @@ -0,0 +1,106 @@ +import { PoliciesApi, PromptStage, StagesApi } from "authentik-api"; +import { gettext } from "django"; +import { customElement, property } from "lit-element"; +import { html, TemplateResult } from "lit-html"; +import { DEFAULT_CONFIG } from "../../../api/Config"; +import { Form } from "../../../elements/forms/Form"; +import { ifDefined } from "lit-html/directives/if-defined"; +import "../../../elements/forms/HorizontalFormElement"; +import "../../../elements/forms/FormGroup"; +import { until } from "lit-html/directives/until"; + +@customElement("ak-stage-prompt-form") +export class PromptStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesPromptStagesRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: PromptStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: PromptStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesPromptStagesCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + +

${gettext("Hold control/command to select multiple items.")}

+
+ + +

${gettext("Selected policies are executed when the stage is submitted to validate the data.")}

+

${gettext("Hold control/command to select multiple items.")}

+
+
+
+
`; + } + +}