mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Full user_delete function
This commit is contained in:
parent
34330a41cc
commit
91bbbe766f
2 changed files with 50 additions and 0 deletions
19
yunohost.py
19
yunohost.py
|
@ -332,6 +332,25 @@ class YunoHostLDAP:
|
||||||
else:
|
else:
|
||||||
return True
|
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):
|
def update(self, rdn, attr_dict, new_rdn=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -60,6 +60,7 @@ def user_create(args, connections):
|
||||||
|
|
||||||
Keyword argument:
|
Keyword argument:
|
||||||
args -- Dictionnary of values (can be empty)
|
args -- Dictionnary of values (can be empty)
|
||||||
|
connections -- LDAP connections
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict
|
Dict
|
||||||
|
@ -132,3 +133,33 @@ def user_create(args, connections):
|
||||||
return { _("Fullname") : fullname, _("Username") : args['username'], _("Mail") : args['mail'] }
|
return { _("Fullname") : fullname, _("Username") : args['username'], _("Mail") : args['mail'] }
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(169, _("An error occured during user creation"))
|
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
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue