[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
--- 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:
--- 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):