# HG changeset patch # User Sylvain Thénault # Date 1329215639 -3600 # Node ID 171a9d6bff8f5b22267b973ec17e00b204b47061 # Parent c59c05c5132167ea22621e6759c3840da403cb9b [ldapfeed] fix synchronisation crash: ldap attributes are given while we want cw attributes and name errors in method checking if a dn still exists in ldap diff -r c59c05c51321 -r 171a9d6bff8f server/ldaputils.py --- a/server/ldaputils.py Mon Feb 20 11:46:28 2012 +0100 +++ b/server/ldaputils.py Tue Feb 14 11:33:59 2012 +0100 @@ -227,7 +227,7 @@ if cnx is None: return True # ldap unreachable, suppose it exists try: - cnx.search_s(base, scope, searchstr, attrs) + cnx.search_s(dn, self.user_base_scope) except ldap.PARTIAL_RESULTS: pass except ldap.NO_SUCH_OBJECT: diff -r c59c05c51321 -r 171a9d6bff8f sobjects/ldapparser.py --- a/sobjects/ldapparser.py Mon Feb 20 11:46:28 2012 +0100 +++ b/sobjects/ldapparser.py Tue Feb 14 11:33:59 2012 +0100 @@ -28,6 +28,9 @@ class DataFeedlDAPParser(datafeed.DataFeedParser): __regid__ = 'ldapfeed' + # attributes that may appears in source user_attrs dict which are not + # attributes of the cw user + non_attribute_keys = set(('email',)) def process(self, url, raise_on_error=False, partialcommit=True): """IDataFeedParser main entry point""" @@ -42,18 +45,23 @@ entity = self.extid2entity(userdict['dn'], 'CWUser', **userdict) if not self.created_during_pull(entity): self.notify_updated(entity) - attrs = dict( (k, v) for k, v in userdict.iteritems() - if not k in ('dn', 'email') ) + attrs = self.ldap2cwattrs(userdict) self.update_if_necessary(entity, attrs) self._process_email(entity, userdict) + def ldap2cwattrs(self, sdict, tdict=None): + if tdict is None: + tdict = {} + for sattr, tattr in self.source.user_attrs.iteritems(): + if tattr not in self.non_attribute_keys: + tdict[tattr] = sdict[sattr] + return tdict + def before_entity_copy(self, entity, sourceparams): if entity.__regid__ == 'EmailAddress': entity.cw_edited['address'] = sourceparams['address'] else: - for ldapattr, cwattr in self.source.user_attrs.iteritems(): - if cwattr != 'email': - entity.cw_edited[cwattr] = sourceparams[ldapattr] + self.ldap2cwattrs(sourceparams, entity.cw_edited) return entity def after_entity_copy(self, entity, sourceparams):