Commit 6b945bf3 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

fix #65, gestion propre de l'historique.

parent cfa6fe09
......@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %}
{% load i18n %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
......@@ -46,14 +47,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ article.type_user }}</td>
<td>{{ article.available_for_everyone }}</td>
<td class="text-right">
{% can_edit article %}
{% can_edit article %}
<a class="btn btn-primary btn-sm" role="button" title="{% trans "Edit" %}" href="{% url 'cotisations:edit-article' article.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
<a class="btn btn-info btn-sm" role="button" title="{% trans "Historique" %}" href="{% url 'cotisations:history' 'article' article.id %}">
<i class="fa fa-history"></i>
</a>
{% acl_end %}
{% history_button article %}
</td>
</tr>
{% endfor %}
......
......@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %}
{% load i18n %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
......@@ -36,14 +37,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<td>{{ banque.name }}</td>
<td class="text-right">
{% can_edit banque %}
<a class="btn btn-primary btn-sm" role="button" title="{% trans "Edit" %}" href="{% url 'cotisations:edit-banque' banque.id %}">
{% can_edit banque %}
<a class="btn btn-primary btn-sm" role="button" title="{% trans "Edit" %}" href="{% url 'cotisations:edit-banque' banque.id %}">
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
<a class="btn btn-info btn-sm" role="button" title="{% trans "Historique" %}" href="{% url 'cotisations:history' 'banque' banque.id %}">
<i class="fa fa-history"></i>
</a>
{% acl_end %}
{% history_button banque %}
</td>
</tr>
{% endfor %}
......
......@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %}
{% load i18n %}
{% load logs_extra %}
<div class="table-responsive">
{% if facture_list.paginator %}
......@@ -86,9 +87,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</li>
{% acl_end %}
<li>
<a href="{% url 'cotisations:history' 'facture' facture.id %}">
<i class="fa fa-history"></i> {% trans "Historique" %}
</a>
{% history_button facture text='History' html_class=''%}
</li>
</ul>
</div>
......
......@@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %}
{% load i18n %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
......@@ -47,9 +48,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="fa fa-edit"></i>
</a>
{% acl_end %}
<a class="btn btn-info btn-sm" role="button" title="{% trans "Historique" %}" href="{% url 'cotisations:history' 'paiement' paiement.id %}">
<i class="fa fa-history"></i>
</a>
{% history_button paiement %}
</td>
</tr>
{% endfor %}
......
......@@ -27,7 +27,6 @@ from __future__ import unicode_literals
from django.conf.urls import url
import re2o
from . import views
from . import payment_methods
......@@ -122,12 +121,6 @@ urlpatterns = [
views.index_paiement,
name='index-paiement'
),
url(
r'history/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
re2o.views.history,
name='history',
kwargs={'application': 'cotisations'},
),
url(
r'^control/$',
views.control,
......
......@@ -33,3 +33,15 @@ register = template.Library()
def classname(obj):
""" Returns the object class name """
return obj.__class__.__name__
@register.inclusion_tag('buttons/history.html')
def history_button(instance, text=None, html_class=None):
"""Creates the correct history button for an instance."""
return {
'application': instance._meta.app_label,
'name': instance._meta.model_name,
'id': instance.id,
'text': text,
'class': html_class,
}
......@@ -39,4 +39,9 @@ urlpatterns = [
url(r'^stats_models/$', views.stats_models, name='stats-models'),
url(r'^stats_users/$', views.stats_users, name='stats-users'),
url(r'^stats_actions/$', views.stats_actions, name='stats-actions'),
url(
r'(?P<application>\w+)/(?P<object_name>\w+)/(?P<object_id>[0-9]+)$',
views.history,
name='history',
),
]
......@@ -2,9 +2,10 @@
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017 Gabriel Détraz
# Copyright © 2017 Goulven Kermarec
# Copyright © 2017 Augustin Lemesle
# Copyright © 2018 Gabriel Détraz
# Copyright © 2018 Goulven Kermarec
# Copyright © 2018 Augustin Lemesle
# Copyright © 2018 Hugo Levy-Falk
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -36,12 +37,15 @@ nombre d'objets par models, nombre d'actions par user, etc
"""
from __future__ import unicode_literals
from itertools import chain
from django.urls import reverse
from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.http import Http404
from django.db.models import Count, Max, F
from django.apps import apps
from reversion.models import Revision
from reversion.models import Version, ContentType
......@@ -453,3 +457,61 @@ def stats_actions(request):
},
}
return render(request, 'logs/stats_users.html', {'stats_list': stats})
def history(request, application, object_name, object_id):
"""Render history for a model.
The model is determined using the `HISTORY_BIND` dictionnary if none is
found, raises a Http404. The view checks if the user is allowed to see the
history using the `can_view` method of the model.
Args:
request: The request sent by the user.
application: Name of the application.
object_name: Name of the model.
object_id: Id of the object you want to acces history.
Returns:
The rendered page of history if access is granted, else the user is
redirected to their profile page, with an error message.
Raises:
Http404: This kind of models doesn't have history.
"""
try:
model = apps.get_model(application, object_name)
except LookupError:
raise Http404(u"Il n'existe pas d'historique pour ce modèle.")
object_name_id = object_name + 'id'
kwargs = {object_name_id: object_id}
try:
instance = model.get_instance(**kwargs)
except model.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect(reverse(
'users:profil',
kwargs={'userid': str(request.user.id)}
))
can, msg = instance.can_view(request.user)
if not can:
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
return redirect(reverse(
'users:profil',
kwargs={'userid': str(request.user.id)}
))
pagination_number = GeneralOption.get_cached_value('pagination_number')
reversions = Version.objects.get_for_object(instance)
if hasattr(instance, 'linked_objects'):
for related_object in chain(instance.linked_objects()):
reversions = (reversions |
Version.objects.get_for_object(related_object))
reversions = re2o_paginator(request, reversions, pagination_number)
return render(
request,
're2o/history.html',
{'reversions': reversions, 'object': instance}
)
......@@ -23,24 +23,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Alias</th>
<th></th>
</tr>
</thead>
{% for alias in alias_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ alias }}</td>
<td class="text-right">
{% can_edit alias %}
{% include 'buttons/edit.html' with href='machines:edit-alias' id=alias.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='domain' id=alias.id %}
</td>
<th>Alias</th>
<th></th>
</tr>
{% endfor %}
</table>
</thead>
{% for alias in alias_list %}
<tr>
<td>{{ alias }}</td>
<td class="text-right">
{% can_edit alias %}
{% include 'buttons/edit.html' with href='machines:edit-alias' id=alias.id %}
{% acl_end %}
{% history_button alias %}
</td>
</tr>
{% endfor %}
</table>
......@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<div class="table-responsive">
<table class="table table-striped">
......@@ -30,28 +31,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<th>Extension</th>
<th>Droit infra pour utiliser ?</th>
<th>Enregistrement SOA</th>
<th>Enregistrement A origin</th>
{% if ipv6_enabled %}
<th>Enregistrement AAAA origin</th>
{% endif %}
<th></th>
<th>Enregistrement SOA</th>
<th>Enregistrement A origin</th>
{% if ipv6_enabled %}
<th>Enregistrement AAAA origin</th>
{% endif %}
<th></th>
</tr>
</thead>
{% for extension in extension_list %}
<tr>
<tr>
<td>{{ extension.name }}</td>
<td>{{ extension.need_infra }}</td>
<td>{{ extension.soa}}</td>
<td>{{ extension.origin }}</td>
<td>{{ extension.origin }}</td>
{% if ipv6_enabled %}
<td>{{ extension.origin_v6 }}</td>
{% endif %}
<td class="text-right">
{% can_edit extension %}
{% can_edit extension %}
{% include 'buttons/edit.html' with href='machines:edit-extension' id=extension.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='extension' id=extension.id %}
{% acl_end %}
{% history_button extension %}
</td>
</tr>
{% endfor %}
......
......@@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<div class="table-responsive">
<table class="table table-striped">
<thead>
......@@ -31,10 +32,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Extension</th>
<th>Nécessite l'autorisation infra</th>
<th>Plage ipv4</th>
<th>Préfixe v6</th>
<th>Préfixe v6</th>
<th>Sur vlan</th>
<th>Ouverture ports par défault</th>
<th></th>
<th>Ouverture ports par défault</th>
<th></th>
<th></th>
</tr>
</thead>
......@@ -43,15 +44,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ type.type }}</td>
<td>{{ type.extension }}</td>
<td>{{ type.need_infra }}</td>
<td>{{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }}</td>
<td>{{ type.prefix_v6 }}</td>
<td>{{ type.domaine_ip_start }}-{{ type.domaine_ip_stop }}</td>
<td>{{ type.prefix_v6 }}</td>
<td>{{ type.vlan }}</td>
<td>{{ type.ouverture_ports }}</td>
<td>{{ type.ouverture_ports }}</td>
<td class="text-right">
{% can_edit type %}
{% can_edit type %}
{% include 'buttons/edit.html' with href='machines:edit-iptype' id=type.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='iptype' id=type.id %}
{% acl_end %}
{% history_button type %}
</td>
</tr>
{% endfor %}
......
......@@ -23,29 +23,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Ipv6</th>
<th>Slaac</th>
<th></th>
</tr>
</thead>
{% for ipv6 in ipv6_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ ipv6.ipv6 }}</td>
<td>{{ ipv6.slaac_ip }}</td>
<td class="text-right">
{% can_edit ipv6 %}
{% include 'buttons/edit.html' with href='machines:edit-ipv6list' id=ipv6.id %}
{% acl_end %}
{% can_delete ipv6 %}
{% include 'buttons/suppr.html' with href='machines:del-ipv6list' id=ipv6.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='ipv6list' id=ipv6.id %}
</td>
<th>Ipv6</th>
<th>Slaac</th>
<th></th>
</tr>
{% endfor %}
</table>
</thead>
{% for ipv6 in ipv6_list %}
<tr>
<td>{{ ipv6.ipv6 }}</td>
<td>{{ ipv6.slaac_ip }}</td>
<td class="text-right">
{% can_edit ipv6 %}
{% include 'buttons/edit.html' with href='machines:edit-ipv6list' id=ipv6.id %}
{% acl_end %}
{% can_delete ipv6 %}
{% include 'buttons/suppr.html' with href='machines:del-ipv6list' id=ipv6.id %}
{% acl_end %}
{% history_button ipv6 %}
</td>
</tr>
{% endfor %}
</table>
......@@ -23,26 +23,27 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Type de machine</th>
<th>Type d'ip correspondant</th>
<th></th>
</tr>
</thead>
{% for type in machinetype_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ type.type }}</td>
<td>{{ type.ip_type }}</td>
<td class="text-right">
{% can_edit type %}
{% include 'buttons/edit.html' with href='machines:edit-machinetype' id=type.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='machinetype' id=type.id %}
</td>
<th>Type de machine</th>
<th>Type d'ip correspondant</th>
<th></th>
</tr>
{% endfor %}
</table>
</thead>
{% for type in machinetype_list %}
<tr>
<td>{{ type.type }}</td>
<td>{{ type.ip_type }}</td>
<td class="text-right">
{% can_edit type %}
{% include 'buttons/edit.html' with href='machines:edit-machinetype' id=type.id %}
{% acl_end %}
{% history_button type %}
</td>
</tr>
{% endfor %}
</table>
......@@ -23,30 +23,31 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Zone concernée</th>
<th>Priorité</th>
<th>Enregistrement</th>
<th></th>
<th></th>
</tr>
</thead>
{% for mx in mx_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ mx.zone }}</td>
<td>{{ mx.priority }}</td>
<td>{{ mx.name }}</td>
<td class="text-right">
<th>Zone concernée</th>
<th>Priorité</th>
<th>Enregistrement</th>
<th></th>
<th></th>
</tr>
</thead>
{% for mx in mx_list %}
<tr>
<td>{{ mx.zone }}</td>
<td>{{ mx.priority }}</td>
<td>{{ mx.name }}</td>
<td class="text-right">
{% can_edit mx %}
{% include 'buttons/edit.html' with href='machines:edit-mx' id=mx.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='mx' id=mx.id %}
</td>
</tr>
{% endfor %}
</table>
{% acl_end %}
{% history_button mx %}
</td>
</tr>
{% endfor %}
</table>
......@@ -23,32 +23,33 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Nom</th>
<th>Type du nas</th>
<th>Type de machine reliées au nas</th>
<th>Mode d'accès</th>
<th>Autocapture mac</th>
<th></th>
</tr>
</thead>
{% for nas in nas_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ nas.name }}</td>
<td>{{ nas.nas_type }}</td>
<td>{{ nas.machine_type }}</td>
<td>{{ nas.port_access_mode }}</td>
<td>{{ nas.autocapture_mac }}</td>
<td class="text-right">
<th>Nom</th>
<th>Type du nas</th>
<th>Type de machine reliées au nas</th>
<th>Mode d'accès</th>
<th>Autocapture mac</th>
<th></th>
</tr>
</thead>
{% for nas in nas_list %}
<tr>
<td>{{ nas.name }}</td>
<td>{{ nas.nas_type }}</td>
<td>{{ nas.machine_type }}</td>
<td>{{ nas.port_access_mode }}</td>
<td>{{ nas.autocapture_mac }}</td>
<td class="text-right">
{% can_edit nas %}
{% include 'buttons/edit.html' with href='machines:edit-nas' id=nas.id %}
{% include 'buttons/edit.html' with href='machines:edit-nas' id=nas.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='nas' id=nas.id %}
</td>
</tr>
{% endfor %}
</table>
{% history_button nas %}
</td>
</tr>
{% endfor %}
</table>
......@@ -23,28 +23,29 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Zone concernée</th>
<th>Interface autoritaire de la zone</th>
<th></th>
<th></th>
</tr>
</thead>
{% for ns in ns_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ ns.zone }}</td>
<td>{{ ns.ns }}</td>
<td class="text-right">
<th>Zone concernée</th>
<th>Interface autoritaire de la zone</th>
<th></th>
<th></th>
</tr>
</thead>
{% for ns in ns_list %}
<tr>
<td>{{ ns.zone }}</td>
<td>{{ ns.ns }}</td>
<td class="text-right">
{% can_edit ns %}
{% include 'buttons/edit.html' with href='machines:edit-ns' id=ns.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='ns' id=ns.id %}
</td>
</tr>
{% endfor %}
</table>
{% acl_end %}
{% history_button ns %}
</td>
</tr>
{% endfor %}
</table>
......@@ -22,26 +22,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
{% endcomment %}
<table class="table table-striped">
<thead>
<tr>
<th>Nom du service</th>
<th>Serveur</th>
<th>Dernière régénération</th>
<th>Régénération nécessaire</th>
<th>Régénération activée</th>
</tr>
</thead>
{% for server in servers_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ server.service }}</td>
<td>{{ server.server }}</td>
<td>{{ server.last_regen }}</td>
<td>{{ server.asked_regen }}</td>
<td>{{ server.need_regen }}</td>
<td class="text-right">
</td>
<th>Nom du service</th>
<th>Serveur</th>
<th>Dernière régénération</th>
<th>Régénération nécessaire</th>
<th>Régénération activée</th>
</tr>
{% endfor %}
</table>
</thead>
{% for server in servers_list %}
<tr>
<td>{{ server.service }}</td>
<td>{{ server.server }}</td>
<td>{{ server.last_regen }}</td>
<td>{{ server.asked_regen }}</td>
<td>{{ server.need_regen }}</td>
<td class="text-right">
</td>
</tr>
{% endfor %}
</table>
......@@ -23,31 +23,32 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% endcomment %}
{% load acl %}
{% load logs_extra %}
<table class="table table-striped">
<thead>
<tr>
<th>Nom du service</th>
<th>Temps minimum avant nouvelle régénération</th>
<th>Temps avant nouvelle génération obligatoire (max)</th>
<th>Serveurs inclus</th>
<th></th>
<th></th>
</tr>
</thead>
{% for service in service_list %}
<table class="table table-striped">
<thead>
<tr>
<td>{{ service.service_type }}</td>
<td>{{ service.min_time_regen }}</td>
<td>{{ service.regular_time_regen }}</td>
<td>{% for serv in service.servers.all %}{{ serv }}, {% endfor %}</td>
<td class="text-right">
{% can_edit service %}
{% include 'buttons/edit.html' with href='machines:edit-service' id=service.id %}
{% acl_end %}
{% include 'buttons/history.html' with href='machines:history' name='service' id=service.id %}
</td>
<th>Nom du service</th>
<th>Temps minimum avant nouvelle régénération</th>
<th>Temps avant nouvelle génération obligatoire (max)</th>
<th>Serveurs inclus</th>
<th></th>
<th></th>
</tr>
{% endfor %}
</table>
</thead>
{% for service in service_list %}
<tr>
<td>{{ service.service_type }}</td>
<td>{{ service.min_time_regen }}</td>
<td>{{ service.regular_time_regen }}</td>
<td>{% for serv in service.servers.all %}{{ serv }}, {% endfor %}</td>
<td class="text-right">
{% can_edit service %}
{% include 'buttons/edit.html' with href='machines:edit-service' id=service.id %}
{% acl_end %}