diff --git a/authentik/stages/consent/forms.py b/authentik/stages/consent/forms.py deleted file mode 100644 index f61e483fd..000000000 --- a/authentik/stages/consent/forms.py +++ /dev/null @@ -1,17 +0,0 @@ -"""authentik consent stage forms""" -from django import forms - -from authentik.stages.consent.models import ConsentStage - - -class ConsentStageForm(forms.ModelForm): - """Form to edit ConsentStage Instance""" - - class Meta: - - model = ConsentStage - fields = ["name", "mode", "consent_expire_in"] - widgets = { - "name": forms.TextInput(), - "consent_expire_in": forms.TextInput(), - } diff --git a/authentik/stages/consent/models.py b/authentik/stages/consent/models.py index 4a96944e2..9c2fa5433 100644 --- a/authentik/stages/consent/models.py +++ b/authentik/stages/consent/models.py @@ -2,7 +2,6 @@ from typing import Type from django.db import models -from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ from django.views import View from rest_framework.serializers import BaseSerializer @@ -51,10 +50,8 @@ class ConsentStage(Stage): return ConsentStageView @property - def form(self) -> Type[ModelForm]: - from authentik.stages.consent.forms import ConsentStageForm - - return ConsentStageForm + def component(self) -> str: + return "ak-stage-consent-form" class Meta: diff --git a/authentik/stages/invitation/tests.py b/authentik/stages/invitation/tests.py index c0df4b6f7..121f76269 100644 --- a/authentik/stages/invitation/tests.py +++ b/authentik/stages/invitation/tests.py @@ -14,7 +14,6 @@ from authentik.flows.models import Flow, FlowDesignation, FlowStageBinding from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan from authentik.flows.tests.test_views import TO_STAGE_RESPONSE_MOCK from authentik.flows.views import SESSION_KEY_PLAN -from authentik.stages.invitation.forms import InvitationStageForm from authentik.stages.invitation.models import Invitation, InvitationStage from authentik.stages.invitation.stage import INVITATION_TOKEN_KEY, PLAN_CONTEXT_PROMPT from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND @@ -36,11 +35,6 @@ class TestUserLoginStage(TestCase): self.stage = InvitationStage.objects.create(name="invitation") FlowStageBinding.objects.create(target=self.flow, stage=self.stage, order=2) - def test_form(self): - """Test Form""" - data = {"name": "test"} - self.assertEqual(InvitationStageForm(data).is_valid(), True) - @patch( "authentik.flows.views.to_stage_response", TO_STAGE_RESPONSE_MOCK, diff --git a/web/src/pages/stages/consent/ConsentStageForm.ts b/web/src/pages/stages/consent/ConsentStageForm.ts new file mode 100644 index 000000000..6f0a84fdf --- /dev/null +++ b/web/src/pages/stages/consent/ConsentStageForm.ts @@ -0,0 +1,99 @@ +import { ConsentStage, ConsentStageModeEnum, 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"; + +@customElement("ak-stage-consent-form") +export class ConsentStageForm extends Form { + + set stageUUID(value: string) { + new StagesApi(DEFAULT_CONFIG).stagesConsentRead({ + stageUuid: value, + }).then(stage => { + this.stage = stage; + this.showExpiresIn = stage.name === ConsentStageModeEnum.Expiring; + }); + } + + @property({attribute: false}) + stage?: ConsentStage; + + @property({type: Boolean}) + showExpiresIn = false; + + getSuccessMessage(): string { + if (this.stage) { + return gettext("Successfully updated stage."); + } else { + return gettext("Successfully created stage."); + } + } + + send = (data: ConsentStage): Promise => { + if (this.stage) { + return new StagesApi(DEFAULT_CONFIG).stagesConsentUpdate({ + stageUuid: this.stage.pk || "", + data: data + }); + } else { + return new StagesApi(DEFAULT_CONFIG).stagesConsentCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + + + ${gettext("Stage-specific settings")} + +
+ + + + + +

${gettext("Offset after which consent expires. (Format: hours=1;minutes=2;seconds=3).")}

+
+
+
+
`; + } + +}