diff --git a/authentik/policies/dummy/forms.py b/authentik/policies/dummy/forms.py deleted file mode 100644 index ed6dae995..000000000 --- a/authentik/policies/dummy/forms.py +++ /dev/null @@ -1,20 +0,0 @@ -"""authentik Policy forms""" - -from django import forms -from django.utils.translation import gettext as _ - -from authentik.policies.dummy.models import DummyPolicy -from authentik.policies.forms import PolicyForm - - -class DummyPolicyForm(PolicyForm): - """DummyPolicyForm Form""" - - class Meta: - - model = DummyPolicy - fields = PolicyForm.Meta.fields + ["result", "wait_min", "wait_max"] - widgets = { - "name": forms.TextInput(), - } - labels = {"result": _("Allow user")} diff --git a/authentik/policies/dummy/models.py b/authentik/policies/dummy/models.py index ee78e7a55..0f892bdfb 100644 --- a/authentik/policies/dummy/models.py +++ b/authentik/policies/dummy/models.py @@ -1,10 +1,8 @@ """Dummy policy""" from random import SystemRandom from time import sleep -from typing import Type from django.db import models -from django.forms import ModelForm from django.utils.translation import gettext_lazy as _ from rest_framework.serializers import BaseSerializer from structlog.stdlib import get_logger @@ -32,10 +30,8 @@ class DummyPolicy(Policy): return DummyPolicySerializer @property - def form(self) -> Type[ModelForm]: - from authentik.policies.dummy.forms import DummyPolicyForm - - return DummyPolicyForm + def component(self) -> str: + return "ak-policy-dummy-form" def passes(self, request: PolicyRequest) -> PolicyResult: """Wait random time then return result""" diff --git a/web/src/pages/policies/dummy/DummyPolicyForm.ts b/web/src/pages/policies/dummy/DummyPolicyForm.ts new file mode 100644 index 000000000..fc7c4ed25 --- /dev/null +++ b/web/src/pages/policies/dummy/DummyPolicyForm.ts @@ -0,0 +1,95 @@ +import { DummyPolicy, PoliciesApi } 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-policy-dummy-form") +export class DummyPolicyForm extends Form { + + set policyUUID(value: string) { + new PoliciesApi(DEFAULT_CONFIG).policiesDummyRead({ + policyUuid: value, + }).then(policy => { + this.policy = policy; + }); + } + + @property({attribute: false}) + policy?: DummyPolicy; + + getSuccessMessage(): string { + if (this.policy) { + return gettext("Successfully updated policy."); + } else { + return gettext("Successfully created policy."); + } + } + + send = (data: DummyPolicy): Promise => { + if (this.policy) { + return new PoliciesApi(DEFAULT_CONFIG).policiesDummyUpdate({ + policyUuid: this.policy.pk || "", + data: data + }); + } else { + return new PoliciesApi(DEFAULT_CONFIG).policiesDummyCreate({ + data: data + }); + } + }; + + renderForm(): TemplateResult { + return html`
+ + + + +
+ + +
+

${gettext("When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.")}

+
+ + + ${gettext("Policy-specific settings")} + +
+ +
+ + +
+

${gettext("When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged.")}

+
+ + +

${gettext("The policy takes a random time to execute. This controls the minimum time it will take.")}

+
+ + + +
+
+
`; + } + +}