From 41ba73ac709a7c55b0d183119ad39e87765b7d65 Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Thu, 28 Dec 2017 14:17:09 +0100 Subject: [PATCH] =?UTF-8?q?Nouveau=20syst=C3=A8me=20d'acl=20pour=20machine?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- machines/urls.py | 21 +++----- machines/views.py | 122 ---------------------------------------------- re2o/views.py | 16 +++++- 3 files changed, 21 insertions(+), 138 deletions(-) diff --git a/machines/urls.py b/machines/urls.py index 3c437f22..960afa8f 100644 --- a/machines/urls.py +++ b/machines/urls.py @@ -24,7 +24,7 @@ from __future__ import unicode_literals from django.conf.urls import url - +import re2o from . import views urlpatterns = [ @@ -76,20 +76,11 @@ urlpatterns = [ url(r'^edit_nas/(?P[0-9]+)$', views.edit_nas, name='edit-nas'), url(r'^del_nas/$', views.del_nas, name='del-nas'), url(r'^index_nas/$', views.index_nas, name='index-nas'), - url(r'^history/(?Pmachine)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pinterface)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pmachinetype)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pextension)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Psoa)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pmx)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pns)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Ptxt)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Psrv)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Piptype)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Palias)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pvlan)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pnas)/(?P[0-9]+)$', views.history, name='history'), - url(r'^history/(?Pservice)/(?P[0-9]+)$', views.history, name='history'), + url( + r'history/(?P\w+)/(?P[0-9]+)$', + re2o.views.history, + name='history', + ), url(r'^$', views.index, name='index'), url(r'^rest/mac-ip/$', views.mac_ip, name='mac-ip'), url(r'^rest/regen-achieved/$', views.regen_achieved, name='regen-achieved'), diff --git a/machines/views.py b/machines/views.py index fc12427a..be51ec27 100644 --- a/machines/views.py +++ b/machines/views.py @@ -1001,128 +1001,6 @@ def index_service(request): servers_list = Service_link.objects.select_related('server__domain__extension').select_related('service').all() return render(request, 'machines/index_service.html', {'service_list':service_list, 'servers_list':servers_list}) -@login_required -def history(request, object, id): - if object == 'machine': - try: - object_instance = Machine.objects.get(pk=id) - except Machine.DoesNotExist: - messages.error(request, "Machine inexistante") - return redirect(reverse('machines:index')) - if not request.user.has_perms(('cableur',)) and object_instance.user != request.user: - messages.error(request, "Vous ne pouvez pas afficher l'historique d'une machine d'un autre user que vous sans droit cableur") - return redirect(reverse( - 'users:profil', - kwargs={'userid':str(request.user.id)} - )) - elif object == 'interface': - try: - object_instance = Interface.objects.get(pk=id) - except Interface.DoesNotExist: - messages.error(request, "Interface inexistante") - return redirect(reverse('machines:index')) - if not request.user.has_perms(('cableur',)) and object_instance.machine.user != request.user: - messages.error(request, "Vous ne pouvez pas afficher l'historique d'une interface d'un autre user que vous sans droit cableur") - return redirect(reverse( - 'users:profil', - kwargs={'userid':str(request.user.id)} - )) - elif object == 'alias': - try: - object_instance = Domain.objects.get(pk=id) - except Domain.DoesNotExist: - messages.error(request, "Alias inexistant") - return redirect(reverse('machines:index')) - if not request.user.has_perms(('cableur',)) and object_instance.cname.interface_parent.machine.user != request.user: - messages.error(request, "Vous ne pouvez pas afficher l'historique d'un alias d'un autre user que vous sans droit cableur") - return redirect(reverse( - 'users:profil', - kwargs={'userid':str(request.user.id)} - )) - elif object == 'machinetype' and request.user.has_perms(('cableur',)): - try: - object_instance = MachineType.objects.get(pk=id) - except MachineType.DoesNotExist: - messages.error(request, "Type de machine inexistant") - return redirect(reverse('machines:index')) - elif object == 'iptype' and request.user.has_perms(('cableur',)): - try: - object_instance = IpType.objects.get(pk=id) - except IpType.DoesNotExist: - messages.error(request, "Type d'ip inexistant") - return redirect(reverse('machines:index')) - elif object == 'extension' and request.user.has_perms(('cableur',)): - try: - object_instance = Extension.objects.get(pk=id) - except Extension.DoesNotExist: - messages.error(request, "Extension inexistante") - return redirect(reverse('machines:index')) - elif object == 'soa' and request.user.has_perms(('cableur',)): - try: - object_instance = SOA.objects.get(pk=id) - except SOA.DoesNotExist: - messages.error(request, "SOA inexistant") - return redirect(reverse('machines:index')) - elif object == 'mx' and request.user.has_perms(('cableur',)): - try: - object_instance = Mx.objects.get(pk=id) - except Mx.DoesNotExist: - messages.error(request, "Mx inexistant") - return redirect(reverse('machines:index')) - elif object == 'txt' and request.user.has_perms(('cableur',)): - try: - object_instance = Txt.objects.get(pk=id) - except Txt.DoesNotExist: - messages.error(request, "Txt inexistant") - return redirect(reverse('machines:index')) - elif object == 'srv' and request.user.has_perms(('cableur',)): - try: - object_instance = Srv.objects.get(pk=id) - except Srv.DoesNotExist: - messages.error(request, "Srv inexistant") - return redirect(reverse('machines:index')) - elif object == 'ns' and request.user.has_perms(('cableur',)): - try: - object_instance = Ns.objects.get(pk=id) - except Ns.DoesNotExist: - messages.error(request, "Ns inexistant") - return redirect(reverse('machines:index')) - elif object == 'service' and request.user.has_perms(('cableur',)): - try: - object_instance = Service.objects.get(pk=id) - except Service.DoesNotExist: - messages.error(request, "Service inexistant") - return redirect(reverse('machines:index')) - elif object == 'vlan' and request.user.has_perms(('cableur',)): - try: - object_instance = Vlan.objects.get(pk=id) - except Vlan.DoesNotExist: - messages.error(request, "Vlan inexistant") - return redirect(reverse('machines:index')) - elif object == 'nas' and request.user.has_perms(('cableur',)): - try: - object_instance = Nas.objects.get(pk=id) - except Nas.DoesNotExist: - messages.error(request, "Nas inexistant") - return redirect(reverse('machines:index')) - else: - messages.error(request, "Objet inconnu") - return redirect(reverse('machines:index')) - options, created = GeneralOption.objects.get_or_create() - pagination_number = options.pagination_number - reversions = Version.objects.get_for_object(object_instance) - paginator = Paginator(reversions, pagination_number) - page = request.GET.get('page') - try: - reversions = paginator.page(page) - except PageNotAnInteger: - # If page is not an integer, deliver first page. - reversions = paginator.page(1) - except EmptyPage: - # If page is out of range (e.g. 9999), deliver last page of results. - reversions = paginator.page(paginator.num_pages) - return render(request, 're2o/history.html', {'reversions': reversions, 'object': object_instance}) - @login_required @can_view_all(OuverturePortList) diff --git a/re2o/views.py b/re2o/views.py index e55cf039..79e54d93 100644 --- a/re2o/views.py +++ b/re2o/views.py @@ -35,7 +35,7 @@ from reversion.models import Version from django.contrib import messages from preferences.models import Service from preferences.models import OptionalUser, GeneralOption -import users, preferences, cotisations, topologie +import users, preferences, cotisations, topologie, machines def form(ctx, template, request): """Form générique, raccourci importé par les fonctions views du site""" @@ -70,6 +70,20 @@ HISTORY_BIND = { 'stack' : topologie.models.Stack, 'model_switch' : topologie.models.ModelSwitch, 'constructor_switch' : topologie.models.ConstructorSwitch, + 'machine' : machines.models.Machine, + 'interface' : machines.models.Interface, + 'alias' : machines.models.Domain, + 'machinetype' : machines.models.MachineType, + 'iptype' : machines.models.IpType, + 'extension' : machines.models.Extension, + 'soa' : machines.models.SOA, + 'mx' : machines.models.Mx, + 'txt' : machines.models.Txt, + 'srv' : machines.models.Srv, + 'ns' : machines.models.Ns, + 'service' : machines.models.Service, + 'vlan' : machines.models.Vlan, + 'nas' : machines.models.Vlan, } @login_required