server/sources/ldapuser.py
branchstable
changeset 6886 b571d2d32971
parent 6750 ef513c03a224
child 6887 72d7feeb071e
equal deleted inserted replaced
6885:ea4baa1d16d6 6886:b571d2d32971
   325             relname = iter(var.stinfo['relations']).next().r_type
   325             relname = iter(var.stinfo['relations']).next().r_type
   326             return self.user_rev_attrs.get(relname)
   326             return self.user_rev_attrs.get(relname)
   327         return None
   327         return None
   328 
   328 
   329     def prepare_columns(self, mainvars, rqlst):
   329     def prepare_columns(self, mainvars, rqlst):
   330         """return two list describin how to build the final results
   330         """return two list describing how to build the final results
   331         from the result of an ldap search (ie a list of dictionnary)
   331         from the result of an ldap search (ie a list of dictionnary)
   332         """
   332         """
   333         columns = []
   333         columns = []
   334         global_transforms = []
   334         global_transforms = []
   335         for i, term in enumerate(rqlst.selection):
   335         for i, term in enumerate(rqlst.selection):
   529 
   529 
   530     def _search(self, session, base, scope,
   530     def _search(self, session, base, scope,
   531                 searchstr='(objectClass=*)', attrs=()):
   531                 searchstr='(objectClass=*)', attrs=()):
   532         """make an ldap query"""
   532         """make an ldap query"""
   533         self.debug('ldap search %s %s %s %s %s', self.uri, base, scope, searchstr, list(attrs))
   533         self.debug('ldap search %s %s %s %s %s', self.uri, base, scope, searchstr, list(attrs))
       
   534         # XXX for now, we do not have connection pool support for LDAP, so
       
   535         # this is always self._conn
   534         cnx = session.pool.connection(self.uri).cnx
   536         cnx = session.pool.connection(self.uri).cnx
   535         try:
   537         try:
   536             res = cnx.search_s(base, scope, searchstr, attrs)
   538             res = cnx.search_s(base, scope, searchstr, attrs)
   537         except ldap.PARTIAL_RESULTS:
   539         except ldap.PARTIAL_RESULTS:
   538             res = cnx.result(all=0)[1]
   540             res = cnx.result(all=0)[1]
   595         res = self._search(session, lid, BASE)[0]
   597         res = self._search(session, lid, BASE)[0]
   596         for attr in entity.e_schema.indexable_attributes():
   598         for attr in entity.e_schema.indexable_attributes():
   597             entity.cw_edited[attr] = res[self.user_rev_attrs[attr]]
   599             entity.cw_edited[attr] = res[self.user_rev_attrs[attr]]
   598         return entity
   600         return entity
   599 
   601 
   600     def after_entity_insertion(self, session, dn, entity):
   602     def after_entity_insertion(self, session, lid, entity):
   601         """called by the repository after an entity stored here has been
   603         """called by the repository after an entity stored here has been
   602         inserted in the system table.
   604         inserted in the system table.
   603         """
   605         """
   604         self.debug('ldap after entity insertion')
   606         self.debug('ldap after entity insertion')
   605         super(LDAPUserSource, self).after_entity_insertion(session, dn, entity)
   607         super(LDAPUserSource, self).after_entity_insertion(session, lid, entity)
       
   608         dn = lid
   606         for group in self.user_default_groups:
   609         for group in self.user_default_groups:
   607             session.execute('SET X in_group G WHERE X eid %(x)s, G name %(group)s',
   610             session.execute('SET X in_group G WHERE X eid %(x)s, G name %(group)s',
   608                             {'x': entity.eid, 'group': group})
   611                             {'x': entity.eid, 'group': group})
   609         # search for existant email first
   612         # search for existant email first
   610         try:
   613         try: