From 995f3a13d150002e734a4b1661a7cd4c0ebad9c3 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Apr 2021 01:03:43 +0200 Subject: [PATCH] stages/authenticator_static: migrate to web Signed-off-by: Jens Langhammer --- .../stages/authenticator_static/forms.py | 17 ---- .../stages/authenticator_static/models.py | 8 +- .../AuthenticatorStaticStageForm.ts | 91 +++++++++++++++++++ 3 files changed, 93 insertions(+), 23 deletions(-) delete mode 100644 authentik/stages/authenticator_static/forms.py create mode 100644 web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts diff --git a/authentik/stages/authenticator_static/forms.py b/authentik/stages/authenticator_static/forms.py deleted file mode 100644 index 95e6b3447..000000000 --- a/authentik/stages/authenticator_static/forms.py +++ /dev/null @@ -1,17 +0,0 @@ -"""Static Authenticator forms""" -from django import forms - -from authentik.stages.authenticator_static.models import AuthenticatorStaticStage - - -class AuthenticatorStaticStageForm(forms.ModelForm): - """Static Authenticator Stage setup form""" - - class Meta: - - model = AuthenticatorStaticStage - fields = ["name", "configure_flow", "token_count"] - - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/authenticator_static/models.py b/authentik/stages/authenticator_static/models.py index d0497b65a..63bff7e47 100644 --- a/authentik/stages/authenticator_static/models.py +++ b/authentik/stages/authenticator_static/models.py @@ -33,12 +33,8 @@ class AuthenticatorStaticStage(ConfigurableStage, Stage): return AuthenticatorStaticStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.authenticator_static.forms import ( - AuthenticatorStaticStageForm, - ) - - return AuthenticatorStaticStageForm + def component(self) -> str: + return "ak-stage-authenticator-static-form" @property def ui_user_settings(self) -> Optional[UserSettingSerializer]: diff --git a/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts b/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts new file mode 100644 index 000000000..5c2b423d2 --- /dev/null +++ b/web/src/pages/stages/authenticator_static/AuthenticatorStaticStageForm.ts @@ -0,0 +1,91 @@ +import { FlowDesignationEnum, FlowsApi, AuthenticatorStaticStage, 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-authenticator-static-form") +export class AuthenticatorStaticStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: AuthenticatorStaticStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: AuthenticatorStaticStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorStaticUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesUserWriteCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + + + + +

${gettext("Flow used by an authenticated user to configure this Stage. If empty, user will not be able to configure this stage.")}

+
+
+
+
`; + } + +}