diff --git a/authentik/stages/user_write/forms.py b/authentik/stages/user_write/forms.py deleted file mode 100644 index 685afc57d..000000000 --- a/authentik/stages/user_write/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""authentik flows write forms""" -from django import forms - -from authentik.stages.user_write.models import UserWriteStage - - -class UserWriteStageForm(forms.ModelForm): - """Form to write/edit UserWriteStage instances""" - - class Meta: - - model = UserWriteStage - fields = ["name"] - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/user_write/models.py b/authentik/stages/user_write/models.py index f4d8b63c4..49c2650e5 100644 --- a/authentik/stages/user_write/models.py +++ b/authentik/stages/user_write/models.py @@ -26,10 +26,8 @@ class UserWriteStage(Stage): return UserWriteStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.user_write.forms import UserWriteStageForm - - return UserWriteStageForm + def component(self) -> str: + return "ak-stage-user-write-form" class Meta: diff --git a/web/src/pages/stages/user_write/UserWriteStageForm.ts b/web/src/pages/stages/user_write/UserWriteStageForm.ts new file mode 100644 index 000000000..514a58c98 --- /dev/null +++ b/web/src/pages/stages/user_write/UserWriteStageForm.ts @@ -0,0 +1,56 @@ +import { UserWriteStage, 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"; + +@customElement("ak-stage-user-write-form") +export class UserWriteStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesUserWriteRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: UserWriteStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: UserWriteStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesUserWriteUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesUserWriteCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + +
`; + } + +}