server/sources/ldapuser.py
changeset 938 a69188963ccb
parent 257 4c7d3af7e94d
child 975 0928daea04e9
equal deleted inserted replaced
937:491dbd818f9b 938:a69188963ccb
   174     def synchronize(self):
   174     def synchronize(self):
   175         """synchronize content known by this repository with content in the
   175         """synchronize content known by this repository with content in the
   176         external repository
   176         external repository
   177         """
   177         """
   178         self.info('synchronizing ldap source %s', self.uri)
   178         self.info('synchronizing ldap source %s', self.uri)
       
   179         try:
       
   180             ldap_emailattr = self.user_rev_attrs['email']
       
   181         except KeyError:
       
   182             return # no email in ldap, we're done
   179         session = self.repo.internal_session()
   183         session = self.repo.internal_session()
   180         try:
   184         try:
   181             cursor = session.system_sql("SELECT eid, extid FROM entities WHERE "
   185             cursor = session.system_sql("SELECT eid, extid FROM entities WHERE "
   182                                         "source='%s'" % self.uri)
   186                                         "source='%s'" % self.uri)
   183             for eid, extid in cursor.fetchall():
   187             for eid, extid in cursor.fetchall():
   184                 # if no result found, _search automatically delete entity information
   188                 # if no result found, _search automatically delete entity information
   185                 res = self._search(session, extid, BASE)
   189                 res = self._search(session, extid, BASE)
   186                 if res: 
   190                 if res: 
   187                     ldapemailaddr = res[0].get(self.user_rev_attrs['email'])
   191                     ldapemailaddr = res[0].get(ldap_emailattr)
   188                     if ldapemailaddr:
   192                     if ldapemailaddr:
   189                         rset = session.execute('EmailAddress X,A WHERE '
   193                         rset = session.execute('EmailAddress X,A WHERE '
   190                                                'U use_email X, U eid %(u)s',
   194                                                'U use_email X, U eid %(u)s',
   191                                                {'u': eid})
   195                                                {'u': eid})
   192                         ldapemailaddr = unicode(ldapemailaddr)
   196                         ldapemailaddr = unicode(ldapemailaddr)