cubicweb/sobjects/ldapparser.py
branch3.26
changeset 12618 3f125fdbcd70
parent 11758 3f81636a75db
child 12626 32ee89340e59
--- a/cubicweb/sobjects/ldapparser.py	Fri Mar 15 12:12:23 2019 +0100
+++ b/cubicweb/sobjects/ldapparser.py	Thu May 16 14:26:38 2019 +0200
@@ -156,9 +156,26 @@
 
     def extentities_generator(self):
         self.debug('processing ldapfeed source %s %s', self.source, self.searchgroupfilterstr)
+        # get existing users *not* managed by this source
+        non_managed_users = dict(self._cw.execute(
+            'Any L, SN WHERE'
+            ' U is CWUser, U login L,'
+            ' U cw_source S, S name SN,'
+            ' NOT S eid %(eid)s',
+            {'eid': self.source.eid}, build_descr=False))
         # generate users and email addresses
         for userdict in self.user_source_entities_by_extid.values():
             attrs = self.ldap2cwattrs(userdict, 'CWUser')
+            login = attrs['login'][0]
+            try:
+                source = non_managed_users[login]
+            except KeyError:
+                pass
+            else:
+                self.error(
+                    'not synchronizing user %s. User already exist in source %s',
+                    login, source)
+                continue
             pwd = attrs.get('upassword')
             if not pwd:
                 # generate a dumb password if not fetched from ldap (see