From ac136ec5f6eb689b8e42c47fab5b358b34faa7ae Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 16:48:15 +0200 Subject: [PATCH] policies/expiry: migrate to web Signed-off-by: Jens Langhammer --- authentik/policies/expiry/forms.py | 22 ----- authentik/policies/expiry/models.py | 8 +- web/src/pages/policies/PolicyListPage.ts | 2 + .../pages/policies/expiry/ExpiryPolicyForm.ts | 87 +++++++++++++++++++ 4 files changed, 91 insertions(+), 28 deletions(-) delete mode 100644 authentik/policies/expiry/forms.py create mode 100644 web/src/pages/policies/expiry/ExpiryPolicyForm.ts diff --git a/authentik/policies/expiry/forms.py b/authentik/policies/expiry/forms.py deleted file mode 100644 index 08631358d..000000000 --- a/authentik/policies/expiry/forms.py +++ /dev/null @@ -1,22 +0,0 @@ -"""authentik PasswordExpiry Policy forms""" - -from django import forms -from django.utils.translation import gettext as _ - -from authentik.policies.expiry.models import PasswordExpiryPolicy -from authentik.policies.forms import PolicyForm - - -class PasswordExpiryPolicyForm(PolicyForm): - """Edit PasswordExpiryPolicy instances""" - - class Meta: - - model = PasswordExpiryPolicy - fields = PolicyForm.Meta.fields + ["days", "deny_only"] - widgets = { - "name": forms.TextInput(), - "order": forms.NumberInput(), - "days": forms.NumberInput(), - } - labels = {"deny_only": _("Only fail the policy, don't set user's password.")} diff --git a/authentik/policies/expiry/models.py b/authentik/policies/expiry/models.py index eca0d9d63..dd76d91af 100644 --- a/authentik/policies/expiry/models.py +++ b/authentik/policies/expiry/models.py @@ -1,9 +1,7 @@ """authentik password_expiry_policy Models""" from datetime import timedelta -from typing import Type from django.db import models -from django.forms import ModelForm from django.utils.timezone import now from django.utils.translation import gettext as _ from rest_framework.serializers import BaseSerializer @@ -29,10 +27,8 @@ class PasswordExpiryPolicy(Policy): return PasswordExpiryPolicySerializer @property - def form(self) -> Type[ModelForm]: - from authentik.policies.expiry.forms import PasswordExpiryPolicyForm - - return PasswordExpiryPolicyForm + def component(self) -> str: + return "ak-policy-password-expiry-form" def passes(self, request: PolicyRequest) -> PolicyResult: """If password change date is more than x days in the past, call set_unusable_password diff --git a/web/src/pages/policies/PolicyListPage.ts b/web/src/pages/policies/PolicyListPage.ts index ab32e6522..4a3eaf50e 100644 --- a/web/src/pages/policies/PolicyListPage.ts +++ b/web/src/pages/policies/PolicyListPage.ts @@ -18,6 +18,7 @@ import { ifDefined } from "lit-html/directives/if-defined"; import "./dummy/DummyPolicyForm"; import "./event_matcher/EventMatcherPolicyForm"; import "./expression/ExpressionPolicyForm"; +import "./expiry/ExpiryPolicyForm"; @customElement("ak-policy-list") export class PolicyListPage extends TablePage { @@ -85,6 +86,7 @@ export class PolicyListPage extends TablePage { "dummy": "ak-policy-dummy-form", "eventmatcher": "ak-policy-event-matcher-form", "expression": "ak-policy-expression-form", + "expiry": "ak-policy-password-expiry-form", }}>