[lc_ldap] Corrections de bugs, et cohérence de code.
This commit is contained in:
parent
6d4d56db72
commit
7ed1874d62
4 changed files with 26 additions and 14 deletions
|
@ -48,7 +48,7 @@ import random
|
|||
import string
|
||||
from unicodedata import normalize
|
||||
from crans_utils import format_tel, format_mac, mailexist, validate_name, ip4_of_rid, ip6_of_mac, fetch_cert_info
|
||||
from crans_utils import toGeneralizedTimeFormat, fromGeneralizedTimeFormat, extractTz
|
||||
from crans_utils import to_generalized_time_format, from_generalized_time_format
|
||||
import itertools
|
||||
|
||||
sys.path.append("/usr/scripts")
|
||||
|
@ -457,6 +457,7 @@ class uid(Attr):
|
|||
legend = u"L'identifiant canonique de l'adhérent"
|
||||
category = 'perso'
|
||||
unique = True
|
||||
can_modify = [nounou]
|
||||
ldap_name = "uid"
|
||||
|
||||
@crans_attribute
|
||||
|
@ -601,13 +602,13 @@ class generalizedTimeFormat(Attr):
|
|||
if isinstance(gtf, str) or isinstance(gtf, unicode):
|
||||
if not ('Z' in gtf or '+' in gtf or '-' in gtf):
|
||||
self._stamp = gtf
|
||||
self.value = toGeneralizedTimeFormat(float(gtf))
|
||||
self.value = to_generalized_time_format(float(gtf))
|
||||
else:
|
||||
self._stamp = fromGeneralizedTimeFormat(gtf)
|
||||
self._stamp = from_generalized_time_format(gtf)
|
||||
self.value = gtf
|
||||
elif isinstance(gtf, float):
|
||||
self._stamp = gtf
|
||||
self.value = toGeneralizedTimeFormat(gtf)
|
||||
self.value = to_generalized_time_format(gtf)
|
||||
|
||||
@crans_attribute
|
||||
class debutAdhesion(generalizedTimeFormat):
|
||||
|
|
|
@ -243,7 +243,7 @@ def hash_password(password, salt=None, longueur=4):
|
|||
raise ValueError("salt devrait faire au moins 4 octets")
|
||||
if salt is None:
|
||||
salt = os.urandom(longueur)
|
||||
elif len(salt)<4:
|
||||
elif len(salt) < 4:
|
||||
raise ValueError("salt devrait faire au moins 4 octets")
|
||||
|
||||
return '{SSHA}' + base64.b64encode(hashlib.sha1(password + salt).digest() + salt)
|
||||
|
@ -306,14 +306,14 @@ def ip4_addresses():
|
|||
ip_list.append(link['addr'])
|
||||
return ip_list
|
||||
|
||||
def extractTz(thetz):
|
||||
def extract_tz(thetz):
|
||||
abstz = 100*abs(thetz)
|
||||
if thetz == 0:
|
||||
return u"Z"
|
||||
else:
|
||||
return u"%s%04d" % ("+"*(thetz < 0) + "-"*(thetz > 0), abstz)
|
||||
|
||||
def toGeneralizedTimeFormat(stamp):
|
||||
def to_generalized_time_format(stamp):
|
||||
"""Converts a timestamp (local) in a generalized time format
|
||||
for LDAP.
|
||||
|
||||
|
@ -322,9 +322,9 @@ def toGeneralizedTimeFormat(stamp):
|
|||
|
||||
"""
|
||||
|
||||
return u"%s%s" % (time.strftime("%Y%m%d%H%M%S", time.localtime(stamp)), extractTz(time.altzone/3600))
|
||||
return u"%s%s" % (time.strftime("%Y%m%d%H%M%S", time.localtime(stamp)), extract_tz(time.altzone/3600))
|
||||
|
||||
def fromGeneralizedTimeFormat(gtf):
|
||||
def from_generalized_time_format(gtf):
|
||||
"""Converts a GTF stamp to unix timestamp
|
||||
|
||||
* gtf : a generalized time format resource without dotsecond
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#
|
||||
## Copyright (C) 2013 Cr@ns <roots@crans.org>
|
||||
# Authors:
|
||||
# * Antoine Durand-Gasselin <adg@crans.org>
|
||||
# * Antoine Durand-Gasselin <adg@crans.org>
|
||||
# * Pierre-Elliott Bécue <becue@crans.org>
|
||||
#
|
||||
# All rights reserved.
|
||||
|
@ -180,7 +180,7 @@ class LdapLockHolder:
|
|||
pass
|
||||
if not self.locks[Id][item]:
|
||||
self.locks[Id].pop(item)
|
||||
|
||||
|
||||
def getlock(self, item, value):
|
||||
"""
|
||||
Trouve le lock item=value, et renvoie le contenu de lockinfo
|
||||
|
|
17
objets.py
17
objets.py
|
@ -108,6 +108,8 @@ class CransLdapObject(object):
|
|||
|
||||
attribs = []
|
||||
|
||||
ldap_name = "CransLdapObject"
|
||||
|
||||
def update_attribs(self):
|
||||
"""
|
||||
Fonction permettant de mettre à jours attribs, dès que les valeurs
|
||||
|
@ -225,6 +227,7 @@ class CransLdapObject(object):
|
|||
|
||||
def __ne__(self, obj):
|
||||
return not self == obj
|
||||
|
||||
def __eq__(self, obj):
|
||||
if isinstance(obj, self.__class__):
|
||||
if self.mode in ['w', 'rw']:
|
||||
|
@ -637,6 +640,14 @@ class CransLdapObject(object):
|
|||
out.append(u"%s : [%s] %s" % (date, author, u" ; ".join(mod_list)))
|
||||
return out
|
||||
|
||||
# On utilise carte_ok et paiement_ok dans blacklist_actif, qui sont définis dans les
|
||||
# objets enfants. On définit des méthodes vides ici pour la cohérence.
|
||||
def carte_ok(self):
|
||||
pass
|
||||
|
||||
def paiement_ok(self, no_bl=False):
|
||||
pass
|
||||
|
||||
def blacklist_actif(self, excepts=[]):
|
||||
"""Renvoie la liste des blacklistes actives sur l'entité
|
||||
Améliorations possibles:
|
||||
|
@ -862,11 +873,11 @@ class proprio(CransLdapObject):
|
|||
|
||||
def fin_adhesion(self):
|
||||
"""Retourne la date de fin d'adhésion"""
|
||||
return max([float(facture.get('finAdhesion', [crans_utils.fromGeneralizedTimeFormat(attributs.finAdhesion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
return max([float(facture.get('finAdhesion', [crans_utils.from_generalized_time_format(attributs.finAdhesion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
|
||||
def fin_connexion(self):
|
||||
"""Retourne la date de fin de connexion"""
|
||||
return max([float(facture.get('finConnexion', [crans_utils.fromGeneralizedTimeFormat(attributs.finConnexion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
return max([float(facture.get('finConnexion', [crans_utils.from_generalized_time_format(attributs.finConnexion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
|
||||
def paiement_ok(self, no_bl=False):
|
||||
u"""
|
||||
|
@ -1108,7 +1119,7 @@ class machine(CransLdapObject):
|
|||
self['ipHostNumber'] = []
|
||||
self['ip6HostNumber'] = []
|
||||
else:
|
||||
if unicode(self['ipHostNumber'][0]) != unicode(ip4_of_rid(sbm['rid'][1])):
|
||||
if unicode(self['ipHostNumber'][0]) != unicode(crans_utils.ip4_of_rid(sbm['rid'][1])):
|
||||
raise ValueError("L'ipv4 et le rid ne concordent pas !")
|
||||
self['ip6HostNumber'] = [unicode(crans_utils.ip6_of_mac(self['macAddress'][0].value, self['rid'][0].value))]
|
||||
if sbm['ipHostNumber']:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue