mirror of
https://github.com/kakwa/ldapcherry
synced 2024-11-22 09:24:21 +01:00
implement search
This commit is contained in:
parent
c9b971e8b0
commit
53660ee1d2
@ -318,9 +318,18 @@ class LdapCherry(object):
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def _search(self, searchstring):
|
def _search(self, searchstring):
|
||||||
|
if searchstring is None:
|
||||||
|
return {}
|
||||||
ret = {}
|
ret = {}
|
||||||
for b in self.backends:
|
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):
|
def _check_auth(self, must_admin):
|
||||||
if self.auth_mode == 'none':
|
if self.auth_mode == 'none':
|
||||||
@ -418,7 +427,9 @@ class LdapCherry(object):
|
|||||||
def searchadmin(self, searchstring=None):
|
def searchadmin(self, searchstring=None):
|
||||||
""" search user page """
|
""" search user page """
|
||||||
self._check_auth(must_admin=True)
|
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
|
@cherrypy.expose
|
||||||
def adduser(self, **params):
|
def adduser(self, **params):
|
||||||
|
@ -23,7 +23,7 @@ class Attributes:
|
|||||||
self.backends = Set([])
|
self.backends = Set([])
|
||||||
self.self_attributes = Set([])
|
self.self_attributes = Set([])
|
||||||
self.backend_attributes = {}
|
self.backend_attributes = {}
|
||||||
self.displayed_attributes = []
|
self.displayed_attributes = {}
|
||||||
self.key = None
|
self.key = None
|
||||||
try:
|
try:
|
||||||
stream = open(attributes_file, 'r')
|
stream = open(attributes_file, 'r')
|
||||||
@ -51,7 +51,7 @@ class Attributes:
|
|||||||
self.backend_attributes[b] = []
|
self.backend_attributes[b] = []
|
||||||
self.backend_attributes[b].append(attr['backends'][b])
|
self.backend_attributes[b].append(attr['backends'][b])
|
||||||
if 'search_displayed' in attr and attr['search_displayed']:
|
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:
|
if self.key is None:
|
||||||
raise MissingUserKey()
|
raise MissingUserKey()
|
||||||
|
@ -21,9 +21,11 @@
|
|||||||
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
|
<table id="RecordTable" class="table table-hover table-condensed tablesorter">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
%for attr in attrs_list:
|
||||||
<th>
|
<th>
|
||||||
User
|
${attrs_list[attr]}
|
||||||
</th>
|
</th>
|
||||||
|
% endfor
|
||||||
<th class="sorter-false">
|
<th class="sorter-false">
|
||||||
Modify
|
Modify
|
||||||
</th>
|
</th>
|
||||||
@ -35,9 +37,13 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
%for user in searchresult:
|
%for user in searchresult:
|
||||||
<tr>
|
<tr>
|
||||||
|
%for attr in attrs_list:
|
||||||
<td>
|
<td>
|
||||||
${user}
|
% if attr in searchresult[user]:
|
||||||
|
${searchresult[user][attr]}
|
||||||
|
% endif
|
||||||
</td>
|
</td>
|
||||||
|
% endfor
|
||||||
<td>
|
<td>
|
||||||
<a href="/modify?user=${user}">
|
<a href="/modify?user=${user}">
|
||||||
<button type="submit" class="btn btn-xs blue">
|
<button type="submit" class="btn btn-xs blue">
|
||||||
@ -56,9 +62,11 @@
|
|||||||
% endfor
|
% endfor
|
||||||
</tbody>
|
</tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
%for attr in attrs_list:
|
||||||
<th>
|
<th>
|
||||||
User
|
${attrs_list[attr]}
|
||||||
</th>
|
</th>
|
||||||
|
% endfor
|
||||||
<th class="sorter-false">
|
<th class="sorter-false">
|
||||||
Modify
|
Modify
|
||||||
</th>
|
</th>
|
||||||
|
@ -30,12 +30,24 @@ class TestError(object):
|
|||||||
expected = Set(['ldap', 'ad'])
|
expected = Set(['ldap', 'ad'])
|
||||||
assert ret == expected
|
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):
|
def testGetBackendAttributes(self):
|
||||||
inv = Attributes('./tests/cfg/attributes.yml')
|
inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
ret = inv.get_backend_attributes('ldap')
|
ret = inv.get_backend_attributes('ldap')
|
||||||
expected = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']
|
expected = ['shell', 'cn', 'uid', 'uidNumber', 'gidNumber', 'home', 'userPassword', 'givenName', 'email', 'sn']
|
||||||
assert ret == expected
|
assert ret == expected
|
||||||
|
|
||||||
|
def testGetKey(self):
|
||||||
|
inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
|
ret = inv.get_key()
|
||||||
|
expected = 'uid'
|
||||||
|
assert ret == expected
|
||||||
|
|
||||||
def testWrongGetBackendAttributes(self):
|
def testWrongGetBackendAttributes(self):
|
||||||
inv = Attributes('./tests/cfg/attributes.yml')
|
inv = Attributes('./tests/cfg/attributes.yml')
|
||||||
try:
|
try:
|
||||||
@ -44,7 +56,6 @@ class TestError(object):
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
raise AssertionError("expected an exception")
|
raise AssertionError("expected an exception")
|
||||||
|
|
||||||
|
|
||||||
def testNoFile(self):
|
def testNoFile(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user