Skip to content

Commit

Permalink
get_object_details to take query_filter and fallback
Browse files Browse the repository at this point in the history
 to LDAP_USER_OBJECT_FILTER or LDAP_GROUP_OBJECT_FILTER
fixes alexferl#58
  • Loading branch information
jm66 committed Dec 27, 2018
1 parent c055478 commit 353ecf1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions flask_simpleldap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,13 @@ def bind_user(self, username, password):
except ldap.LDAPError:
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.
: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 query_filter: If included, will be used to query object.
:param bool dn_only: If we should only retrieve the object's
distinguished name or not. Default: ``False``.
"""
Expand All @@ -169,13 +171,15 @@ def get_object_details(self, user=None, group=None, dn_only=False):
if user is not None:
if not dn_only:
fields = current_app.config['LDAP_USER_FIELDS']
query = ldap_filter.filter_format(
current_app.config['LDAP_USER_OBJECT_FILTER'], (user,))
query_filter = query_filter or \
current_app.config['LDAP_USER_OBJECT_FILTER']
query = ldap_filter.filter_format(query_filter, (user,))
elif group is not None:
if not dn_only:
fields = current_app.config['LDAP_GROUP_FIELDS']
query = ldap_filter.filter_format(
current_app.config['LDAP_GROUP_OBJECT_FILTER'], (group,))
query_filter = query_filter or \
current_app.config['LDAP_GROUP_OBJECT_FILTER']
query = ldap_filter.filter_format(query_filter, (group,))
conn = self.bind
try:
records = conn.search_s(current_app.config['LDAP_BASE_DN'],
Expand Down

0 comments on commit 353ecf1

Please sign in to comment.