bug fixes & improvments

This commit is contained in:
Kload 2012-12-01 15:33:56 +01:00
parent 7d3a25108d
commit cda0099808
3 changed files with 203 additions and 195 deletions

View file

@ -138,12 +138,8 @@ user:
info:
action_help: Get user informations
arguments:
-u:
full: --username
ask: "Username"
pattern: '^[a-z0-9_]+$'
-m:
full: --mail
user-or-mail:
help: Username or mail to get informations
#############################

View file

@ -166,7 +166,14 @@ def main():
try:
args = parse_dict(action_map)
result = args.func(args)
args_dict = vars(args).copy()
for key in args_dict.keys():
sanitized_key = key.replace('-', '_')
if sanitized_key is not key:
args_dict[sanitized_key] = args_dict[key]
del args_dict[key]
del args_dict['func']
result = args.func(**args_dict)
except TypeError, error:
if not __debug__ :
traceback.print_exc()

View file

@ -32,7 +32,7 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
else: limit = 1000
if not filter: filter = 'uid=*'
if fields:
for attr in fields:
for attr in fields.items():
if attr in user_attrs:
attrs.append(attr)
continue
@ -267,13 +267,13 @@ def user_update(username, firstname=None, lastname=None, mail=None, change_passw
if yldap.update('uid=' + username + ',ou=users', new_attr_dict):
win_msg(_("User successfully updated"))
return user_info(username=username)
return user_info(username)
else:
raise YunoHostError(169, _("An error occured during user update"))
def user_info(username=None, mail=None):
def user_info(user_or_mail):
"""
Fetch user informations from LDAP
@ -287,13 +287,18 @@ def user_info(username=None, mail=None):
with YunoHostLDAP() as yldap:
user_attrs = ['cn', 'mail', 'uid', 'mailAlias']
if mail:
filter = 'mail=' + mail
if len(user_or_mail.split('@')) is 2:
filter = '(|(mail='+ user_or_mail +')(mailalias='+ user_or_mail +'))'
else:
filter = 'uid=' + username
filter = 'uid='+ user_or_mail
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs)
user = result[0]
if result:
user = result[0]
else:
raise YunoHostError(22, _("Unknown user/mail"))
result_dict = {
'Username': user['uid'],
'Fullname': user['cn'],