Logo Search packages:      
Sourcecode: zope-ldapmultiplugins version File versions  Download package

def LDAPMultiPlugins::ActiveDirectoryMultiPlugin::ActiveDirectoryMultiPlugin::enumerateUsers (   self,
  id = None,
  login = None,
  exact_match = 0,
  sort_by = None,
  max_results = None,
  kw 
)

Fulfill the UserEnumerationPlugin requirements 

Definition at line 267 of file ActiveDirectoryMultiPlugin.py.

                       :
        """ Fulfill the UserEnumerationPlugin requirements """
        view_name = self.getId() + '_enumerateUsers'
        criteria = {'id':id, 'login':login, 'exact_match':exact_match,
                    'sort_by':sort_by, 'max_results':max_results}
        criteria.update(kw)

        cached_info = self.ZCacheable_get(view_name = view_name,
                                          keywords = criteria,
                                          default = None)

        if cached_info is not None:
            logger.debug('returning cached results from enumerateUsers')
            return cached_info
        
        result = []
        acl = self._getLDAPUserFolder()
        login_attr = acl.getProperty('_login_attr')
        uid_attr = acl.getProperty('_uid_attr')
        plugin_id = self.getId()
        edit_url = '%s/%s/manage_userrecords' % (plugin_id, acl.getId())

        if login_attr in kw:
            login = kw[login_attr]
            del kw[login_attr]

        if uid_attr in kw:
            id = kw[uid_attr]
            del kw[uid_attr]

        if acl is None:
            return ()

        if exact_match:
            if id:
                ldap_user = acl.getUserById(id)
            elif login:
                ldap_user = acl.getUser(login)
            else:
                msg = 'Exact Match specified but no ID or Login given'
                raise ValueError, msg

            if ldap_user is not None:
                qs = 'user_dn=%s' % quote_plus(ldap_user.getUserDN())
                result.append( { 'id' : ldap_user.getId()
                               , 'login' : ldap_user.getProperty(login_attr)
                               , 'pluginid' : plugin_id
                               , 'title': ldap_user.getProperty(login_attr)
                               , 'editurl' : '%s?%s' % (edit_url, qs)
                               } ) 
        elif id or login or kw:
            l_results = []
            seen = []
            attrs = (uid_attr, login_attr)

            if id:
                l_results.extend(acl.findUser(uid_attr, id, attrs=attrs))

            if login:
                l_results.extend(acl.findUser(login_attr, login, attrs=attrs))

            for key, val in kw.items():
                l_results.extend(acl.findUser(key, val, attrs=attrs))

            for l_res in l_results:
                if l_res['dn'] not in seen and l_res.has_key(login_attr):
                    l_res['id'] = l_res[uid_attr]
                    l_res['login'] = l_res[login_attr]
                    l_res['pluginid'] = plugin_id
                    quoted_dn = quote_plus(l_res['dn'])
                    l_res['editurl'] = '%s?user_dn=%s' % (edit_url, quoted_dn)
                    result.append(l_res)
                    seen.append(l_res['dn'])

            if sort_by is not None:
                result.sort(lambda a, b: cmp( a.get(sort_by, '').lower()
                                            , b.get(sort_by, '').lower()
                                            ) )

            if isinstance(max_results, int) and len(result) > max_results:
                result = result[:max_results-1]

        else:
            result = []
            for uid, name in acl.getUserIdsAndNames():
                tmp = {}
                tmp['id'] = uid
                tmp['login'] = name
                tmp['pluginid'] = plugin_id
                tmp['editurl'] = None
                result.append(tmp)

            if sort_by is not None:
                result.sort(lambda a, b: cmp( a.get(sort_by, '').lower()
                                            , b.get(sort_by, '').lower()
                                            ) )

            if isinstance(max_results, int) and len(result) > max_results:
                result = result[:max_results-1]

        result =  tuple(result)

        self.ZCacheable_set(result, view_name=view_name, keywords=criteria)

        return result

    security.declarePrivate('enumerateGroups')
    def enumerateGroups( self


Generated by  Doxygen 1.6.0   Back to index