From 1d72019645f5470e3730ab9af81cb6fa1a2f37a5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 3 Apr 2021 00:48:15 +0200 Subject: [PATCH] stages/deny: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/deny/forms.py | 16 ------ authentik/stages/deny/models.py | 6 +- web/src/pages/stages/deny/DenyStageForm.ts | 56 +++++++++++++++++++ .../stages/user_delete/UserDeleteStageForm.ts | 2 +- 4 files changed, 59 insertions(+), 21 deletions(-) delete mode 100644 authentik/stages/deny/forms.py create mode 100644 web/src/pages/stages/deny/DenyStageForm.ts diff --git a/authentik/stages/deny/forms.py b/authentik/stages/deny/forms.py deleted file mode 100644 index d1c66e646..000000000 --- a/authentik/stages/deny/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""authentik flows deny forms""" -from django import forms - -from authentik.stages.deny.models import DenyStage - - -class DenyStageForm(forms.ModelForm): - """Form to create/edit DenyStage instances""" - - class Meta: - - model = DenyStage - fields = ["name"] - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/deny/models.py b/authentik/stages/deny/models.py index 5c201de7d..b123674f3 100644 --- a/authentik/stages/deny/models.py +++ b/authentik/stages/deny/models.py @@ -25,10 +25,8 @@ class DenyStage(Stage): return DenyStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.deny.forms import DenyStageForm - - return DenyStageForm + def component(self) -> str: + return "ak-stage-deny-form" class Meta: diff --git a/web/src/pages/stages/deny/DenyStageForm.ts b/web/src/pages/stages/deny/DenyStageForm.ts new file mode 100644 index 000000000..970f6aa87 --- /dev/null +++ b/web/src/pages/stages/deny/DenyStageForm.ts @@ -0,0 +1,56 @@ +import { DenyStage, 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-deny-form") +export class DenyStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesDenyRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: DenyStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: DenyStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesDenyUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesDenyCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + +
`; + } + +} diff --git a/web/src/pages/stages/user_delete/UserDeleteStageForm.ts b/web/src/pages/stages/user_delete/UserDeleteStageForm.ts index 32f6edc82..156286b3e 100644 --- a/web/src/pages/stages/user_delete/UserDeleteStageForm.ts +++ b/web/src/pages/stages/user_delete/UserDeleteStageForm.ts @@ -8,7 +8,7 @@ import { ifDefined } from "lit-html/directives/if-defined"; import "../../../elements/forms/HorizontalFormElement"; @customElement("ak-stage-user-delete-form") -export class UserLogoutStageForm extends Form { +export class UserDeleteStageForm extends Form { set stageUUID(value: string) { new StagesApi(DEFAULT_CONFIG).stagesUserDeleteRead({