From 128af67011ef8163a20f1227bfacfe02d3c714e9 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 23:52:55 +0200 Subject: [PATCH] stages/user_logout: migrate to web Signed-off-by: Jens Langhammer --- authentik/stages/user_logout/forms.py | 16 ------ authentik/stages/user_logout/models.py | 7 +-- .../stages/user_logout/UserLogoutStageForm.ts | 56 +++++++++++++++++++ 3 files changed, 58 insertions(+), 21 deletions(-) delete mode 100644 authentik/stages/user_logout/forms.py create mode 100644 web/src/pages/stages/user_logout/UserLogoutStageForm.ts diff --git a/authentik/stages/user_logout/forms.py b/authentik/stages/user_logout/forms.py deleted file mode 100644 index 44d3cba4c..000000000 --- a/authentik/stages/user_logout/forms.py +++ /dev/null @@ -1,16 +0,0 @@ -"""authentik flows logout forms""" -from django import forms - -from authentik.stages.user_logout.models import UserLogoutStage - - -class UserLogoutStageForm(forms.ModelForm): - """Form to create/edit UserLogoutStage instances""" - - class Meta: - - model = UserLogoutStage - fields = ["name"] - widgets = { - "name": forms.TextInput(), - } diff --git a/authentik/stages/user_logout/models.py b/authentik/stages/user_logout/models.py index 8f07a5236..ff92f545b 100644 --- a/authentik/stages/user_logout/models.py +++ b/authentik/stages/user_logout/models.py @@ -1,7 +1,6 @@ """logout stage models""" from typing import Type -from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer @@ -25,10 +24,8 @@ class UserLogoutStage(Stage): return UserLogoutStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.user_logout.forms import UserLogoutStageForm - - return UserLogoutStageForm + def component(self) -> str: + return "ak-stage-user-logout-form" class Meta: diff --git a/web/src/pages/stages/user_logout/UserLogoutStageForm.ts b/web/src/pages/stages/user_logout/UserLogoutStageForm.ts new file mode 100644 index 000000000..23bba1f67 --- /dev/null +++ b/web/src/pages/stages/user_logout/UserLogoutStageForm.ts @@ -0,0 +1,56 @@ +import { UserLogoutStage, 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-logout-form") +export class UserLogoutStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesUserLogoutRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + }); + } + + @property({attribute: false}) + stage?: UserLogoutStage; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: UserLogoutStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesUserLogoutCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + +
`; + } + +}