From 8ac82b97d332155581d13b471a37f931fd20b21d Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 23:54:00 +0200 Subject: [PATCH] stages/user_write: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/user_write/forms.py | 16 ------ authentik/stages/user_write/models.py | 6 +- .../stages/user_write/UserWriteStageForm.ts | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+), 20 deletions(-) delete mode 100644 authentik/stages/user_write/forms.py create mode 100644 web/src/pages/stages/user_write/UserWriteStageForm.ts 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`
+ + + +
`; + } + +}