mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 01:14:21 +01:00
implement search
This commit is contained in:
parent
c9b971e8b0
commit
53660ee1d2
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -21,9 +21,11 @@
|
||||
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
|
||||
<thead>
|
||||
<tr>
|
||||
%for attr in attrs_list:
|
||||
<th>
|
||||
User
|
||||
${attrs_list[attr]}
|
||||
</th>
|
||||
% endfor
|
||||
<th class="sorter-false">
|
||||
Modify
|
||||
</th>
|
||||
@ -35,9 +37,13 @@
|
||||
<tbody>
|
||||
%for user in searchresult:
|
||||
<tr>
|
||||
%for attr in attrs_list:
|
||||
<td>
|
||||
${user}
|
||||
% if attr in searchresult[user]:
|
||||
${searchresult[user][attr]}
|
||||
% endif
|
||||
</td>
|
||||
% endfor
|
||||
<td>
|
||||
<a href="/modify?user=${user}">
|
||||
<button type="submit" class="btn btn-xs blue">
|
||||
@ -56,9 +62,11 @@
|
||||
% endfor
|
||||
</tbody>
|
||||
<tr>
|
||||
%for attr in attrs_list:
|
||||
<th>
|
||||
User
|
||||
${attrs_list[attr]}
|
||||
</th>
|
||||
% endfor
|
||||
<th class="sorter-false">
|
||||
Modify
|
||||
</th>
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user