From 4e9493f1980336c9e87bcaf68757413d4270717a Mon Sep 17 00:00:00 2001 From: PCoder Date: Sun, 24 Feb 2019 17:44:48 +0100 Subject: [PATCH] Add delete_user --- dal/ungleich_ldap.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dal/ungleich_ldap.py b/dal/ungleich_ldap.py index 2ee70c5..5d56d2a 100644 --- a/dal/ungleich_ldap.py +++ b/dal/ungleich_ldap.py @@ -200,6 +200,27 @@ class LdapManager: conn.unbind() return result, entries + def delete_user(self, uid): + """ + Deletes the user with the given uid from ldap + + :param uid: str representing the user + :return: True if the delete was successful False otherwise + """ + conn = self.get_admin_conn() + try: + return_val = conn.delete( + ("uid={uid}," + settings.LDAP_CUSTOMER_DN).format(uid=uid), + ) + msg = "success" + except Exception as ex: + msg = str(ex) + logger.error("Exception: " + msg) + return_val = False + finally: + conn.unbind() + return return_val, msg + def _set_max_uid(self, max_uid): """ a utility function to save max_uid value to a file