mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
bug fixes & improvments
This commit is contained in:
parent
7d3a25108d
commit
cda0099808
3 changed files with 203 additions and 195 deletions
|
@ -138,12 +138,8 @@ user:
|
||||||
info:
|
info:
|
||||||
action_help: Get user informations
|
action_help: Get user informations
|
||||||
arguments:
|
arguments:
|
||||||
-u:
|
user-or-mail:
|
||||||
full: --username
|
help: Username or mail to get informations
|
||||||
ask: "Username"
|
|
||||||
pattern: '^[a-z0-9_]+$'
|
|
||||||
-m:
|
|
||||||
full: --mail
|
|
||||||
|
|
||||||
|
|
||||||
#############################
|
#############################
|
||||||
|
|
|
@ -166,7 +166,14 @@ def main():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
args = parse_dict(action_map)
|
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:
|
except TypeError, error:
|
||||||
if not __debug__ :
|
if not __debug__ :
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
|
@ -32,7 +32,7 @@ def user_list(fields=None, filter=None, limit=None, offset=None):
|
||||||
else: limit = 1000
|
else: limit = 1000
|
||||||
if not filter: filter = 'uid=*'
|
if not filter: filter = 'uid=*'
|
||||||
if fields:
|
if fields:
|
||||||
for attr in fields:
|
for attr in fields.items():
|
||||||
if attr in user_attrs:
|
if attr in user_attrs:
|
||||||
attrs.append(attr)
|
attrs.append(attr)
|
||||||
continue
|
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):
|
if yldap.update('uid=' + username + ',ou=users', new_attr_dict):
|
||||||
win_msg(_("User successfully updated"))
|
win_msg(_("User successfully updated"))
|
||||||
return user_info(username=username)
|
return user_info(username)
|
||||||
else:
|
else:
|
||||||
raise YunoHostError(169, _("An error occured during user update"))
|
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
|
Fetch user informations from LDAP
|
||||||
|
|
||||||
|
@ -287,13 +287,18 @@ def user_info(username=None, mail=None):
|
||||||
with YunoHostLDAP() as yldap:
|
with YunoHostLDAP() as yldap:
|
||||||
user_attrs = ['cn', 'mail', 'uid', 'mailAlias']
|
user_attrs = ['cn', 'mail', 'uid', 'mailAlias']
|
||||||
|
|
||||||
if mail:
|
if len(user_or_mail.split('@')) is 2:
|
||||||
filter = 'mail=' + mail
|
filter = '(|(mail='+ user_or_mail +')(mailalias='+ user_or_mail +'))'
|
||||||
else:
|
else:
|
||||||
filter = 'uid=' + username
|
filter = 'uid='+ user_or_mail
|
||||||
|
|
||||||
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs)
|
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, user_attrs)
|
||||||
|
|
||||||
|
if result:
|
||||||
user = result[0]
|
user = result[0]
|
||||||
|
else:
|
||||||
|
raise YunoHostError(22, _("Unknown user/mail"))
|
||||||
|
|
||||||
result_dict = {
|
result_dict = {
|
||||||
'Username': user['uid'],
|
'Username': user['uid'],
|
||||||
'Fullname': user['cn'],
|
'Fullname': user['cn'],
|
||||||
|
|
Loading…
Add table
Reference in a new issue