diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 6bce181..53ce65c 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -318,9 +318,18 @@ class LdapCherry(object): exit(1) def _search(self, searchstring): + if searchstring is None: + return {} ret = {} for b in self.backends: - ret[b] = self.backends[b].search(searchstring) + tmp = self.backends[b].search(searchstring) + for u in tmp: + if not u in ret: + ret[u] = {} + for attr in tmp[u]: + if not attr in ret[u]: + ret[u][attr] = tmp[u][attr] + return ret def _check_auth(self, must_admin): if self.auth_mode == 'none': @@ -418,7 +427,9 @@ class LdapCherry(object): def searchadmin(self, searchstring=None): """ search user page """ self._check_auth(must_admin=True) - return self.temp_searchadmin.render(searchresult=['test', 'toto', 'tata']) + res = self._search(searchstring) + attrs_list = self.attributes.get_search_attributes() + return self.temp_searchadmin.render(searchresult = res, attrs_list = attrs_list) @cherrypy.expose def adduser(self, **params): diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index 60533fb..ac78f36 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -23,7 +23,7 @@ class Attributes: self.backends = Set([]) self.self_attributes = Set([]) self.backend_attributes = {} - self.displayed_attributes = [] + self.displayed_attributes = {} self.key = None try: stream = open(attributes_file, 'r') @@ -51,7 +51,7 @@ class Attributes: self.backend_attributes[b] = [] self.backend_attributes[b].append(attr['backends'][b]) if 'search_displayed' in attr and attr['search_displayed']: - self.displayed_attributes.append(attrid) + self.displayed_attributes[attrid] = attr['display_name'] if self.key is None: raise MissingUserKey() diff --git a/resources/templates/searchadmin.tmpl b/resources/templates/searchadmin.tmpl index 8c845bc..0cf3db9 100644 --- a/resources/templates/searchadmin.tmpl +++ b/resources/templates/searchadmin.tmpl @@ -21,9 +21,11 @@ + %for attr in attrs_list: + % endfor @@ -35,9 +37,13 @@ %for user in searchresult: + %for attr in attrs_list: + % endfor + %for attr in attrs_list: + % endfor diff --git a/tests/test_Attributes.py b/tests/test_Attributes.py index 1de80b5..df9f720 100644 --- a/tests/test_Attributes.py +++ b/tests/test_Attributes.py @@ -30,12 +30,24 @@ class TestError(object): expected = Set(['ldap', 'ad']) assert ret == expected + def testGetSearchAttributes(self): + inv = Attributes('./tests/cfg/attributes.yml') + ret = inv.get_search_attributes() + expected = {'first-name': 'First Name', 'cn': 'Display Name', 'name': 'Name', 'uid': 'UID', 'email': 'Name'} + assert ret == expected + def testGetBackendAttributes(self): inv = Attributes('./tests/cfg/attributes.yml') ret = inv.get_backend_attributes('ldap') expected = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn'] assert ret == expected + def testGetKey(self): + inv = Attributes('./tests/cfg/attributes.yml') + ret = inv.get_key() + expected = 'uid' + assert ret == expected + def testWrongGetBackendAttributes(self): inv = Attributes('./tests/cfg/attributes.yml') try: @@ -44,7 +56,6 @@ class TestError(object): return else: raise AssertionError("expected an exception") - def testNoFile(self): try:
- User + ${attrs_list[attr]} Modify
- ${user} + % if attr in searchresult[user]: + ${searchresult[user][attr]} + % endif
- User + ${attrs_list[attr]} Modify