Commit ea31157a authored by Gabriel Detraz's avatar Gabriel Detraz

Merge branch 'acl_mixin' into 'master'

Acl mixin

See merge request nounous/re2o!19
parents 96c5df92 c9fd4cd7
......@@ -59,7 +59,7 @@ from machines.models import regen
from re2o.field_permissions import FieldPermissionModelMixin
from re2o.mixins import AclMixin
class Facture(FieldPermissionModelMixin, models.Model):
class Facture(AclMixin, FieldPermissionModelMixin, models.Model):
""" Définition du modèle des factures. Une facture regroupe une ou
plusieurs ventes, rattachée à un user, et reliée à un moyen de paiement
et si il y a lieu un numero pour les chèques. Possède les valeurs
......@@ -114,13 +114,6 @@ class Facture(FieldPermissionModelMixin, models.Model):
).values_list('name', flat=True))
return name
def get_instance(factureid, *args, **kwargs):
return Facture.objects.get(pk=factureid)
def can_create(user_request, *args, **kwargs):
return user_request.has_perm('cotisations.add_facture'), u"Vous n'avez pas le\
droit de créer des factures"
def can_edit(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.change_facture'):
return False, u"Vous n'avez pas le droit d'éditer les factures"
......@@ -144,11 +137,6 @@ class Facture(FieldPermissionModelMixin, models.Model):
else:
return True, None
def can_view_all(user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_facture'):
return False, u"Vous n'avez pas le droit de voir les factures"
return True, None
def can_view(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_facture') and\
self.user != user_request:
......@@ -192,7 +180,7 @@ def facture_post_delete(sender, **kwargs):
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
class Vente(models.Model):
class Vente(AclMixin, models.Model):
"""Objet vente, contient une quantité, une facture parente, un nom,
un prix. Peut-être relié à un objet cotisation, via le boolean
iscotisation"""
......@@ -277,14 +265,6 @@ class Vente(models.Model):
self.update_cotisation()
super(Vente, self).save(*args, **kwargs)
def get_instance(venteid, *args, **kwargs):
return Vente.objects.get(pk=venteid)
def can_create(user_request, *args, **kwargs):
return user_request.has_perm('cotisations.add_vente'), u"Vous n'avez pas le\
droit de créer des ventes"
return True, None
def can_edit(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.change_vente'):
return False, u"Vous n'avez pas le droit d'éditer les ventes"
......@@ -308,11 +288,6 @@ class Vente(models.Model):
else:
return True, None
def can_view_all(user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_vente'):
return False, u"Vous n'avez pas le droit de voir les ventes"
return True, None
def can_view(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_vente') and\
self.facture.user != user_request:
......@@ -402,9 +377,6 @@ class Article(AclMixin, models.Model):
"La durée est obligatoire si il s'agit d'une cotisation"
)
def get_instance(articleid, *args, **kwargs):
return Article.objects.get(pk=articleid)
def __str__(self):
return self.name
......@@ -420,9 +392,6 @@ class Banque(AclMixin, models.Model):
("view_banque", "Peut voir un objet banque"),
)
def get_instance(banqueid, *args, **kwargs):
return Banque.objects.get(pk=banqueid)
def __str__(self):
return self.name
......@@ -443,9 +412,6 @@ class Paiement(AclMixin, models.Model):
("view_paiement", "Peut voir un objet paiement"),
)
def get_instance(paiementid, *args, **kwargs):
return Paiement.objects.get(pk=paiementid)
def __str__(self):
return self.moyen
......@@ -460,7 +426,7 @@ class Paiement(AclMixin, models.Model):
super(Paiement, self).save(*args, **kwargs)
class Cotisation(models.Model):
class Cotisation(AclMixin, models.Model):
"""Objet cotisation, debut et fin, relié en onetoone à une vente"""
PRETTY_NAME = "Cotisations"
......@@ -485,14 +451,6 @@ class Cotisation(models.Model):
("change_all_cotisation", "Superdroit, peut modifier toutes les cotisations"),
)
def get_instance(cotisationid, *args, **kwargs):
return Cotisations.objects.get(pk=cotisationid)
def can_create(user_request, *args, **kwargs):
return user_request.has_perm('cotisations.add_cotisation'), u"Vous n'avez pas le\
droit de créer des cotisations"
return True, None
def can_edit(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.change_cotisation'):
return False, u"Vous n'avez pas le droit d'éditer les cotisations"
......@@ -512,11 +470,6 @@ class Cotisation(models.Model):
else:
return True, None
def can_view_all(user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_cotisation'):
return False, u"Vous n'avez pas le droit de voir les cotisations"
return True, None
def can_view(self, user_request, *args, **kwargs):
if not user_request.has_perm('cotisations.view_cotisation') and\
self.vente.facture.user != user_request:
......
......@@ -38,6 +38,7 @@ from .models import (
Nas,
Service,
OuverturePort,
Ipv6List,
OuverturePortList
)
......@@ -46,6 +47,10 @@ class MachineAdmin(VersionAdmin):
pass
class Ipv6ListAdmin(VersionAdmin):
pass
class IpTypeAdmin(VersionAdmin):
pass
......@@ -124,6 +129,7 @@ admin.site.register(Interface, InterfaceAdmin)
admin.site.register(Domain, DomainAdmin)
admin.site.register(Service, ServiceAdmin)
admin.site.register(Vlan, VlanAdmin)
admin.site.register(Ipv6List, Ipv6ListAdmin)
admin.site.register(Nas, NasAdmin)
admin.site.register(OuverturePort, OuverturePortAdmin)
admin.site.register(OuverturePortList, OuverturePortListAdmin)
......
This diff is collapsed.
This diff is collapsed.
......@@ -3,9 +3,7 @@
# 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
#
# 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
......@@ -30,34 +28,42 @@ class AclMixin(object):
def get_modulename(cls):
return str(cls.__module__).split('.')[0].lower()
@classmethod
def get_instance(cls, *args, **kwargs):
"""Récupère une instance
:param objectid: Instance id à trouver
:return: Une instance de la classe évidemment"""
object_id = kwargs.get(cls.get_classname() + 'id')
return cls.objects.get(pk=object_id)
@classmethod
def can_create(cls, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour créer
un servicelink
"""Verifie que l'user a les bons droits pour créer
un object
:param user_request: instance utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec"""
return user_request.has_perm(cls.get_modulename() + '.add_' + cls.get_classname()), u"Vous n'avez pas le droit\
de créer un " + cls.get_classname()
def can_edit(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour editer
cette instance servicelink
:param self: Instance servicelink à editer
"""Verifie que l'user a les bons droits pour editer
cette instance
:param self: Instance à editer
:param user_request: Utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec"""
return user_request.has_perm(self.get_modulename() + '.change_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
def can_delete(self, user_request, *args, **kwargs):
"""Verifie que l'user a les bons droits infra pour delete
cette instance servicelink
:param self: Instance servicelink à delete
"""Verifie que l'user a les bons droits pour delete
cette instance
:param self: Instance à delete
:param user_request: Utilisateur qui fait la requête
:return: soit True, soit False avec la raison de l'échec"""
return user_request.has_perm(self.get_modulename() + '.delete_' + self.get_classname()), u"Vous n'avez pas le droit d'éditer des " + self.get_classname()
@classmethod
def can_view_all(cls, user_request, *args, **kwargs):
"""Vérifie qu'on peut bien afficher l'ensemble des services,
"""Vérifie qu'on peut bien afficher l'ensemble des objets,
droit particulier view objet correspondant
:param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant"""
......@@ -66,7 +72,7 @@ class AclMixin(object):
def can_view(self, user_request, *args, **kwargs):
"""Vérifie qu'on peut bien voir cette instance particulière avec
droit view objet
:param self: instance service à voir
:param self: instance à voir
:param user_request: instance user qui fait l'edition
:return: True ou False avec la raison de l'échec le cas échéant"""
return user_request.has_perm(self.get_modulename() + '.view_' + self.get_classname()), u"Vous n'avez pas le droit de voir des " + self.get_classname()
......@@ -65,7 +65,7 @@ HISTORY_BIND = {
'school' : users.models.School,
'listright' : users.models.ListRight,
'serviceuser' : users.models.ServiceUser,
'shell' : users.models.ListShell,
'listshell' : users.models.ListShell,
},
'preferences' : {
'service' : preferences.models.Service,
......@@ -81,9 +81,9 @@ HISTORY_BIND = {
'port' : topologie.models.Port,
'room' : topologie.models.Room,
'stack' : topologie.models.Stack,
'model_switch' : topologie.models.ModelSwitch,
'constructor_switch' : topologie.models.ConstructorSwitch,
'ap' : topologie.models.AccessPoint,
'modelswitch' : topologie.models.ModelSwitch,
'constructorswitch' : topologie.models.ConstructorSwitch,
'accesspoint' : topologie.models.AccessPoint,
},
'machines' : {
'machine' : machines.models.Machine,
......@@ -99,7 +99,7 @@ HISTORY_BIND = {
'ns' : machines.models.Ns,
'service' : machines.models.Service,
'vlan' : machines.models.Vlan,
'nas' : machines.models.Vlan,
'nas' : machines.models.Nas,
'ipv6list' : machines.models.Ipv6List,
},
}
......@@ -128,8 +128,10 @@ def history(request, application, object_name, object_id):
model = HISTORY_BIND[application][object_name]
except KeyError as e:
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(object_id)
instance = model.get_instance(**kwargs)
except model.DoesNotExist:
messages.error(request, u"Entrée inexistante")
return redirect(reverse('users:profil',
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2018-03-29 02:31
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('topologie', '0054_auto_20180326_1742'),
]
operations = [
migrations.AlterModelOptions(
name='accesspoint',
options={'permissions': (('view_accesspoint', 'Peut voir une borne'),)},
),
]
......@@ -67,9 +67,6 @@ class Stack(AclMixin, models.Model):
("view_stack", "Peut voir un objet stack"),
)
def get_instance(stack_id, *args, **kwargs):
return Stack.objects.get(pk=stack_id)
def __str__(self):
return " ".join([self.name, self.stack_id])
......@@ -105,9 +102,6 @@ class AccessPoint(AclMixin, Machine):
("view_accesspoint", "Peut voir une borne"),
)
def get_instance(ap_id, *args, **kwargs):
return AccessPoint.objects.get(pk=ap_id)
class Switch(AclMixin, Machine):
""" Definition d'un switch. Contient un nombre de ports (number),
......@@ -146,9 +140,6 @@ class Switch(AclMixin, Machine):
("view_switch", "Peut voir un objet switch"),
)
def get_instance(switch_id, *args, **kwargs):
return Switch.objects.get(pk=switch_id)
def clean(self):
""" Verifie que l'id stack est dans le bon range
Appelle également le clean de la classe parente"""
......@@ -210,9 +201,6 @@ class ModelSwitch(AclMixin, models.Model):
("view_modelswitch", "Peut voir un objet modelswitch"),
)
def get_instance(model_switch_id, *args, **kwargs):
return ModelSwitch.objects.get(pk=model_switch_id)
def __str__(self):
return str(self.constructor) + ' ' + self.reference
......@@ -227,9 +215,6 @@ class ConstructorSwitch(AclMixin, models.Model):
("view_constructorswitch", "Peut voir un objet constructorswitch"),
)
def get_instance(constructor_switch_id, *args, **kwargs):
return ConstructorSwitch.objects.get(pk=constructor_switch_id)
def __str__(self):
return self.name
......@@ -297,14 +282,14 @@ class Port(AclMixin, models.Model):
("view_port", "Peut voir un objet port"),
)
def get_instance(port_id, *args, **kwargs):
def get_instance(portid, *args, **kwargs):
return Port.objects\
.select_related('machine_interface__domain__extension')\
.select_related('machine_interface__machine__switch')\
.select_related('room')\
.select_related('related')\
.prefetch_related('switch__interface_set__domain__extension')\
.get(pk=port_id)
.get(pk=portid)
def make_port_related(self):
""" Synchronise le port distant sur self"""
......@@ -363,9 +348,6 @@ class Room(AclMixin, models.Model):
("view_room", "Peut voir un objet chambre"),
)
def get_instance(room_id, *args, **kwargs):
return Room.objects.get(pk=room_id)
def __str__(self):
return self.name
......
......@@ -49,7 +49,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ap.interface_set.first.details}}</td>
<td>{{ap.location}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'ap' ap.pk %}">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'accesspoint' ap.pk %}">
<i class="fa fa-history"></i>
</a>
{% can_edit ap %}
......
......@@ -39,7 +39,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<tr>
<td>{{constructor_switch}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'constructor_switch' constructor_switch.pk %}">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'constructorswitch' constructor_switch.pk %}">
<i class="fa fa-history"></i>
</a>
{% can_edit constructor_switch %}
......
......@@ -41,7 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{model_switch.reference}}</td>
<td>{{model_switch.constructor}}</td>
<td class="text-right">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'model_switch' model_switch.pk %}">
<a class="btn btn-info btn-sm" role="button" title="Historique" href="{% url 'topologie:history' 'modelswitch' model_switch.pk %}">
<i class="fa fa-history"></i>
</a>
{% can_edit model_switch %}
......
......@@ -52,7 +52,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</td>
<td>
{% if port.related %}
<a href="{% url 'topologie:index-port' switch_id=port.related.switch.id %}">{{ port.related }}</a>
<a href="{% url 'topologie:index-port' switchid=port.related.switch.id %}">{{ port.related }}</a>
{% endif %}
</td>
<td>{{ port.radius }}</td>
......
......@@ -33,9 +33,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:edit-switch' id_switch %}"><i class="fa fa-edit"></i> Editer</a>
{% can_create Port %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:new-port' id_switch %}"><i class="fa fa-plus"></i> Ajouter un port</a>
{% acl_end %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'topologie:create-ports' id_switch %}"><i class="fa fa-plus"></i> Ajouter des ports</a>
{% include "topologie/aff_port.html" with port_list=port_list %}
{% acl_end %}
{% include "topologie/aff_port.html" with port_list=port_list %}
<br />
<br />
<br />
......
......@@ -37,18 +37,18 @@ urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^index_ap/$', views.index_ap, name='index-ap'),
url(r'^new_ap/$', views.new_ap, name='new-ap'),
url(r'^edit_ap/(?P<ap_id>[0-9]+)$',
url(r'^edit_ap/(?P<accesspointid>[0-9]+)$',
views.edit_ap,
name='edit-ap'),
url(r'^create_ports/(?P<switch_id>[0-9]+)$',
url(r'^create_ports/(?P<switchid>[0-9]+)$',
views.create_ports,
name='create-ports'),
url(r'^index_room/$', views.index_room, name='index-room'),
url(r'^new_room/$', views.new_room, name='new-room'),
url(r'^edit_room/(?P<room_id>[0-9]+)$', views.edit_room, name='edit-room'),
url(r'^del_room/(?P<room_id>[0-9]+)$', views.del_room, name='del-room'),
url(r'^edit_room/(?P<roomid>[0-9]+)$', views.edit_room, name='edit-room'),
url(r'^del_room/(?P<roomid>[0-9]+)$', views.del_room, name='del-room'),
url(r'^new_switch/$', views.new_switch, name='new-switch'),
url(r'^switch/(?P<switch_id>[0-9]+)$',
url(r'^switch/(?P<switchid>[0-9]+)$',
views.index_port,
name='index-port'),
url(
......@@ -57,18 +57,18 @@ urlpatterns = [
name='history',
kwargs={'application':'topologie'},
),
url(r'^edit_port/(?P<port_id>[0-9]+)$', views.edit_port, name='edit-port'),
url(r'^new_port/(?P<switch_id>[0-9]+)$', views.new_port, name='new-port'),
url(r'^del_port/(?P<port_id>[0-9]+)$', views.del_port, name='del-port'),
url(r'^edit_switch/(?P<switch_id>[0-9]+)$',
url(r'^edit_port/(?P<portid>[0-9]+)$', views.edit_port, name='edit-port'),
url(r'^new_port/(?P<switchid>[0-9]+)$', views.new_port, name='new-port'),
url(r'^del_port/(?P<portid>[0-9]+)$', views.del_port, name='del-port'),
url(r'^edit_switch/(?P<switchid>[0-9]+)$',
views.edit_switch,
name='edit-switch'),
url(r'^new_stack/$', views.new_stack, name='new-stack'),
url(r'^index_stack/$', views.index_stack, name='index-stack'),
url(r'^edit_stack/(?P<stack_id>[0-9]+)$',
url(r'^edit_stack/(?P<stackid>[0-9]+)$',
views.edit_stack,
name='edit-stack'),
url(r'^del_stack/(?P<stack_id>[0-9]+)$',
url(r'^del_stack/(?P<stackid>[0-9]+)$',
views.del_stack,
name='del-stack'),
url(r'^index_model_switch/$',
......@@ -83,20 +83,20 @@ urlpatterns = [
views.new_model_switch,
name='new-model-switch'
),
url(r'^edit_model_switch/(?P<model_switch_id>[0-9]+)$',
url(r'^edit_model_switch/(?P<modelswitchid>[0-9]+)$',
views.edit_model_switch,
name='edit-model-switch'),
url(r'^del_model_switch/(?P<model_switch_id>[0-9]+)$',
url(r'^del_model_switch/(?P<modelswitchid>[0-9]+)$',
views.del_model_switch,
name='del-model-switch'),
url(r'^new_constructor_switch/$',
views.new_constructor_switch,
name='new-constructor-switch'
),
url(r'^edit_constructor_switch/(?P<constructor_switch_id>[0-9]+)$',
url(r'^edit_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
views.edit_constructor_switch,
name='edit-constructor-switch'),
url(r'^del_constructor_switch/(?P<constructor_switch_id>[0-9]+)$',
url(r'^del_constructor_switch/(?P<constructorswitchid>[0-9]+)$',
views.del_constructor_switch,
name='del-constructor-switch'),
]
......@@ -123,7 +123,7 @@ def index(request):
@login_required
@can_view_all(Port)
@can_view(Switch)
def index_port(request, switch, switch_id):
def index_port(request, switch, switchid):
""" Affichage de l'ensemble des ports reliés à un switch particulier"""
port_list = Port.objects.filter(switch=switch)\
.select_related('room')\
......@@ -143,7 +143,7 @@ def index_port(request, switch, switch_id):
)
return render(request, 'topologie/index_p.html', {
'port_list': port_list,
'id_switch': switch_id,
'id_switch': switchid,
'nom_switch': switch
})
......@@ -250,10 +250,10 @@ def index_model_switch(request):
@login_required
@can_create(Port)
def new_port(request, switch_id):
def new_port(request, switchid):
""" Nouveau port"""
try:
switch = Switch.objects.get(pk=switch_id)
switch = Switch.objects.get(pk=switchid)
except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant")
return redirect(reverse('topologie:index'))
......@@ -271,14 +271,14 @@ def new_port(request, switch_id):
messages.error(request, "Ce port existe déjà")
return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id':switch_id}
kwargs={'switchid':switchid}
))
return form({'id_switch': switch_id,'topoform': port, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
return form({'id_switch': switchid,'topoform': port, 'action_name' : 'Ajouter'}, 'topologie/topo.html', request)
@login_required
@can_edit(Port)
def edit_port(request, port_object, port_id):
def edit_port(request, port_object, portid):
""" Edition d'un port. Permet de changer le switch parent et
l'affectation du port"""
......@@ -293,14 +293,14 @@ def edit_port(request, port_object, port_id):
messages.success(request, "Le port a bien été modifié")
return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id': str(port_object.switch.id)}
kwargs={'switchid': str(port_object.switch.id)}
))
return form({'id_switch': str(port_object.switch.id), 'topoform': port, 'action_name' : 'Editer'}, 'topologie/topo.html', request)
@login_required
@can_delete(Port)
def del_port(request, port, port_id):
def del_port(request, port, portid):
""" Supprime le port"""
if request.method == "POST":
try:
......@@ -314,7 +314,7 @@ def del_port(request, port, port_id):
impossible de le supprimer" % port)
return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id':str(port.switch.id)}
kwargs={'switchid':str(port.switch.id)}
))
return form({'objet': port}, 'topologie/delete.html', request)
......@@ -322,7 +322,7 @@ def del_port(request, port, port_id):
@login_required
@can_create(Stack)
def new_stack(request):
"""Ajoute un nouveau stack : stack_id_min, max, et nombre de switches"""
"""Ajoute un nouveau stack : stackid_min, max, et nombre de switches"""
stack = StackForm(request.POST or None)
if stack.is_valid():
with transaction.atomic(), reversion.create_revision():
......@@ -335,7 +335,7 @@ def new_stack(request):
@login_required
@can_edit(Stack)
def edit_stack(request, stack, stack_id):
def edit_stack(request, stack, stackid):
"""Edition d'un stack (nombre de switches, nom...)"""
stack = StackForm(request.POST or None, instance=stack)
......@@ -354,7 +354,7 @@ def edit_stack(request, stack, stack_id):
@login_required
@can_delete(Stack)
def del_stack(request, stack, stack_id):
def del_stack(request, stack, stackid):
"""Supprime un stack"""
if request.method == "POST":
try:
......@@ -372,7 +372,7 @@ def del_stack(request, stack, stack_id):
@login_required
@can_edit(Stack)
def edit_switchs_stack(request, stack, stack_id):
def edit_switchs_stack(request, stack, stackid):
"""Permet d'éditer la liste des switches dans une stack et l'ajouter"""
if request.method == "POST":
......@@ -440,10 +440,10 @@ def new_switch(request):
@login_required
@can_create(Port)
def create_ports(request, switch_id):
def create_ports(request, switchid):
""" Création d'une liste de ports pour un switch."""
try:
switch = Switch.objects.get(pk=switch_id)
switch = Switch.objects.get(pk=switchid)
except Switch.DoesNotExist:
messages.error(request, u"Switch inexistant")
return redirect(reverse('topologie:index'))
......@@ -471,14 +471,14 @@ def create_ports(request, switch_id):
return redirect(reverse(
'topologie:index-port',
kwargs={'switch_id':switch_id}
kwargs={'switchid':switchid}
))
return form({'id_switch': switch_id, 'topoform': port_form}, 'topologie/switch.html', request)
return form({'id_switch': switchid, 'topoform': port_form}, 'topologie/switch.html', request)
@login_required
@can_edit(Switch)
def edit_switch(request, switch, switch_id):
def edit_switch(request, switch, switchid):
""" Edition d'un switch. Permet de chambre nombre de ports,
place dans le stack, interface et machine associée"""
......@@ -524,7 +524,7 @@ def edit_switch(request, switch, switch_id):
return redirect(reverse('topologie:index'))
i_mbf_param = generate_ipv4_mbf_param(interface_form, False )
return form({
'id_switch': switch_id,
'id_switch': switchid,
'topoform': interface_form,
'machineform': switch_form,
'domainform': domain_form,
......@@ -590,7 +590,7 @@ def new_ap(request):
@login_required
@can_edit(AccessPoint)
def edit_ap(request, ap, ap_id):
def edit_ap(request, ap, accesspointid):
""" Edition d'un switch. Permet de chambre nombre de ports,
place dans le stack, interface et machine associée"""
interface_form = EditInterfaceForm(
......@@ -665,7 +665,7 @@ def new_room(request):
@login_required
@can_edit(Room)
def edit_room(request, room, room_id):
def edit_room(request, room, roomid):
""" Edition numero et details de la chambre"""
room = EditRoomForm(request.POST or None, instance=room)
......@@ -683,7 +683,7 @@ def edit_room(request, room, room_id):
@login_required
@can_delete(Room)
def del_room(request, room, room_id):
def del_room(request, room, roomid):
""" Suppression d'un chambre"""
if request.method == "POST":
try:
......@@ -719,7 +719,7 @@ def new_model_switch(request):
@login_required
@can_edit(ModelSwitch)
def edit_model_switch(request, model_switch, model_switch_id):
def edit_model_switch(request, model_switch, modelswitchid):
""" Edition d'un modèle de switch"""
model_switch = EditModelSwitchForm(request.POST or None, instance=model_switch)
......@@ -737,7 +737,7 @@ def edit_model_switch(request, model_switch, model_switch_id):
@login_required
@can_delete(ModelSwitch)
def del_model_switch(request, model_switch_id):
def del_model_switch(request, model_switch, modelswitchid):
""" Suppression d'un modèle de switch"""
if request.method == "POST":
try:
......@@ -773,7 +773,7 @@ def new_constructor_switch(request):
@login_required
@can_edit(ConstructorSwitch)
def edit_constructor_switch(request, constructor_switch, constructor_switch_id):
def edit_constructor_switch(request, constructor_switch, constructorswitchid):
""" Edition d'un constructeur de switch"""
constructor_switch = EditConstructorSwitchForm(request.POST or None, instance=constructor_switch)
......@@ -791,7 +791,7 @@ def edit_constructor_switch(request, constructor_switch, constructor_switch_id):
@login_required
@can_delete(ConstructorSwitch)
def del_constructor_switch(request, constructor_switch_id):
def del_constructor_switch(request, constructor_switch, constructorswitchid):
""" Suppression d'un constructeur de switch"""
if request.method == "POST":
try:
......
......@@ -171,7 +171,7 @@ class UserManager(BaseUserManager):
"""
return self._create_user(pseudo, surname, email, password, True)
class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin, AclMixin):
""" Definition de l'utilisateur de base.
Champs principaux : name, surnname, pseudo, email, room, password
Herite du django BaseUser et du système d'auth django"""
......@@ -668,14 +668,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
num += 1
return composed_pseudo(num)
def get_instance(userid, *args, **kwargs):
"""Get the User instance with userid.
:param userid: The id
:return: The user
"""
return User.objects.get(pk=userid)
def can_edit(self, user_request, *args, **kwargs):
"""Check if an user can edit an user object.
......@@ -746,29 +738,6 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
def can_change_groups(user_request, *args, **kwargs):
return user_request.has_perm('users.change_user_groups'), "Droit requis pour éditer les groupes de l'user"
def can_delete(self, user_request, *args, **kwargs):
"""Check if an user can delete an user object.
:param self: The user who is to be deleted.
:param user_request: The user who requests deletion.
:return: True if user_request has the right 'bureau', and a message.
"""
if user_request.has_perm('users.delete_user'):
return True, None
else: