|
|
|
@ -76,6 +76,7 @@ import ldapdb.models.fields |
|
|
|
from re2o.settings import RIGHTS_LINK, LDAP, GID_RANGES, UID_RANGES |
|
|
|
from re2o.login import hashNT |
|
|
|
from re2o.field_permissions import FieldPermissionModelMixin |
|
|
|
from re2o.mixins import AclMixin |
|
|
|
|
|
|
|
from cotisations.models import Cotisation, Facture, Paiement, Vente |
|
|
|
from machines.models import Domain, Interface, Machine, regen |
|
|
|
@ -922,7 +923,7 @@ def user_post_delete(sender, **kwargs): |
|
|
|
user.ldap_del() |
|
|
|
regen('mailing') |
|
|
|
|
|
|
|
class ServiceUser(AbstractBaseUser): |
|
|
|
class ServiceUser(AclMixin, AbstractBaseUser): |
|
|
|
""" Classe des users daemons, règle leurs accès au ldap""" |
|
|
|
readonly = 'readonly' |
|
|
|
ACCESS = ( |
|
|
|
@ -992,58 +993,6 @@ class ServiceUser(AbstractBaseUser): |
|
|
|
def get_instance(userid, *args, **kwargs): |
|
|
|
return ServiceUser.objects.get(pk=userid) |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a ServiceUser object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a user object. |
|
|
|
:return: a message and a boolean which is True if the user can create |
|
|
|
or if the `options.all_can_create` is set. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_serviceuser'), ( |
|
|
|
u"Vous n'avez pas le droit de créer un service user" |
|
|
|
) |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a ServiceUser object. |
|
|
|
|
|
|
|
:param self: The ServiceUser which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_serviceuser'), ( |
|
|
|
u"Vous n'avez pas le droit d'éditer les services users" |
|
|
|
) |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a ServiceUser object. |
|
|
|
|
|
|
|
:param self: The ServiceUser who is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if user_request has the right 'infra', and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_serviceuser'), u"Vous n'avez pas le droit de\ |
|
|
|
supprimer un service user" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every ServiceUser 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_serviceuser'), u"Vous n'avez pas le droit de\ |
|
|
|
voir un service user" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a ServiceUser object. |
|
|
|
|
|
|
|
:param self: The targeted ServiceUser. |
|
|
|
:param user_request: The user who ask for viewing the target. |
|
|
|
:return: A boolean telling if the acces is granted and an explanation |
|
|
|
text |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.view_serviceuser'), u"Vous n'avez pas le droit de\ |
|
|
|
voir un service user" |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return self.pseudo |
|
|
|
|
|
|
|
@ -1061,7 +1010,7 @@ def service_user_post_delete(sender, **kwargs): |
|
|
|
service_user.ldap_del() |
|
|
|
|
|
|
|
|
|
|
|
class School(models.Model): |
|
|
|
class School(AclMixin, models.Model): |
|
|
|
""" Etablissement d'enseignement""" |
|
|
|
PRETTY_NAME = "Établissements enregistrés" |
|
|
|
|
|
|
|
@ -1075,60 +1024,11 @@ class School(models.Model): |
|
|
|
def get_instance(schoolid, *args, **kwargs): |
|
|
|
return School.objects.get(pk=schoolid) |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a School object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a user object. |
|
|
|
:return: a message and a boolean which is True if the user can create. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_school'), u"Vous n'avez pas le\ |
|
|
|
droit de créer des écoles" |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a School object. |
|
|
|
|
|
|
|
:param self: The School which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_school'), u"Vous n'avez pas le\ |
|
|
|
droit d'éditer des écoles" |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a School object. |
|
|
|
|
|
|
|
:param self: The School which is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if deletion is granted, and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_school'), u"Vous n'avez pas le\ |
|
|
|
droit de supprimer des écoles" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every School 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_school'), u"Vous n'avez pas le\ |
|
|
|
droit de voir les écoles" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a School object. |
|
|
|
|
|
|
|
:param self: The targeted School. |
|
|
|
:param user_request: The user who ask for viewing the target. |
|
|
|
:return: A boolean telling if the acces is granted and an explanation |
|
|
|
text |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.view_school'), u"Vous n'avez pas le\ |
|
|
|
droit de voir les écoles" |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return self.name |
|
|
|
|
|
|
|
|
|
|
|
class ListRight(Group): |
|
|
|
class ListRight(AclMixin, Group): |
|
|
|
""" Ensemble des droits existants. Chaque droit crée un groupe |
|
|
|
ldap synchronisé, avec gid. |
|
|
|
Permet de gérer facilement les accès serveurs et autres |
|
|
|
@ -1161,55 +1061,6 @@ class ListRight(Group): |
|
|
|
def get_instance(listrightid, *args, **kwargs): |
|
|
|
return ListRight.objects.get(pk=listrightid) |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a ListRight object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a ListRight object. |
|
|
|
:return: a message and a boolean which is True if the user can create. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_listright'), u"Vous n'avez pas le droit\ |
|
|
|
de créer des groupes de droits" |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a ListRight object. |
|
|
|
|
|
|
|
:param self: The object which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_listright'), u"Vous n'avez pas le droit\ |
|
|
|
d'éditer des groupes de droits" |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a ListRight object. |
|
|
|
|
|
|
|
:param self: The object which is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if deletion is granted, and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_listright'), u"Vous n'avez pas le droit\ |
|
|
|
de supprimer des groupes de droits" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every ListRight 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_listright'), u"Vous n'avez pas le droit\ |
|
|
|
de voir les groupes de droits" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a ListRight object. |
|
|
|
|
|
|
|
:param self: The targeted object. |
|
|
|
:param user_request: The user who ask for viewing the target. |
|
|
|
:return: A boolean telling if the acces is granted and an explanation |
|
|
|
text |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.view_listright'), u"Vous n'avez pas le droit\ |
|
|
|
de voir les groupes de droits" |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return self.name |
|
|
|
|
|
|
|
@ -1247,7 +1098,7 @@ def listright_post_delete(sender, **kwargs): |
|
|
|
right.ldap_del() |
|
|
|
|
|
|
|
|
|
|
|
class ListShell(models.Model): |
|
|
|
class ListShell(AclMixin, models.Model): |
|
|
|
"""Un shell possible. Pas de check si ce shell existe, les |
|
|
|
admin sont des grands""" |
|
|
|
PRETTY_NAME = "Liste des shells disponibles" |
|
|
|
@ -1266,60 +1117,11 @@ class ListShell(models.Model): |
|
|
|
"""Return the canonical name of the shell""" |
|
|
|
return self.shell.split("/")[-1] |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a ListShell object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a user object. |
|
|
|
:return: a message and a boolean which is True if the user can create. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_listshell'), u"Vous n'avez pas le\ |
|
|
|
droit de créer des shells" |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a ListShell object. |
|
|
|
|
|
|
|
:param self: The Shell which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_listshell'), u"Vous n'avez pas le\ |
|
|
|
droit d'éditer des shells" |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a ListShell object. |
|
|
|
|
|
|
|
:param self: The Shell which is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if deletion is granted, and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_listshell'), u"Vous n'avez pas le\ |
|
|
|
droit de supprimer des shells" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every ListShell 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_listshell'), u"Vous n'avez pas le\ |
|
|
|
droit de voir les shells" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a ListShell object. |
|
|
|
|
|
|
|
:param self: The targeted ListShell instance. |
|
|
|
:param user_request: The user who ask for viewing the target. |
|
|
|
:return: A boolean telling if the acces is granted and an explanation |
|
|
|
text |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.view_listshell'), u"Vous n'avez pas le\ |
|
|
|
droit de voir les shells" |
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
return self.shell |
|
|
|
|
|
|
|
|
|
|
|
class Ban(models.Model): |
|
|
|
class Ban(AclMixin, models.Model): |
|
|
|
""" Bannissement. Actuellement a un effet tout ou rien. |
|
|
|
Gagnerait à être granulaire""" |
|
|
|
PRETTY_NAME = "Liste des bannissements" |
|
|
|
@ -1369,44 +1171,6 @@ class Ban(models.Model): |
|
|
|
def get_instance(banid, *args, **kwargs): |
|
|
|
return Ban.objects.get(pk=banid) |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a Ban object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a Ban object. |
|
|
|
:return: a message and a boolean which is True if the user can create. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_ban'), u"Vous n'avez pas le droit de\ |
|
|
|
créer des bannissements" |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a Ban object. |
|
|
|
|
|
|
|
:param self: The object which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_ban'), u"Vous n'avez pas le droit\ |
|
|
|
d'éditer des bannissements" |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a Ban object. |
|
|
|
|
|
|
|
:param self: The object which is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if deletion is granted, and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_ban'), u"Vous n'avez pas le droit\ |
|
|
|
de supprimer des bannissements" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every Ban 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_ban'), u"Vous n'avez pas le droit\ |
|
|
|
de voir tous les bannissements" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a Ban object. |
|
|
|
|
|
|
|
@ -1453,7 +1217,7 @@ def ban_post_delete(sender, **kwargs): |
|
|
|
regen('mac_ip_list') |
|
|
|
|
|
|
|
|
|
|
|
class Whitelist(models.Model): |
|
|
|
class Whitelist(AclMixin, models.Model): |
|
|
|
"""Accès à titre gracieux. L'utilisateur ne paye pas; se voit |
|
|
|
accorder un accès internet pour une durée défini. Moins |
|
|
|
fort qu'un ban quel qu'il soit""" |
|
|
|
@ -1475,44 +1239,6 @@ class Whitelist(models.Model): |
|
|
|
def get_instance(whitelistid, *args, **kwargs): |
|
|
|
return Whitelist.objects.get(pk=whitelistid) |
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can create a Whitelist object. |
|
|
|
|
|
|
|
:param user_request: The user who wants to create a Whitelist object. |
|
|
|
:return: a message and a boolean which is True if the user can create. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.add_whitelist'), u"Vous n'avez pas le\ |
|
|
|
droit de créer des accès gracieux" |
|
|
|
|
|
|
|
def can_edit(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can edit a Whitelist object. |
|
|
|
|
|
|
|
:param self: The object which is to be edited. |
|
|
|
:param user_request: The user who requests to edit self. |
|
|
|
:return: a message and a boolean which is True if edition is granted. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.change_whitelist'), u"Vous n'avez pas le\ |
|
|
|
droit d'éditer des accès gracieux" |
|
|
|
|
|
|
|
def can_delete(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can delete a Whitelist object. |
|
|
|
|
|
|
|
:param self: The object which is to be deleted. |
|
|
|
:param user_request: The user who requests deletion. |
|
|
|
:return: True if deletion is granted, and a message. |
|
|
|
""" |
|
|
|
return user_request.has_perm('users.delete_whitelist'), u"Vous n'avez pas le\ |
|
|
|
droit de supprimer des accès gracieux" |
|
|
|
|
|
|
|
def can_view_all(user_request, *args, **kwargs): |
|
|
|
"""Check if an user can access to the list of every Whitelist 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_whitelist'), u"Vous n'avez pas le\ |
|
|
|
droit de voir les accès gracieux" |
|
|
|
|
|
|
|
def can_view(self, user_request, *args, **kwargs): |
|
|
|
"""Check if an user can view a Whitelist object. |
|
|
|
|
|
|
|
|