From 322aba33e8762a42d2e4e7f7b790c8538cdbf57d Mon Sep 17 00:00:00 2001 From: kakwa Date: Mon, 15 Jun 2015 23:03:47 +0200 Subject: [PATCH] fix search display * fix attritues handling, not using backend attribute name but key given in attributes.yml --- ldapcherry/__init__.py | 6 ++++-- ldapcherry/attributes.py | 6 +++--- tests/test_Attributes.py | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ldapcherry/__init__.py b/ldapcherry/__init__.py index 5968a3a..c119f92 100644 --- a/ldapcherry/__init__.py +++ b/ldapcherry/__init__.py @@ -332,8 +332,10 @@ class LdapCherry(object): if not u in ret: ret[u] = {} for attr in tmp[u]: - if not attr in ret[u]: - ret[u][attr] = tmp[u][attr] + if attr in self.attributes.backend_attributes[b]: + attrid = self.attributes.backend_attributes[b][attr] + if not attr in ret[u]: + ret[u][attrid] = tmp[u][attr] return ret def _check_admin(self): diff --git a/ldapcherry/attributes.py b/ldapcherry/attributes.py index 860cae9..1c3abfb 100644 --- a/ldapcherry/attributes.py +++ b/ldapcherry/attributes.py @@ -48,8 +48,8 @@ class Attributes: for b in attr['backends']: self.backends.add(b) if b not in self.backend_attributes: - self.backend_attributes[b] = [] - self.backend_attributes[b].append(attr['backends'][b]) + self.backend_attributes[b] = {} + self.backend_attributes[b][attr['backends'][b]] = attrid if 'search_displayed' in attr and attr['search_displayed']: self.displayed_attributes[attrid] = attr @@ -78,7 +78,7 @@ class Attributes: def get_backend_attributes(self, backend): if backend not in self.backends: raise WrongBackend(backend) - return self.backend_attributes[backend] + return self.backend_attributes[backend].keys() def get_backend_key(self, backend): if backend not in self.backends: diff --git a/tests/test_Attributes.py b/tests/test_Attributes.py index acabfd0..c5a9f9b 100644 --- a/tests/test_Attributes.py +++ b/tests/test_Attributes.py @@ -39,7 +39,7 @@ class TestError(object): 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'] + expected = ['shell', 'cn', 'userPassword', 'uidNumber', 'gidNumber', 'sn', 'home', 'givenName', 'email', 'uid'] assert ret == expected def testGetKey(self):