admin: improve policy binding listing by showing Target object type

This commit is contained in:
Jens Langhammer 2020-07-04 00:16:46 +02:00
parent 16b966c16e
commit 94281bee88
4 changed files with 62 additions and 23 deletions

View File

@ -28,29 +28,50 @@
<table class="pf-c-table pf-m-compact pf-m-grid-xl" role="grid"> <table class="pf-c-table pf-m-compact pf-m-grid-xl" role="grid">
<thead> <thead>
<tr role="row"> <tr role="row">
<th role="columnheader" scope="col">{% trans 'Enabled' %}</th>
<th role="columnheader" scope="col">{% trans 'Policy' %}</th> <th role="columnheader" scope="col">{% trans 'Policy' %}</th>
<th role="columnheader" scope="col">{% trans 'Target' %}</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> <th role="cell"></th>
</tr> </tr>
</thead> </thead>
<tbody role="rowgroup" class="pf-m-expanded"> <tbody role="rowgroup">
{% for binding in object_list %} {% for pbm in object_list %}
<tr role="row pf-c-table__expandable-row pf-m-expanded"> <tr role="role">
<th role="cell"> <td>
<div>{{ binding.enabled }}</div> {{ pbm }}
</th> <small>
<th role="cell"> {{ pbm|fieldtype }}
<div>{{ binding.policy }}</div> </small>
</th> </td>
<th role="cell"> <td></td>
<div>{{ binding.target|verbose_name }}</div> <td></td>
</th> <td></td>
<td> <td></td>
<a class="pf-c-button pf-m-secondary" href="{% url 'passbook_admin:policy-binding-update' pk=binding.pk %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a> </tr>
<a class="pf-c-button pf-m-danger" href="{% url 'passbook_admin:policy-binding-delete' pk=binding.pk %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a> {% for binding in pbm.bindings %}
</td> <tr class="row pf-c-table__expandable-row pf-m-expanded">
</tr> <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 class="pb-table-action" role="cell">
<a class="pf-c-button pf-m-secondary" href="{% url 'passbook_admin:policy-binding-update' pk=binding.pk %}?back={{ request.get_full_path }}">{% trans 'Edit' %}</a>
<a class="pf-c-button pf-m-danger" href="{% url 'passbook_admin:policy-binding-delete' pk=binding.pk %}?back={{ request.get_full_path }}">{% trans 'Delete' %}</a>
</td>
</tr>
{% endfor %}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View File

@ -4,6 +4,7 @@ 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 QuerySet
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.views.generic import ListView, UpdateView from django.views.generic import ListView, UpdateView
@ -12,7 +13,7 @@ from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
from passbook.admin.views.utils import DeleteMessageView from passbook.admin.views.utils import DeleteMessageView
from passbook.lib.views import CreateAssignPermView from passbook.lib.views import CreateAssignPermView
from passbook.policies.forms import PolicyBindingForm from passbook.policies.forms import PolicyBindingForm
from passbook.policies.models import PolicyBinding from passbook.policies.models import PolicyBinding, PolicyBindingModel
class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView): class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView):
@ -22,7 +23,20 @@ class PolicyBindingListView(LoginRequiredMixin, PermissionListMixin, ListView):
permission_required = "passbook_policies.view_policybinding" permission_required = "passbook_policies.view_policybinding"
paginate_by = 10 paginate_by = 10
ordering = ["order", "target"] ordering = ["order", "target"]
template_name = "administration/policybinding/list.html" 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 = (
PolicyBindingModel.objects.filter(policies__isnull=False)
.select_subclasses()
.select_related()
.order_by("pk")
)
for pbm in objects:
pbm.bindings = PolicyBinding.objects.filter(target__pk=pbm.pbm_uuid)
return objects
class PolicyBindingCreateView( class PolicyBindingCreateView(

View File

@ -1,7 +1,5 @@
"""Utility Widgets""" """Utility Widgets"""
from functools import partial
from itertools import groupby from itertools import groupby
from operator import attrgetter
from django.forms.models import ModelChoiceField, ModelChoiceIterator from django.forms.models import ModelChoiceField, ModelChoiceIterator

View File

@ -235,3 +235,9 @@ input[data-is-monospace] {
.pf-c-alert pre { .pf-c-alert pre {
white-space: pre-wrap; white-space: pre-wrap;
} }
/* Table buttons (Don't wrap, align) */
.pb-table-action {
white-space: nowrap !important;
padding: var(--pf-c-table--cell--PaddingTop) var(--pf-c-table--cell--PaddingRight) var(--pf-c-table--cell--PaddingBottom) var(--pf-c-table--cell--PaddingLeft) !important;
}