admin: remove PolicyBinding list
This commit is contained in:
parent
75d0bd01c2
commit
8008918d8b
|
@ -1,119 +0,0 @@
|
||||||
{% extends "administration/base.html" %}
|
|
||||||
|
|
||||||
{% load i18n %}
|
|
||||||
{% load authentik_utils %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<section class="pf-c-page__main-section pf-m-light">
|
|
||||||
<div class="pf-c-content">
|
|
||||||
<h1>
|
|
||||||
<i class="pf-icon pf-icon-infrastructure"></i>
|
|
||||||
{% trans 'Policy Bindings' %}
|
|
||||||
</h1>
|
|
||||||
<p>{% trans "Bind existing Policies to Models accepting policies." %}</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
<section class="pf-c-page__main-section pf-m-no-padding-mobile">
|
|
||||||
<div class="pf-c-card">
|
|
||||||
{% if object_list %}
|
|
||||||
<div class="pf-c-toolbar">
|
|
||||||
<div class="pf-c-toolbar__content">
|
|
||||||
<div class="pf-c-toolbar__bulk-select">
|
|
||||||
<ak-modal-button href="{% url 'authentik_admin:policy-binding-create' %}">
|
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-primary">
|
|
||||||
{% trans 'Create' %}
|
|
||||||
</ak-spinner-button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
<button role="ak-refresh" class="pf-c-button pf-m-primary">
|
|
||||||
{% trans 'Refresh' %}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
{% include 'partials/pagination.html' %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<table class="pf-c-table pf-m-compact pf-m-grid-xl" role="grid">
|
|
||||||
<thead>
|
|
||||||
<tr role="row">
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Policy' %}</th>
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Enabled' %}</th>
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Order' %}</th>
|
|
||||||
<th role="columnheader" scope="col">{% trans 'Timeout' %}</th>
|
|
||||||
<th role="cell"></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody role="rowgroup">
|
|
||||||
{% for pbm in object_list %}
|
|
||||||
<tr role="role">
|
|
||||||
<td>
|
|
||||||
{{ pbm }}
|
|
||||||
<small>
|
|
||||||
{{ pbm|fieldtype }}
|
|
||||||
</small>
|
|
||||||
</td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
<td></td>
|
|
||||||
</tr>
|
|
||||||
{% for binding in pbm.bindings %}
|
|
||||||
<tr class="row pf-c-table__expandable-row pf-m-expanded">
|
|
||||||
<th role="cell">
|
|
||||||
<div>{{ binding.policy }}</div>
|
|
||||||
<small>
|
|
||||||
{{ binding.policy|fieldtype }}
|
|
||||||
</small>
|
|
||||||
</th>
|
|
||||||
<th role="cell">
|
|
||||||
<div>{{ binding.enabled }}</div>
|
|
||||||
</th>
|
|
||||||
<th role="cell">
|
|
||||||
<div>{{ binding.order }}</div>
|
|
||||||
</th>
|
|
||||||
<th role="cell">
|
|
||||||
<div>{{ binding.timeout }}</div>
|
|
||||||
</th>
|
|
||||||
<td>
|
|
||||||
<ak-modal-button href="{% url 'authentik_admin:policy-binding-update' pk=binding.pk %}">
|
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-secondary">
|
|
||||||
{% trans 'Edit' %}
|
|
||||||
</ak-spinner-button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
<ak-modal-button href="{% url 'authentik_admin:policy-binding-delete' pk=binding.pk %}">
|
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-danger">
|
|
||||||
{% trans 'Delete' %}
|
|
||||||
</ak-spinner-button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<div class="pf-c-pagination pf-m-bottom">
|
|
||||||
{% include 'partials/pagination.html' %}
|
|
||||||
</div>
|
|
||||||
{% else %}
|
|
||||||
<div class="pf-c-empty-state">
|
|
||||||
<div class="pf-c-empty-state__content">
|
|
||||||
<i class="fas fa-cubes pf-c-empty-state__icon" aria-hidden="true"></i>
|
|
||||||
<h1 class="pf-c-title pf-m-lg">
|
|
||||||
{% trans 'No Policy Bindings.' %}
|
|
||||||
</h1>
|
|
||||||
<div class="pf-c-empty-state__body">
|
|
||||||
{% trans 'Currently no policy bindings exist. Click the button below to create one.' %}
|
|
||||||
</div>
|
|
||||||
<ak-modal-button href="{% url 'authentik_admin:policy-binding-create' %}">
|
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-primary">
|
|
||||||
{% trans 'Create' %}
|
|
||||||
</ak-spinner-button>
|
|
||||||
<div slot="modal"></div>
|
|
||||||
</ak-modal-button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
{% endblock %}
|
|
|
@ -90,11 +90,6 @@ urlpatterns = [
|
||||||
name="policy-test",
|
name="policy-test",
|
||||||
),
|
),
|
||||||
# Policy bindings
|
# Policy bindings
|
||||||
path(
|
|
||||||
"policies/bindings/",
|
|
||||||
policies_bindings.PolicyBindingListView.as_view(),
|
|
||||||
name="policies-bindings",
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"policies/bindings/create/",
|
"policies/bindings/create/",
|
||||||
policies_bindings.PolicyBindingCreateView.as_view(),
|
policies_bindings.PolicyBindingCreateView.as_view(),
|
||||||
|
|
|
@ -6,52 +6,17 @@ from django.contrib.auth.mixins import (
|
||||||
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
||||||
)
|
)
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.db.models import Max, QuerySet
|
from django.db.models import Max
|
||||||
from django.urls import reverse_lazy
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import ListView, UpdateView
|
from django.views.generic import UpdateView
|
||||||
from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
from guardian.shortcuts import get_objects_for_user
|
|
||||||
|
|
||||||
from authentik.admin.views.utils import (
|
from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView
|
||||||
BackSuccessUrlMixin,
|
|
||||||
DeleteMessageView,
|
|
||||||
UserPaginateListMixin,
|
|
||||||
)
|
|
||||||
from authentik.lib.views import CreateAssignPermView
|
from authentik.lib.views import CreateAssignPermView
|
||||||
from authentik.policies.forms import PolicyBindingForm
|
from authentik.policies.forms import PolicyBindingForm
|
||||||
from authentik.policies.models import PolicyBinding, PolicyBindingModel
|
from authentik.policies.models import PolicyBinding, PolicyBindingModel
|
||||||
|
|
||||||
|
|
||||||
class PolicyBindingListView(
|
|
||||||
LoginRequiredMixin, PermissionListMixin, UserPaginateListMixin, ListView
|
|
||||||
):
|
|
||||||
"""Show list of all policies"""
|
|
||||||
|
|
||||||
model = PolicyBinding
|
|
||||||
permission_required = "authentik_policies.view_policybinding"
|
|
||||||
ordering = ["order", "target"]
|
|
||||||
template_name = "administration/policy_binding/list.html"
|
|
||||||
|
|
||||||
def get_queryset(self) -> QuerySet:
|
|
||||||
# Since `select_subclasses` does not work with a foreign key, we have to do two queries here
|
|
||||||
# First, get all pbm objects that have bindings attached
|
|
||||||
objects = (
|
|
||||||
get_objects_for_user(
|
|
||||||
self.request.user, "authentik_policies.view_policybindingmodel"
|
|
||||||
)
|
|
||||||
.filter(policies__isnull=False)
|
|
||||||
.select_subclasses()
|
|
||||||
.select_related()
|
|
||||||
.order_by("pk")
|
|
||||||
)
|
|
||||||
for pbm in objects:
|
|
||||||
pbm.bindings = get_objects_for_user(
|
|
||||||
self.request.user, self.permission_required
|
|
||||||
).filter(target__pk=pbm.pbm_uuid)
|
|
||||||
return objects
|
|
||||||
|
|
||||||
|
|
||||||
class PolicyBindingCreateView(
|
class PolicyBindingCreateView(
|
||||||
SuccessMessageMixin,
|
SuccessMessageMixin,
|
||||||
BackSuccessUrlMixin,
|
BackSuccessUrlMixin,
|
||||||
|
@ -66,7 +31,7 @@ class PolicyBindingCreateView(
|
||||||
form_class = PolicyBindingForm
|
form_class = PolicyBindingForm
|
||||||
|
|
||||||
template_name = "generic/create.html"
|
template_name = "generic/create.html"
|
||||||
success_url = reverse_lazy("authentik_admin:policies-bindings")
|
success_url = "/"
|
||||||
success_message = _("Successfully created PolicyBinding")
|
success_message = _("Successfully created PolicyBinding")
|
||||||
|
|
||||||
def get_initial(self) -> dict[str, Any]:
|
def get_initial(self) -> dict[str, Any]:
|
||||||
|
@ -100,7 +65,7 @@ class PolicyBindingUpdateView(
|
||||||
form_class = PolicyBindingForm
|
form_class = PolicyBindingForm
|
||||||
|
|
||||||
template_name = "generic/update.html"
|
template_name = "generic/update.html"
|
||||||
success_url = reverse_lazy("authentik_admin:policies-bindings")
|
success_url = "/"
|
||||||
success_message = _("Successfully updated PolicyBinding")
|
success_message = _("Successfully updated PolicyBinding")
|
||||||
|
|
||||||
|
|
||||||
|
@ -113,5 +78,5 @@ class PolicyBindingDeleteView(
|
||||||
permission_required = "authentik_policies.delete_policybinding"
|
permission_required = "authentik_policies.delete_policybinding"
|
||||||
|
|
||||||
template_name = "generic/delete.html"
|
template_name = "generic/delete.html"
|
||||||
success_url = reverse_lazy("authentik_admin:policies-bindings")
|
success_url = "/"
|
||||||
success_message = _("Successfully deleted PolicyBinding")
|
success_message = _("Successfully deleted PolicyBinding")
|
||||||
|
|
|
@ -11,10 +11,7 @@ from django.utils.translation import gettext as _
|
||||||
from django.views.generic import UpdateView
|
from django.views.generic import UpdateView
|
||||||
from guardian.mixins import PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
|
|
||||||
from authentik.admin.views.utils import (
|
from authentik.admin.views.utils import BackSuccessUrlMixin, DeleteMessageView
|
||||||
BackSuccessUrlMixin,
|
|
||||||
DeleteMessageView,
|
|
||||||
)
|
|
||||||
from authentik.flows.forms import FlowStageBindingForm
|
from authentik.flows.forms import FlowStageBindingForm
|
||||||
from authentik.flows.models import Flow, FlowStageBinding
|
from authentik.flows.models import Flow, FlowStageBinding
|
||||||
from authentik.lib.views import CreateAssignPermView
|
from authentik.lib.views import CreateAssignPermView
|
||||||
|
|
|
@ -7,7 +7,6 @@ from django.shortcuts import get_object_or_404, reverse
|
||||||
from drf_yasg2.utils import swagger_auto_schema
|
from drf_yasg2.utils import swagger_auto_schema
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.mixins import ListModelMixin
|
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.serializers import (
|
from rest_framework.serializers import (
|
||||||
|
@ -16,7 +15,7 @@ from rest_framework.serializers import (
|
||||||
Serializer,
|
Serializer,
|
||||||
SerializerMethodField,
|
SerializerMethodField,
|
||||||
)
|
)
|
||||||
from rest_framework.viewsets import GenericViewSet, ModelViewSet, ReadOnlyModelViewSet
|
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet
|
||||||
|
|
||||||
from authentik.core.api.utils import (
|
from authentik.core.api.utils import (
|
||||||
CacheSerializer,
|
CacheSerializer,
|
||||||
|
|
Reference in New Issue