From 3a867a4cd1b603e0a562ad07676f7fa32bb67202 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 24 Feb 2019 15:25:59 +0100 Subject: [PATCH] Update check_user_exists to accept attributes and add doc --- dal/ungleich_ldap.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/dal/ungleich_ldap.py b/dal/ungleich_ldap.py index 24566fa..5e31b38 100644 --- a/dal/ungleich_ldap.py +++ b/dal/ungleich_ldap.py @@ -142,7 +142,8 @@ class LdapManager: conn.unbind() return return_val - def check_user_exists(self, uid, is_customer=True, search_filter=""): + def check_user_exists(self, uid, is_customer=True, search_filter="", + attributes=None): """ Check if the user with the given uid exists in the customer group. @@ -152,7 +153,11 @@ class LdapManager: :param search_filter: str representing the filter condition to find users. If its empty, the search finds the user with the given uid. - :return: True if the user exists otherwise return False + :param attributes: list A list of str representing all the attributes + to be obtained in the result entries + :return: tuple (bool, [ldap3.abstract.entry.Entry ..]) + A bool indicating if the user exists + A list of all entries obtained in the search """ conn = self.get_admin_conn() entries = [] @@ -160,7 +165,8 @@ class LdapManager: result = conn.search( settings.LDAP_CUSTOMER_DN if is_customer else settings.LDAP_USERS_DN, search_filter=search_filter if len(search_filter)> 0 else - '(uid={uid})'.format(uid=uid) + '(uid={uid})'.format(uid=uid), + attributes=attributes ) entries = conn.entries finally: