Skip to content

Commit

Permalink
Fix signature of node.ext.ldap.ugm.LDAPPrincipals.search accordin…
Browse files Browse the repository at this point in the history
…g to ``node.ext.ugm.interfaces.IPrincipals.search``. The implementation exposed LDAP related arguments and has been renamed to ``raw_search``.
  • Loading branch information
rnixx committed Dec 14, 2017
1 parent 709ece0 commit 2b11669
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ History
1.0b7 (unreleased)
------------------

- Fix signature of ``node.ext.ldap.ugm.LDAPPrincipals.search`` according to
``node.ext.ugm.interfaces.IPrincipals.search``. The implementation exposed
LDAP related arguments and has been renamed to ``raw_search``.
[rnix]

- Add ``exists`` property to ``LDAPStorage``.
[rnix]

Expand Down
29 changes: 26 additions & 3 deletions src/node/ext/ldap/ugm/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,9 +586,9 @@ def _unalias_dict(self, dct):
return unaliased_dct

@default
def search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False, or_keys=None,
or_values=None, page_size=None, cookie=None):
def raw_search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False, or_keys=None,
or_values=None, page_size=None, cookie=None):
search_attrlist = [self._key_attr]
if attrlist is not None and self._key_attr not in attrlist:
search_attrlist += attrlist
Expand Down Expand Up @@ -624,6 +624,29 @@ def search(self, criteria=None, attrlist=None,
return results, cookie
return results

@default
def search(self, criteria=None, attrlist=None,
exact_match=False, or_search=False):
result = []
cookie = None
while True:
try:
chunk, cookie = self.raw_search(
criteria=criteria,
attrlist=attrlist,
exact_match=exact_match,
or_search=or_search,
page_size=self.context.ldap_session._props.page_size,
cookie=cookie
)
except ValueError as e:
logger.error(str(e))
return ret
result += chunk
if not cookie:
break
return result

@default
@locktree
def create(self, pid, **kw):
Expand Down
7 changes: 4 additions & 3 deletions src/node/ext/ldap/ugm/principals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,14 @@ Search for users::
>>> users.search(criteria=dict(sn=schmidt.attrs['sn']), attrlist=['login'])
[(u'Schmidt', {'login': [u'user3']})]

Paginated search for users::
By default, search function is paginated. To control the LDAP search behavior
in more detail, ``raw_search`` can be used::

>>> results, cookie = users.search(page_size=3, cookie='')
>>> results, cookie = users.raw_search(page_size=3, cookie='')
>>> results
[u'Meier', u'M\xfcller', u'Schmidt']

>>> results, cookie = users.search(page_size=3, cookie=cookie)
>>> results, cookie = users.raw_search(page_size=3, cookie=cookie)
>>> results
[u'Umhauer']
>>> assert cookie == ''
Expand Down

0 comments on commit 2b11669

Please sign in to comment.