Update check_user_exists to accept attributes and add doc

This commit is contained in:
PCoder 2019-02-24 15:25:59 +01:00
parent 017ca767be
commit 3a867a4cd1

View file

@ -142,7 +142,8 @@ class LdapManager:
conn.unbind() conn.unbind()
return return_val 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. 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 :param search_filter: str representing the filter condition to find
users. If its empty, the search finds the user with users. If its empty, the search finds the user with
the given uid. 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() conn = self.get_admin_conn()
entries = [] entries = []
@ -160,7 +165,8 @@ class LdapManager:
result = conn.search( result = conn.search(
settings.LDAP_CUSTOMER_DN if is_customer else settings.LDAP_USERS_DN, settings.LDAP_CUSTOMER_DN if is_customer else settings.LDAP_USERS_DN,
search_filter=search_filter if len(search_filter)> 0 else 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 entries = conn.entries
finally: finally: