[ldap] handle modification date
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Wed, 24 Apr 2013 17:40:49 +0200
changeset 8919 4cba95ef4738
parent 8918 43fd866e8f8a
child 8920 386049566ceb
[ldap] handle modification date We are now able to import modification date from ldap.
server/ldaputils.py
sobjects/ldapparser.py
--- a/server/ldaputils.py	Wed Apr 24 17:39:10 2013 +0200
+++ b/server/ldaputils.py	Wed Apr 24 17:40:49 2013 +0200
@@ -32,6 +32,8 @@
 
 from __future__ import division # XXX why?
 
+from datetime import datetime
+
 import ldap
 from ldap.ldapobject import ReconnectLDAPObject
 from ldap.filter import filter_format
@@ -160,7 +162,7 @@
         self.user_base_scope = globals()[typedconfig['user-scope']]
         self.user_login_attr = typedconfig['user-login-attr']
         self.user_default_groups = typedconfig['user-default-group']
-        self.user_attrs = {'dn': 'eid'}
+        self.user_attrs = {'dn': 'eid', 'modifyTimestamp': 'modification_date'}
         self.user_attrs.update(typedconfig['user-attrs-map'])
         self.user_rev_attrs = dict((v, k) for k, v in self.user_attrs.iteritems())
         self.base_filters = [filter_format('(%s=%s)', ('objectClass', o))
@@ -340,6 +342,8 @@
                 if not value.startswith('{SSHA}'):
                     value = utils.crypt_password(value)
                 itemdict[key] = Binary(value)
+            elif self.user_attrs.get(key) == 'modification_date':
+                itemdict[key] = datetime.strptime(value[0], '%Y%m%d%H%M%SZ')
             else:
                 value = [unicode(val, 'utf-8', 'replace') for val in value]
                 if len(value) == 1:
--- a/sobjects/ldapparser.py	Wed Apr 24 17:39:10 2013 +0200
+++ b/sobjects/ldapparser.py	Wed Apr 24 17:40:49 2013 +0200
@@ -32,7 +32,7 @@
     __regid__ = 'ldapfeed'
     # attributes that may appears in source user_attrs dict which are not
     # attributes of the cw user
-    non_attribute_keys = set(('email', 'eid'))
+    non_attribute_keys = set(('email', 'eid', 'member', 'modification_date'))
 
     @cachedproperty
     def searchfilterstr(self):