admin: add basic audit display

This commit is contained in:
Jens Langhammer 2018-12-14 10:28:37 +01:00
parent 258d59ef1b
commit a373054e90
5 changed files with 128 additions and 1 deletions

View File

@ -0,0 +1,84 @@
{% extends "administration/base.html" %}
{% load i18n %}
{% load utils %}
{% block title %}
{% title %}
{% endblock %}
{% block content %}
<div class="container">
<h1>{% trans "Audit Log" %}</h1>
<div id="pf-list-standard" class="list-group list-view-pf list-view-pf-view">
{% for entry in object_list %}
<div class="list-group-item">
<div class="list-view-pf-main-info">
<div class="list-view-pf-left">
<span class="fa fa-plane list-view-pf-icon-sm"></span>
</div>
<div class="list-view-pf-body">
<div class="list-view-pf-description">
<div class="list-group-item-heading">
{{ entry.action }}
</div>
<div class="list-group-item-text">
</div>
</div>
<div class="list-view-pf-additional-info">
<div class="list-view-pf-additional-info-item">
<span class="pficon pficon-user"></span>
<strong>{{ entry.user }}</strong>
</div>
<div class="list-view-pf-additional-info-item">
<span class="pficon pficon-screen"></span>
<strong>{{ entry.request_ip }}</strong>
</div>
<div class="list-view-pf-additional-info-item">
<span class="pficon pficon-cluster"></span>
<strong>{{ entry.app|default:'-' }}</strong>
</div>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
<script>
$(document).ready(function () {
// Row Checkbox Selection
$("#pf-list-standard input[type='checkbox']").change(function (e) {
if ($(this).is(":checked")) {
$(this).closest('.list-group-item').addClass("active");
} else {
$(this).closest('.list-group-item').removeClass("active");
}
});
// toggle dropdown menu
$('#pf-list-standard .list-view-pf-actions').on('show.bs.dropdown', function () {
var $this = $(this);
var $dropdown = $this.find('.dropdown');
var space = $(window).height() - $dropdown[0].getBoundingClientRect().top - $this.find('.dropdown-menu').outerHeight(true);
$dropdown.toggleClass('dropup', space < 10);
});
// allow users to select multiple list items with shift key
$('#pf-list-standard .list-group').on('click', '.list-view-pf-checkbox>input', function (event) {
var $list = $('.list-group');
var prevIndex = $list.data('preIndex');
var $listItems = $list.children('.list-group-item');
var $currentItem = $(this).closest('.list-group-item');
if (event.shiftKey && prevIndex > -1 && this.checked) {
var currentIndex = $listItems.index($currentItem);
var $selectScope = currentIndex - prevIndex > 0
? $currentItem.prevAll().not($listItems.eq(prevIndex).prevAll().addBack())
: $listItems.eq(prevIndex).prevAll().not($currentItem.prevAll().addBack());
$selectScope.addClass('active').find('.list-view-pf-checkbox').children('input').prop('checked', true);
}
$list.data('preIndex', this.checked ? $listItems.index($currentItem) : -1);
});
});
</script>
{% include 'partials/pagination.html' %}
</div>
{% endblock %}

View File

@ -26,6 +26,9 @@
<li>
<a href="#">{% trans 'Users' %}</a>
</li>
<li class="{% is_active 'passbook_admin:audit-log' %}">
<a href="{% url 'passbook_admin:audit-log' %}">{% trans 'Audit Log' %}</a>
</li>
<li class="{% is_active_app 'admin' %}">
<a href="{% url 'admin:index' %}">{% trans 'Django' %}</a>
</li>

View File

@ -1,7 +1,7 @@
"""passbook URL Configuration"""
from django.urls import path
from passbook.admin.views import (applications, invitations, overview,
from passbook.admin.views import (applications, audit, invitations, overview,
providers, rules, sources)
urlpatterns = [
@ -40,5 +40,7 @@ urlpatterns = [
invitations.InvitationCreateView.as_view(), name='invitation-create'),
path('invitations/<uuid:pk>/delete/',
invitations.InvitationDeleteView.as_view(), name='invitation-delete'),
# Audit Log
path('audit/', audit.AuditEntryListView.as_view(), name='audit-log'),
# path('api/v1/', include('passbook.admin.api.v1.urls'))
]

View File

@ -0,0 +1,16 @@
"""passbook AuditEntry administration"""
from django.views.generic import ListView
from passbook.admin.mixins import AdminRequiredMixin
from passbook.audit.models import AuditEntry
class AuditEntryListView(AdminRequiredMixin, ListView):
"""Show list of all invitations"""
model = AuditEntry
template_name = 'administration/audit/list.html'
paginate_by = 10
def get_queryset(self):
return AuditEntry.objects.all().order_by('-created')

View File

@ -0,0 +1,22 @@
{% load i18n %}
<div class="btn-group">
{% with param=get_param|default:'page' %}
{% if page_obj.has_previous %}
<a class="btn btn-default" href="?{{ param }}={{ page_obj.previous_page_number }}"><span class="fa fa-angle-left"></span></a>
{% else %}
<a class="btn btn-default disabled" href=""><span class="fa fa-angle-left"></span></a>
{% endif %}
<span class="btn btn-default">
{% blocktrans with current=page_obj.number total=page_obj.paginator.num_pages %}
Page {{ current }} of {{ total }}
{% endblocktrans %}
</span>
{% if page_obj.has_next %}
<a class="btn btn-default" href="?{{ param }}={{ page_obj.next_page_number }}"><span class="fa fa-angle-right"></span></a>
{% else %}
<a class="btn btn-default disabled" href=""><span class="fa fa-angle-right"></span></a>
{% endif %}
{% endwith %}
</div>
<hr>