From 75d8641a38293509e4f05af3bc7c4693f6eaba5f Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Apr 2021 00:49:15 +0200 Subject: [PATCH] stages/dummy: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/dummy/forms.py | 16 ------ authentik/stages/dummy/models.py | 6 +-- web/src/pages/stages/dummy/DummyStageForm.ts | 56 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 20 deletions(-) delete mode 100644 authentik/stages/dummy/forms.py create mode 100644 web/src/pages/stages/dummy/DummyStageForm.ts diff --git a/authentik/stages/dummy/forms.py b/authentik/stages/dummy/forms.py deleted file mode 100644 index 92420cdd6..000000000 --- a/authentik/stages/dummy/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""authentik administration forms""" -from django import forms - -from authentik.stages.dummy.models import DummyStage - - -class DummyStageForm(forms.ModelForm): - """Form to create/edit Dummy Stage""" - - class Meta: - - model = DummyStage - fields = ["name"] - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/dummy/models.py b/authentik/stages/dummy/models.py index 344868a82..2790ae3a5 100644 --- a/authentik/stages/dummy/models.py +++ b/authentik/stages/dummy/models.py @@ -27,10 +27,8 @@ class DummyStage(Stage): return DummyStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.dummy.forms import DummyStageForm - - return DummyStageForm + def component(self) -> str: + return "ak-stage-dummy-form" class Meta: diff --git a/web/src/pages/stages/dummy/DummyStageForm.ts b/web/src/pages/stages/dummy/DummyStageForm.ts new file mode 100644 index 000000000..b15e8b00f --- /dev/null +++ b/web/src/pages/stages/dummy/DummyStageForm.ts @@ -0,0 +1,56 @@ +import { DummyStage, 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-dummy-form") +export class DummyStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesDummyRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: DummyStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: DummyStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesDummyUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesDummyCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + +
`; + } + +}