Merge branch 'master' of ssh://git.crans.org/git/ldap into cerveaulent
This commit is contained in:
commit
2073f5055b
14 changed files with 887 additions and 42 deletions
51
attributs.py
51
attributs.py
|
@ -3,9 +3,11 @@
|
|||
#
|
||||
# ATTRIBUTS.PY-- Description des attributs ldap
|
||||
#
|
||||
# Copyright (C) 2010 Cr@ns <roots@crans.org>
|
||||
# Author: Antoine Durand-Gasselin <adg@crans.org>
|
||||
# All rights reserved.
|
||||
# Copyright (C) 2010-2013 Cr@ns <roots@crans.org>
|
||||
# Authors: Antoine Durand-Gasselin <adg@crans.org>
|
||||
# Nicolas Dandrimont <olasd@crans.org>
|
||||
# Valentin Samir <samir@crans.org>
|
||||
# Vincent Le Gallic <legallic@crans.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are met:
|
||||
|
@ -54,13 +56,13 @@ def attrify(val, attr, ldif, conn, ctxt_check = True):
|
|||
return CRANS_ATTRIBUTES.get(attr, Attr)(val, ldif, conn, ctxt_check)
|
||||
|
||||
class Attr(object):
|
||||
"""La liste des droits qui suffisent à avoir le droit de modifier la valeur"""
|
||||
legend = "Human-readable description of attribute"
|
||||
singlevalue = None
|
||||
optional = None
|
||||
conn = None
|
||||
|
||||
can_modify = ['Nounou']
|
||||
"""La liste des droits qui suffisent à avoir le droit de modifier la valeur"""
|
||||
|
||||
can_view = ['Nounou', 'apprenti', 'self', 'parent', 'owner']
|
||||
"""Qui peut voir l'attribut. Par défaut, les nounous et les apprentis
|
||||
|
@ -154,8 +156,7 @@ class objectClass(Attr):
|
|||
'adherent', 'club', 'machine', 'machineCrans',
|
||||
'borneWifi', 'machineWifi', 'machineFixe',
|
||||
'cransAccount', 'service', 'facture', 'freeMid' ]:
|
||||
print(val)
|
||||
raise ValueError("Pourquoi insérer un objectClass=%s ?" % val)
|
||||
raise ValueError("Pourquoi insérer un objectClass=%r ?" % val)
|
||||
else:
|
||||
self.value = unicode(val)
|
||||
|
||||
|
@ -163,7 +164,7 @@ class objectClass(Attr):
|
|||
class intAttr(Attr):
|
||||
def parse_value(self, val, ldif):
|
||||
if int(val) <= 0:
|
||||
raise ValueError("Valeur entière invalide : %s" % val)
|
||||
raise ValueError("Valeur entière invalide : %r" % val)
|
||||
self.value = int(val)
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -220,7 +221,7 @@ class tel(Attr):
|
|||
def parse_value(self, val, ldif):
|
||||
self.value = format_tel(val)
|
||||
if len(self.value) == 0:
|
||||
raise ValueError("Numéro de téléphone invalide ('%s')" % val)
|
||||
raise ValueError("Numéro de téléphone invalide (%r)" % val)
|
||||
|
||||
|
||||
class yearAttr(intAttr):
|
||||
|
@ -228,8 +229,8 @@ class yearAttr(intAttr):
|
|||
optional= True
|
||||
|
||||
def parse_value(self, val, ldif):
|
||||
if int(val) < 1998 or int(val) > config.ann_scol:
|
||||
raise ValueError("Année invalide (%s)" % val)
|
||||
if int(val) < 1998:
|
||||
raise ValueError("Année invalide (%r)" % val)
|
||||
self.value = int(val)
|
||||
|
||||
|
||||
|
@ -255,7 +256,7 @@ class mailAlias(Attr):
|
|||
def parse_value(self, val, ldif):
|
||||
val = val.lower()
|
||||
if not re.match('[a-z][-_.0-9a-z]+', val):
|
||||
raise ValueError("Alias mail invalide (%s)" % val)
|
||||
raise ValueError("Alias mail invalide (%r)" % val)
|
||||
self.value = val
|
||||
|
||||
|
||||
|
@ -297,7 +298,7 @@ class chbre(Attr):
|
|||
self.value = val
|
||||
return
|
||||
else:
|
||||
raise ValueError("Club devrait etre en XclN, pas en %s" % val)
|
||||
raise ValueError("Club devrait etre en XclN, pas en %r" % val)
|
||||
|
||||
if val in (u"EXT", u"????"):
|
||||
self.value = val
|
||||
|
@ -320,8 +321,8 @@ class droits(Attr):
|
|||
|
||||
def parse_value(self, val, ldif):
|
||||
if val.lower() not in ['apprenti', 'nounou', 'cableur', 'tresorier', 'bureau',
|
||||
'webmaster', 'webradio', 'imprimeur', 'multimachines', 'victime', 'moderateur']:
|
||||
raise ValueError("Ces droits n'existent pas ('%s')" % val)
|
||||
'webmaster', 'webradio', 'imprimeur', 'multimachines', 'victime', 'moderateur', 'nounours']:
|
||||
raise ValueError("Ces droits n'existent pas (%r)" % val)
|
||||
if val.lower() == 'webmaster':
|
||||
self.value = u'WebMaster'
|
||||
else:
|
||||
|
@ -336,7 +337,7 @@ class solde(Attr):
|
|||
def parse_value(self, solde, ldif):
|
||||
# on évite les dépassements, sauf si on nous dit de ne pas vérifier
|
||||
if self.ctxt_check and not (float(solde) >= config.impression.decouvert and float(solde) <= 1024.):
|
||||
raise ValueError("Solde invalide: %s" % solde)
|
||||
raise ValueError("Solde invalide: %r" % solde)
|
||||
self.value = solde
|
||||
|
||||
class dnsAttr(Attr):
|
||||
|
@ -346,7 +347,7 @@ class dnsAttr(Attr):
|
|||
name, net = dns.split('.', 1)
|
||||
if self.ctxt_check and (net not in ['crans.org', 'wifi.crans.org'] or
|
||||
not re.match('[a-z][-_a-z0-9]+', name)):
|
||||
raise ValueError("Nom d'hote invalide '%s'" % dns)
|
||||
raise ValueError("Nom d'hote invalide %r" % dns)
|
||||
self.value = dns
|
||||
|
||||
|
||||
|
@ -436,18 +437,18 @@ class portAttr(Attr):
|
|||
a,b = port.split(":", 1)
|
||||
if a:
|
||||
if int(a) <0 or int(a)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
else:
|
||||
a = 0
|
||||
if b:
|
||||
if int(a) <0 or int(a)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
else:
|
||||
b = 65535
|
||||
self.value = [int(a), int(b)]
|
||||
else:
|
||||
if int(port) <0 or int(port)> 65535:
|
||||
raise ValueError("Port invalide: %s" % port)
|
||||
raise ValueError("Port invalide: %r" % port)
|
||||
self.value = [int(port)]
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -504,7 +505,7 @@ class responsable(Attr):
|
|||
self.value = property(self.get_respo)
|
||||
|
||||
def __unicode__(self):
|
||||
return self.value.attrs['aid'][0].__unicode__()
|
||||
return self.__resp
|
||||
|
||||
|
||||
class blacklist(Attr):
|
||||
|
@ -516,11 +517,11 @@ class blacklist(Attr):
|
|||
def parse_value(self, bl, ldif):
|
||||
bl_debut, bl_fin, bl_type, bl_comm = bl.split('$')
|
||||
now = time.time()
|
||||
self.value = { 'debut' : int (bl_debut),
|
||||
self.value = { 'debut' : bl_debut if bl_debut == '-' else int (bl_debut),
|
||||
'fin' : bl_fin if bl_fin == '-' else int(bl_fin),
|
||||
'type' : bl_type,
|
||||
'comm' : bl_comm,
|
||||
'actif' : int(bl_debut) < now and (bl_fin == '-' or int(bl_fin) > now) }
|
||||
'actif' : (bl_debut == '-' or int(bl_debut) < now) and (bl_fin == '-' or int(bl_fin) > now) }
|
||||
|
||||
def is_actif(self):
|
||||
return self.value['actif']
|
||||
|
@ -561,7 +562,7 @@ class charteMA(Attr):
|
|||
|
||||
def parse_value(self, signed, ldif):
|
||||
if signed.upper() not in ["TRUE", "FALSE"]:
|
||||
raise ValueError("La charte MA est soit TRUE ou FALSE, pas %s" % signed)
|
||||
raise ValueError("La charte MA est soit TRUE ou FALSE, pas %r" % signed)
|
||||
self.value = signed.upper()
|
||||
|
||||
class homeDirectory(Attr):
|
||||
|
@ -574,7 +575,7 @@ class homeDirectory(Attr):
|
|||
if uid.startswith('club-'):
|
||||
uid = uid.split('-',1)[1]
|
||||
if home != u'/home/%s' % uid and home != u'/home/club/%s' % uid:
|
||||
raise ValueError("Le répertoire personnel n'est pas bon: %s (devrait être %s ou %s)" %
|
||||
raise ValueError("Le répertoire personnel n'est pas bon: %r (devrait être %r ou %r)" %
|
||||
(home, '/home/%s' % ldif['uid'][0], '/home/club/%s' % ldif['uid'][0]))
|
||||
self.value = home
|
||||
|
||||
|
@ -611,7 +612,7 @@ class loginShell(Attr):
|
|||
'/bin//zsh'
|
||||
'']
|
||||
if self.ctxt_check and (shell not in shells):
|
||||
raise ValueError("Shell %s invalide" % shell)
|
||||
raise ValueError("Shell %r invalide" % shell)
|
||||
self.value = shell
|
||||
|
||||
class uidNumber(intAttr):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue