admin: remove policies views
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
6acfbb7d66
commit
0f76e80341
|
@ -1,16 +1,9 @@
|
|||
"""authentik URL Configuration"""
|
||||
from django.urls import path
|
||||
|
||||
from authentik.admin.views import policies, stages
|
||||
from authentik.admin.views import stages
|
||||
|
||||
urlpatterns = [
|
||||
# Policies
|
||||
path("policies/create/", policies.PolicyCreateView.as_view(), name="policy-create"),
|
||||
path(
|
||||
"policies/<uuid:pk>/update/",
|
||||
policies.PolicyUpdateView.as_view(),
|
||||
name="policy-update",
|
||||
),
|
||||
# Stages
|
||||
path("stages/create/", stages.StageCreateView.as_view(), name="stage-create"),
|
||||
path(
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
"""authentik Policy administration"""
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.contrib.auth.mixins import (
|
||||
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
||||
)
|
||||
from django.contrib.messages.views import SuccessMessageMixin
|
||||
from django.urls import reverse_lazy
|
||||
from django.utils.translation import gettext as _
|
||||
from guardian.mixins import PermissionRequiredMixin
|
||||
|
||||
from authentik.admin.views.utils import InheritanceCreateView, InheritanceUpdateView
|
||||
from authentik.policies.models import Policy
|
||||
|
||||
|
||||
class PolicyCreateView(
|
||||
SuccessMessageMixin,
|
||||
LoginRequiredMixin,
|
||||
DjangoPermissionRequiredMixin,
|
||||
InheritanceCreateView,
|
||||
):
|
||||
"""Create new Policy"""
|
||||
|
||||
model = Policy
|
||||
permission_required = "authentik_policies.add_policy"
|
||||
|
||||
template_name = "generic/create.html"
|
||||
success_url = reverse_lazy("authentik_core:if-admin")
|
||||
success_message = _("Successfully created Policy")
|
||||
|
||||
|
||||
class PolicyUpdateView(
|
||||
SuccessMessageMixin,
|
||||
LoginRequiredMixin,
|
||||
PermissionRequiredMixin,
|
||||
InheritanceUpdateView,
|
||||
):
|
||||
"""Update policy"""
|
||||
|
||||
model = Policy
|
||||
permission_required = "authentik_policies.change_policy"
|
||||
|
||||
template_name = "generic/update.html"
|
||||
success_url = reverse_lazy("authentik_core:if-admin")
|
||||
success_message = _("Successfully updated Policy")
|
|
@ -1,26 +0,0 @@
|
|||
"""Utility Widgets"""
|
||||
from itertools import groupby
|
||||
|
||||
from django.forms.models import ModelChoiceField, ModelChoiceIterator
|
||||
|
||||
|
||||
class GroupedModelChoiceIterator(ModelChoiceIterator):
|
||||
"""ModelChoiceField which groups objects by their verbose_name"""
|
||||
|
||||
def __iter__(self):
|
||||
if self.field.empty_label is not None:
|
||||
yield ("", self.field.empty_label)
|
||||
queryset = self.queryset
|
||||
# Can't use iterator() when queryset uses prefetch_related()
|
||||
if not queryset._prefetch_related_lookups:
|
||||
queryset = queryset.iterator()
|
||||
# We can't use DB-level sorting as we sort by subclass
|
||||
queryset = sorted(queryset, key=lambda x: x._meta.verbose_name)
|
||||
for group, objs in groupby(queryset, key=lambda x: x._meta.verbose_name):
|
||||
yield (group, [self.choice(obj) for obj in objs])
|
||||
|
||||
|
||||
class GroupedModelChoiceField(ModelChoiceField):
|
||||
"""ModelChoiceField which groups objects by their verbose_name"""
|
||||
|
||||
iterator = GroupedModelChoiceIterator
|
|
@ -1,6 +1,5 @@
|
|||
"""policy API Views"""
|
||||
from django.core.cache import cache
|
||||
from django.urls import reverse
|
||||
from drf_yasg.utils import no_body, swagger_auto_schema
|
||||
from guardian.shortcuts import get_objects_for_user
|
||||
from rest_framework import mixins
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
"""General fields"""
|
||||
|
||||
from django import forms
|
||||
|
||||
from authentik.core.models import Group
|
||||
from authentik.lib.widgets import GroupedModelChoiceField
|
||||
from authentik.policies.models import Policy, PolicyBinding, PolicyBindingModel
|
||||
|
||||
|
||||
class PolicyBindingForm(forms.ModelForm):
|
||||
"""Form to edit Policy to PolicyBindingModel Binding"""
|
||||
|
||||
target = GroupedModelChoiceField(
|
||||
queryset=PolicyBindingModel.objects.all().select_subclasses(),
|
||||
to_field_name="pbm_uuid",
|
||||
)
|
||||
policy = GroupedModelChoiceField(
|
||||
queryset=Policy.objects.all().order_by("name").select_subclasses(),
|
||||
required=False,
|
||||
)
|
||||
group = forms.ModelChoiceField(
|
||||
queryset=Group.objects.all().order_by("name"), required=False
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs): # pragma: no cover
|
||||
super().__init__(*args, **kwargs)
|
||||
if "target" in self.initial:
|
||||
self.fields["target"].widget = forms.HiddenInput()
|
||||
|
||||
class Meta:
|
||||
|
||||
model = PolicyBinding
|
||||
fields = ["enabled", "policy", "group", "user", "target", "order", "timeout"]
|
||||
|
||||
|
||||
class PolicyForm(forms.ModelForm):
|
||||
"""Base Policy form"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = Policy
|
||||
fields = ["name", "execution_logging"]
|
|
@ -1,9 +1,7 @@
|
|||
"""authentik HIBP Models"""
|
||||
from hashlib import sha1
|
||||
from typing import Type
|
||||
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext as _
|
||||
from requests import get
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
"""Policy base models"""
|
||||
from typing import Type
|
||||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from model_utils.managers import InheritanceManager
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
@ -147,8 +145,8 @@ class Policy(SerializerModel, CreatedUpdatedModel):
|
|||
objects = InheritanceAutoManager()
|
||||
|
||||
@property
|
||||
def form(self) -> Type[ModelForm]:
|
||||
"""Return Form class used to edit this object"""
|
||||
def component(self) -> str:
|
||||
"""Return component used to edit this object"""
|
||||
raise NotImplementedError
|
||||
|
||||
def __str__(self):
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
"""authentik reputation request policy"""
|
||||
from typing import Type
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext as _
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
"""flow model tests"""
|
||||
from typing import Callable, Type
|
||||
|
||||
from django.forms import ModelForm
|
||||
from django.test import TestCase
|
||||
|
||||
from authentik.lib.utils.reflection import all_subclasses
|
||||
from authentik.policies.models import Policy
|
||||
|
||||
|
||||
class TestPolicyProperties(TestCase):
|
||||
"""Generic model properties tests"""
|
||||
|
||||
|
||||
def policy_tester_factory(model: Type[Policy]) -> Callable:
|
||||
"""Test a form"""
|
||||
|
||||
def tester(self: TestPolicyProperties):
|
||||
model_inst = model()
|
||||
self.assertTrue(issubclass(model_inst.form, ModelForm))
|
||||
|
||||
return tester
|
||||
|
||||
|
||||
for policy_type in all_subclasses(Policy):
|
||||
setattr(
|
||||
TestPolicyProperties,
|
||||
f"test_policy_{policy_type.__name__}",
|
||||
policy_tester_factory(policy_type),
|
||||
)
|
|
@ -20,6 +20,8 @@ import "./event_matcher/EventMatcherPolicyForm";
|
|||
import "./expression/ExpressionPolicyForm";
|
||||
import "./expiry/ExpiryPolicyForm";
|
||||
import "./hibp/HaveIBeenPwnedPolicyForm";
|
||||
import "./password/PasswordPolicyForm";
|
||||
import "./reputation/ReputationPolicyForm";
|
||||
|
||||
@customElement("ak-policy-list")
|
||||
export class PolicyListPage extends TablePage<Policy> {
|
||||
|
@ -89,6 +91,8 @@ export class PolicyListPage extends TablePage<Policy> {
|
|||
"expression": "ak-policy-expression-form",
|
||||
"passwordexpiry": "ak-policy-password-expiry-form",
|
||||
"haveibeenpwend": "ak-policy-hibp-form",
|
||||
"password": "ak-policy-password-form",
|
||||
"reputation": "ak-policy-reputation-form",
|
||||
}}>
|
||||
</ak-proxy-form>
|
||||
<button slot="trigger" class="pf-c-button pf-m-secondary">
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { AdminApi, ExpressionPolicy, EventsApi, PoliciesApi } from "authentik-api";
|
||||
import { ExpressionPolicy, PoliciesApi } from "authentik-api";
|
||||
import { gettext } from "django";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
|
@ -7,6 +7,7 @@ import { Form } from "../../../elements/forms/Form";
|
|||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../../elements/forms/HorizontalFormElement";
|
||||
import "../../../elements/forms/FormGroup";
|
||||
import "../../../elements/CodeMirror";
|
||||
|
||||
@customElement("ak-policy-expression-form")
|
||||
export class ExpressionPolicyForm extends Form<ExpressionPolicy> {
|
||||
|
|
|
@ -114,7 +114,7 @@ export class PasswordPolicyForm extends Form<PasswordPolicy> {
|
|||
label=${gettext("Symbol charset")}
|
||||
?required=${true}
|
||||
name="symbolCharset">
|
||||
<input type="text" value="${ifDefined(this.policy?.symbolCharset || "!\\\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ ")}" class="pf-c-form-control" required>
|
||||
<input type="text" value="${ifDefined(this.policy?.symbolCharset || "!\\\"#$%&'()*+,-./:;<=>?@[]^_`{|}~ ")}" class="pf-c-form-control" required>
|
||||
<p class="pf-c-form__helper-text">${gettext("Characters which are considered as symbols.")}</p>
|
||||
</ak-form-element-horizontal>
|
||||
</div>
|
||||
|
|
Reference in New Issue