cubicweb/sobjects/ldapparser.py
changeset 12626 32ee89340e59
parent 12567 26744ad37953
parent 12618 3f125fdbcd70
--- a/cubicweb/sobjects/ldapparser.py	Wed May 22 11:34:08 2019 +0200
+++ b/cubicweb/sobjects/ldapparser.py	Fri May 24 16:29:14 2019 +0200
@@ -154,9 +154,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