Skip to content
Snippets Groups Projects
Unverified Commit c366be4c authored by Alexandre Ferland's avatar Alexandre Ferland Committed by GitHub
Browse files

Merge pull request #59 from jm66/issue-58

get_object_details to take query_filter and fallback to LDAP_USER_OBJECT_FILTER or LDAP_GROUP_OBJECT_FILTER
parents 6f5e15ec 353ecf13
No related branches found
No related tags found
No related merge requests found
...@@ -157,11 +157,13 @@ class LDAP(object): ...@@ -157,11 +157,13 @@ class LDAP(object):
except ldap.LDAPError: except ldap.LDAPError:
return return
def get_object_details(self, user=None, group=None, dn_only=False): def get_object_details(self, user=None, group=None, query_filter=None,
dn_only=False):
"""Returns a ``dict`` with the object's (user or group) details. """Returns a ``dict`` with the object's (user or group) details.
:param str user: Username of the user object you want details for. :param str user: Username of the user object you want details for.
:param str group: Name of the group object you want details for. :param str group: Name of the group object you want details for.
:param str query_filter: If included, will be used to query object.
:param bool dn_only: If we should only retrieve the object's :param bool dn_only: If we should only retrieve the object's
distinguished name or not. Default: ``False``. distinguished name or not. Default: ``False``.
""" """
...@@ -171,13 +173,15 @@ class LDAP(object): ...@@ -171,13 +173,15 @@ class LDAP(object):
if user is not None: if user is not None:
if not dn_only: if not dn_only:
fields = current_app.config['LDAP_USER_FIELDS'] fields = current_app.config['LDAP_USER_FIELDS']
query = ldap_filter.filter_format( query_filter = query_filter or \
current_app.config['LDAP_USER_OBJECT_FILTER'], (user,)) current_app.config['LDAP_USER_OBJECT_FILTER']
query = ldap_filter.filter_format(query_filter, (user,))
elif group is not None: elif group is not None:
if not dn_only: if not dn_only:
fields = current_app.config['LDAP_GROUP_FIELDS'] fields = current_app.config['LDAP_GROUP_FIELDS']
query = ldap_filter.filter_format( query_filter = query_filter or \
current_app.config['LDAP_GROUP_OBJECT_FILTER'], (group,)) current_app.config['LDAP_GROUP_OBJECT_FILTER']
query = ldap_filter.filter_format(query_filter, (group,))
conn = self.bind conn = self.bind
try: try:
records = conn.search_s(current_app.config['LDAP_BASE_DN'], records = conn.search_s(current_app.config['LDAP_BASE_DN'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment