From 91bbbe766fe2a466aea53fd0cb7ca8affc835014 Mon Sep 17 00:00:00 2001 From: Kloadut Date: Mon, 29 Oct 2012 12:35:29 +0100 Subject: [PATCH] Full user_delete function --- yunohost.py | 19 +++++++++++++++++++ yunohost_user.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/yunohost.py b/yunohost.py index b58027e1..3d83e6c8 100644 --- a/yunohost.py +++ b/yunohost.py @@ -332,6 +332,25 @@ class YunoHostLDAP: else: return True + def remove(self, rdn): + """ + Remove LDAP entry + + Keyword arguments: + rdn -- DN without domain + + Returns: + Boolean | YunoHostError + + """ + dn = rdn + ',' + self.base + try: + self.conn.delete_s(dn) + except: + raise YunoHostError(169, _('An error occured during LDAP entry deletion')) + else: + return True + def update(self, rdn, attr_dict, new_rdn=False): """ diff --git a/yunohost_user.py b/yunohost_user.py index 5cab685d..c055b879 100644 --- a/yunohost_user.py +++ b/yunohost_user.py @@ -60,6 +60,7 @@ def user_create(args, connections): Keyword argument: args -- Dictionnary of values (can be empty) + connections -- LDAP connections Returns: Dict @@ -132,3 +133,33 @@ def user_create(args, connections): return { _("Fullname") : fullname, _("Username") : args['username'], _("Mail") : args['mail'] } else: raise YunoHostError(169, _("An error occured during user creation")) + + +def user_delete(args, connections): + """ + Remove user from LDAP + + Keyword argument: + args -- Dictionnary of values (can be empty) + connections -- LDAP connection + + Returns: + Dict + """ + yldap = connections['ldap'] + result = { 'Users' : [] } + + if not isinstance(args['users'], list): + args['users'] = [ args['users'] ] + + for user in args['users']: + validate({ user : r'^[a-z0-9_]+$' }) + if yldap.remove('uid=' + user+ ',ou=users'): + result['Users'].append(user) + continue + else: + raise YunoHostError(169, _("An error occured during user deletion")) + + win_msg(_("User(s) successfully deleted")) + return result +