From 353ecf137330528d995cc08c622ed57c6d447fbf Mon Sep 17 00:00:00 2001 From: JM Lopez Lujan Date: Wed, 26 Dec 2018 21:37:31 -0500 Subject: [PATCH] get_object_details to take query_filter and fallback to LDAP_USER_OBJECT_FILTER or LDAP_GROUP_OBJECT_FILTER fixes #58 --- flask_simpleldap/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/flask_simpleldap/__init__.py b/flask_simpleldap/__init__.py index 82ae17f..36f7f39 100644 --- a/flask_simpleldap/__init__.py +++ b/flask_simpleldap/__init__.py @@ -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``. """ @@ -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'],