Révision de la fonction _get_etab pour le multi-établissement
This commit is contained in:
@@ -195,7 +195,7 @@ index 69f3411..07fa33a 100644
|
||||
Mise à niveau d'un compte enseignant
|
||||
"""
|
||||
diff --git usr/lib/python3/dist-packages/scribe/eoleldap.py usr/lib/python3/dist-packages/scribe/eoleldap.py
|
||||
index 45ec338..dac52b3 100644
|
||||
index 45ec338..a3054ee 100644
|
||||
--- usr/lib/python3/dist-packages/scribe/eoleldap.py
|
||||
+++ usr/lib/python3/dist-packages/scribe/eoleldap.py
|
||||
@@ -8,21 +8,21 @@
|
||||
@@ -257,41 +257,60 @@ index 45ec338..dac52b3 100644
|
||||
users = []
|
||||
res = self.ldap_admin._search("(&%s%s)" % (USER_FILTER, filtre), attrs)
|
||||
for user in res:
|
||||
@@ -572,21 +570,31 @@ elif LDAP_MODE == 'openldap':
|
||||
@@ -566,27 +564,47 @@ elif LDAP_MODE == 'openldap':
|
||||
ret.append((key, sub))
|
||||
return ret
|
||||
|
||||
class LdapEntry(_LdapEntry):
|
||||
def _get_etab(self, _type, name, ldap_filter, attr, multi_etabs=False):
|
||||
"""
|
||||
récupère le numéro d'etab du cache ou requète LDAP
|
||||
"""
|
||||
if not SUPPORT_ETAB:
|
||||
return None
|
||||
+
|
||||
if not multi_etabs and name in self.cache_etab[_type]:
|
||||
return self.cache_etab[_type][name]
|
||||
+
|
||||
need_close = False
|
||||
if self.ldap_admin.connexion == None:
|
||||
- if self.ldap_admin.connexion == None:
|
||||
+ if self.ldap_admin.connexion is None:
|
||||
self.ldap_admin.connect()
|
||||
need_close = True
|
||||
- dn = self.ldap_admin._search(ldap_filter, [attr])[0][0]
|
||||
+ try:
|
||||
+ if _type == 'group':
|
||||
+ attr = 'cn'
|
||||
+ result = self.ldap_admin._search(ldap_filter, [attr])[0]
|
||||
+ if _type == 'login':
|
||||
+ etab = [cn[1]['cn'][0] for cn in self.ldap_admin._search(f'(&(objectClass=eolegroupe)(type=Etablissement)(memberUid={name}))', ['cn'])]
|
||||
+ if not etab:
|
||||
+ return None
|
||||
+ else:
|
||||
+ etab = [result[0].split(',ou=')[-3]]
|
||||
+ if not multi_etabs:
|
||||
+ etab = etab[0]
|
||||
+ except:
|
||||
+ etab = None
|
||||
if need_close:
|
||||
self.ldap_admin.close()
|
||||
- if need_close:
|
||||
- self.ldap_admin.close()
|
||||
- etab = dn.split(',ou=')[-3]
|
||||
- if multi_etabs:
|
||||
- etab = [etab]
|
||||
- else:
|
||||
+
|
||||
+ try:
|
||||
+ if _type == 'login':
|
||||
+ etab = [cn[1]['cn'][0] for cn in self.ldap_admin._search(f'(&(objectClass=eolegroupe)(type=Etablissement)(memberUid={name}))', ['cn'])]
|
||||
+ else:
|
||||
+ if _type == 'group':
|
||||
+ attr = 'cn'
|
||||
+ result = self.ldap_admin._search(ldap_filter, [attr])[0]
|
||||
+ etab = [result[0].split(',ou=')[-3]]
|
||||
+
|
||||
+ if not multi_etabs:
|
||||
+ if len(etab) == 0:
|
||||
+ etab = None
|
||||
+ else:
|
||||
+ etab = etab[0]
|
||||
+
|
||||
+ except BaseException:
|
||||
+ etab = None
|
||||
+ finally:
|
||||
+ if need_close:
|
||||
+ self.ldap_admin.close()
|
||||
+
|
||||
+ if not multi_etabs:
|
||||
self.cache_etab[_type][name] = etab
|
||||
+
|
||||
return etab
|
||||
+
|
||||
else:
|
||||
raise Exception('Unknown mode')
|
||||
diff --git usr/lib/python3/dist-packages/scribe/eoleuser.py usr/lib/python3/dist-packages/scribe/eoleuser.py
|
||||
|
Reference in New Issue
Block a user