diff --git a/attributs.py b/attributs.py index 3e5fcb8..76726cc 100644 --- a/attributs.py +++ b/attributs.py @@ -106,9 +106,11 @@ class Attr(object): attr = self.__class__.__name__ if attr in [ "mid", "uid", "cid", "fid", "aid"]: #... etc assert not self.conn.search('%s=%s' % (attr, str(self))) - if attr in [ "mailAlias", "canonicalAlias"]: - assert not self.conn.search('|(mailAlias=%s)(canonicalAlias=%s)' % ((str(self),)*2)) - assert not mailexist(str(self)) + if attr in [ "mailAlias", "canonicalAlias", 'mail', 'uid']: + res = self.conn.search('(|(mail=%s)(mailAlias=%s)(canonicalAlias=%s))' % ((str(self),)*3)) + if res: + raise ValueError("Mail déjà existant", [r.dn for r in res]) + #assert not mailexist(str(self)) def _check_users_restrictions(self, values): """Vérifie les restrictions supplémentaires imposées selon les diff --git a/crans_utils.py b/crans_utils.py index c518ded..7dee801 100644 --- a/crans_utils.py +++ b/crans_utils.py @@ -50,22 +50,20 @@ def strip_accents(a): def strip_spaces(a): """ Suppression des espaces et des apostrophes""" - res = a.copy() - res.replace(u' ', u'_').replace(u"'", u'') - return res + return a.replace(u' ', u'_').replace(u"'", u'') def mailexist(mail): """Vérifie si une adresse mail existe ou non grace à la commande vrfy du serveur mail """ mail = mail.split('@', 1)[0] - try: - s = smtplib.SMTP(config.smtpserv) - s.putcmd("vrfy", mail) - r = s.getreply()[0] in [250, 252] - s.close() - except: - raise ValueError(u'Serveur de mail injoignable') +# try: + s = smtplib.SMTP('smtp.adm.crans.org') + s.putcmd("vrfy", mail) + r = s.getreply()[0] in [250, 252] + s.close() +# except: +# raise ValueError(u'Serveur de mail injoignable') return r diff --git a/lc_ldap.py b/lc_ldap.py index 1f33e7a..8696f05 100644 --- a/lc_ldap.py +++ b/lc_ldap.py @@ -287,8 +287,8 @@ class CransLdapObject(object): self.attrs = ldif_to_uldif(self.attrs) if mode in ['w', 'rw']: + self._modifs = copy.deepcopy(self.attrs) self.attrs = ldif_to_cldif(self.attrs, conn, check_ctxt = False) - ### Vérification que `λv. str(Attr(v))` est bien une projection oldif = res[0][1] nldif = cldif_to_ldif(self.attrs) @@ -582,12 +582,12 @@ class adherent(proprio): if u'posixAccount' in self.attrs['objectClass']: return self.attrs['uid'][0] elif login: - fn = crans_utils.strip_accents(self.attrs['prenom'][0].capitalize()) - ln = crans_utils.strip_accents(self.attrs['nom'][0].capitalize()) + fn = crans_utils.strip_accents(unicode(self.attrs['prenom'][0]).capitalize()) + ln = crans_utils.strip_accents(unicode(self.attrs['nom'][0]).capitalize()) login = crans_utils.strip_accents(login).lower() if jaro(ln.lower(), login) < 0.75 and jaro(fn.lower() + ' ' + ln.lower(), login) < 0.75: - raise ValueError("Le login est trop différent du nom (%s -> %s)" % - (login, self.attrs['nom'][0])) + raise ValueError("Le login est trop différent du nom", + login, self.attrs['nom'][0]) if not re.match('^[a-z][-a-z]{1,15}$', login): raise ValueError("Le login a entre 2 et 16 lettres, il peut contenir (pas au début) des - ") if crans_utils.mailexist(login): @@ -633,7 +633,7 @@ class adherent(proprio): self._modifs['uidNumber'] = [unicode(uidNumber)] self._modifs['gidNumber'] = [unicode(config.gid)] - self._modifs['gecos'] = self._modifs['cn'][0] + u',,,' + self._modifs['gecos'] = [self._modifs['cn'][0] + u',,,'] self.save() diff --git a/lc_ldap_tests.py b/lc_ldap_tests.py index f4e6c78..399018c 100755 --- a/lc_ldap_tests.py +++ b/lc_ldap_tests.py @@ -46,7 +46,7 @@ class LDAPTest(unittest.TestCase): class AdherentTest(LDAPTest): """Classe de test de la création d'un adhérent""" - tests = ["creationAdherent"] + tests = ["creationAdherent", "creationCompte"] def creationAdherent(self): """Crée un adhérent""" @@ -57,6 +57,18 @@ class AdherentTest(LDAPTest): 'chbre': [u"G001"], 'mail': [u"dave.null@toto.example"], }) + self.ldap.delete_s(self.adherent.dn) + + def creationCompte(self): + self.adherent = self.ldap.newAdherent({ + 'nom' : [u'McLellan'], + 'prenom' : [u'Stue'], + 'tel': [u'01 47 51 00 00'], + 'chbre': [u"G001"], + 'mail': [u'nobody@nowhere.example'], + }) + self.adherent.compte(u'mclellan') + self.ldap.delete_s(self.adherent.dn) def auto_suite(testcase):