mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 07:02:26 +00:00
Fix acl mixin sur users, docstring, fix topologie acl
This commit is contained in:
parent
34024bfc29
commit
c9fd4cd7b5
5 changed files with 56 additions and 46 deletions
|
@ -65,6 +65,13 @@ class Machine(FieldPermissionModelMixin, models.Model):
|
|||
("change_machine_user", "Peut changer le propriétaire d'une machine"),
|
||||
)
|
||||
|
||||
def get_instance(machineid, *args, **kwargs):
|
||||
"""Get the Machine instance with machineid.
|
||||
:param userid: The id
|
||||
:return: The user
|
||||
"""
|
||||
return Machine.objects.get(pk=machineid)
|
||||
|
||||
@staticmethod
|
||||
def can_change_user(user_request, *args, **kwargs):
|
||||
"""Checks if an user is allowed to change the user who owns a
|
||||
|
|
|
@ -38,32 +38,32 @@ class AclMixin(object):
|
|||
|
||||
@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"""
|
||||
|
@ -72,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()
|
||||
|
|
19
topologie/migrations/0055_auto_20180329_0431.py
Normal file
19
topologie/migrations/0055_auto_20180329_0431.py
Normal file
|
@ -0,0 +1,19 @@
|
|||
# -*- 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'),)},
|
||||
),
|
||||
]
|
|
@ -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 />
|
||||
|
|
|
@ -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:
|
||||
return False, u"Vous ne pouvez pas supprimer cet utilisateur."
|
||||
|
||||
def can_view_all(user_request, *args, **kwargs):
|
||||
"""Check if an user can access to the list of every user objects
|
||||
|
||||
:param user_request: The user who wants to view the list.
|
||||
:return: True if the user can view the list and an explanation message.
|
||||
"""
|
||||
if user_request.has_perm('users.view_user'):
|
||||
return True, None
|
||||
else:
|
||||
return False, u"Vous n'avez pas accès à la liste des utilisateurs."
|
||||
|
||||
def can_view(self, user_request, *args, **kwargs):
|
||||
"""Check if an user can view an user object.
|
||||
|
||||
|
@ -791,6 +760,23 @@ class User(FieldPermissionModelMixin, AbstractBaseUser, PermissionsMixin):
|
|||
else:
|
||||
return False, u"Vous ne pouvez voir un autre utilisateur que vous même"
|
||||
|
||||
def can_view_all(user_request, *args, **kwargs):
|
||||
"""Check if an user can access to the list of every user objects
|
||||
|
||||
:param user_request: The user who wants to view the list.
|
||||
:return: True if the user can view the list and an explanation message.
|
||||
"""
|
||||
return user_request.has_perm('users.view_user'), u"Vous n'avez pas accès à la liste des utilisateurs."
|
||||
|
||||
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.
|
||||
"""
|
||||
return user_request.has_perm('users.delete_user'), u"Vous ne pouvez pas supprimer cet utilisateur."
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(User, self).__init__(*args, **kwargs)
|
||||
self.field_permissions = {
|
||||
|
@ -813,8 +799,6 @@ class Adherent(User):
|
|||
null=True
|
||||
)
|
||||
|
||||
|
||||
|
||||
def get_instance(adherentid, *args, **kwargs):
|
||||
"""Try to find an instance of `Adherent` with the given id.
|
||||
|
||||
|
|
Loading…
Reference in a new issue