mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
User info function + purge home for delete func
This commit is contained in:
parent
91bbbe766f
commit
63e31f7985
2 changed files with 38 additions and 6 deletions
|
@ -93,6 +93,8 @@ user:
|
|||
users:
|
||||
help: Username of users to delete
|
||||
nargs: "+"
|
||||
--purge:
|
||||
action: store_true
|
||||
|
||||
### user_update()
|
||||
update:
|
||||
|
@ -135,12 +137,10 @@ user:
|
|||
connections:
|
||||
- ldap
|
||||
arguments:
|
||||
user:
|
||||
nargs: "?"
|
||||
-u:
|
||||
full: --user
|
||||
-m:
|
||||
full: --mail
|
||||
-cn:
|
||||
full: --fullname
|
||||
|
||||
|
||||
#############################
|
||||
|
|
|
@ -42,14 +42,14 @@ def user_list(args, connections):
|
|||
|
||||
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, attrs)
|
||||
|
||||
if len(result) > (0 + offset) and limit > 0:
|
||||
if result and len(result) > (0 + offset) and limit > 0:
|
||||
i = 0 + offset
|
||||
for entry in result[i:]:
|
||||
if i < limit:
|
||||
result_dict[str(i)] = entry
|
||||
i += 1
|
||||
else:
|
||||
result_dict = { 'Notice' : _("No user found") }
|
||||
raise YunoHostError(167, _("No user found"))
|
||||
|
||||
return result_dict
|
||||
|
||||
|
@ -155,6 +155,8 @@ def user_delete(args, connections):
|
|||
for user in args['users']:
|
||||
validate({ user : r'^[a-z0-9_]+$' })
|
||||
if yldap.remove('uid=' + user+ ',ou=users'):
|
||||
if args['purge']:
|
||||
os.system('rm -rf /home/' + user)
|
||||
result['Users'].append(user)
|
||||
continue
|
||||
else:
|
||||
|
@ -163,3 +165,33 @@ def user_delete(args, connections):
|
|||
win_msg(_("User(s) successfully deleted"))
|
||||
return result
|
||||
|
||||
|
||||
def user_info(args, connections):
|
||||
"""
|
||||
Fetch user informations from LDAP
|
||||
|
||||
Keyword argument:
|
||||
args -- Dictionnary of values (can be empty)
|
||||
connections -- LDAP connection
|
||||
|
||||
Returns:
|
||||
Dict
|
||||
"""
|
||||
yldap = connections['ldap']
|
||||
user_attrs = ['cn', 'mail', 'uid']
|
||||
|
||||
if args['mail']:
|
||||
validate({ args['mail'] : r'^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,6}$' })
|
||||
filter = 'mail=' + args['mail']
|
||||
else:
|
||||
args = get_required_args(args, { 'user' : _("Username") })
|
||||
validate({ args['user'] : r'^[a-z0-9_]+$' })
|
||||
filter = 'uid=' + args['user']
|
||||
|
||||
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs)
|
||||
|
||||
if result:
|
||||
return result[0]
|
||||
else:
|
||||
raise YunoHostError(167, _("No user found"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue