add new curie objectclass, copy ic* attributes (#10960)

This commit is contained in:
Benjamin Dauvergne 2016-05-20 11:19:45 +02:00
parent 3e57eee8bf
commit b70ded2d9c
1 changed files with 34 additions and 15 deletions

View File

@ -106,7 +106,7 @@ class CurieLdifParser(ldif.LDIFParser):
self.users[uid].update({
'objectClass': ['person', 'supannPerson', 'organizationalPerson', 'eduPerson',
'inetOrgPerson'],
'inetOrgPerson', 'icPerson'],
'uid': uid,
'supannAliasLogin': supann_alias_login,
'userPassword': user_password,
@ -114,6 +114,13 @@ class CurieLdifParser(ldif.LDIFParser):
})
self.users[uid].setdefault('_source', set()).add('ad')
def extract_top_rdn(self, dn, name='ou'):
parsed = ldap.dn.str2dn(dn)
assert len(parsed) > 1, 'dn is empty'
assert len(parsed[0]) == 1, 'rdn has more than one part %r' % parsed[0]
assert parsed[0][0][0].lower() == name, 'top rdn is not %s: %r' % (name, parsed[0][0])
return parsed[0][0][1]
def handle_sun(self, dn, entry):
uid = self.assert_sv_attribute(entry, 'uid')
if 'icprenomnaissance' in entry:
@ -128,29 +135,41 @@ class CurieLdifParser(ldif.LDIFParser):
cn = self.assert_sv_attribute(entry, 'cn')
else:
cn = strip_accents('%s %s' % (prenom, nom)).strip()
telephone = entry.get('telephoneNumber', [])
mail = entry.get('mail', [])
supann_entite_affectation = []
supann_entite_affectation_principale = []
if entry.get('iclibelleentite', []) == ['Recherche']:
ic_equipe_recherche = self.assert_sv_attribute(entry, 'icequiperecherche')
ic_equipe_recherche_dn = ldap.dn.str2dn(ic_equipe_recherche)
assert ic_equipe_recherche_dn[0][0][0].lower() == 'ou', \
('ICEquipeRecherche ne contient pas le DN d\'une OU: %r %s' % (
ic_equipe_recherche[0][0][0].lower(), ic_equipe_recherche))
supann_entite_affectation_principale = ic_equipe_recherche_dn[0][0][1]
else:
supann_entite_affectation_principale = None
try:
ic_equipe_recherche = self.assert_sv_attribute(entry, 'icequiperecherche')
except AssertionError, e:
self.errors.append(Error(dn, str(e)))
else:
ou = self.extract_top_rdn(ic_equipe_recherche)
supann_entite_affectation.append(ou)
supann_entite_affectation_principale.append(ou)
try:
ic_unite_fonctionnelle = self.assert_sv_attribute(entry, 'icunitefonctionnelle')
except AssertionError, e:
self.errors.append(Error(dn, str(e)))
else:
ou = self.extract_top_rdn(ic_unite_fonctionnelle)
supann_entite_affectation.append(ou)
d = {
'iclibelleentite': entry.get('iclibelleentite', []),
'uid': uid,
'sn': nom,
'givenName': prenom,
'cn': cn,
'mail': mail,
'supannEntiteAffectation': supann_entite_affectation,
'supannEntiteAffectationPrincipale': supann_entite_affectation_principale,
}
if telephone:
d['telephoneNumber'] = telephone
if supann_entite_affectation_principale:
d['supannEntiteAffectationPrincipale'] = supann_entite_affectation_principale
# attributes to copy
for to_copy in ('telephoneNumber', 'icLibelleEntite', 'icUniteFonctionnelle',
'icEquipeRecherche'):
to_copy = to_copy.lower()
if to_copy in entry:
d[to_copy] = entry[to_copy]
self.users[uid].update(d)
self.users[uid].setdefault('_source', set()).add('sun')