mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
user_list() function
This commit is contained in:
parent
0367811b6e
commit
34330a41cc
2 changed files with 51 additions and 8 deletions
|
@ -37,10 +37,12 @@ def colorize(astr, color):
|
||||||
def pretty_print_dict(d, depth=0):
|
def pretty_print_dict(d, depth=0):
|
||||||
for k,v in sorted(d.items(), key=lambda x: x[0]):
|
for k,v in sorted(d.items(), key=lambda x: x[0]):
|
||||||
k = colorize(k, 'purple')
|
k = colorize(k, 'purple')
|
||||||
|
if isinstance(v, list) and len(v) == 1:
|
||||||
|
v = v[0]
|
||||||
if isinstance(v, dict):
|
if isinstance(v, dict):
|
||||||
print((" ") * depth + ("%s: " % k))
|
print((" ") * depth + ("%s: " % k))
|
||||||
pretty_print_dict(v, depth+1)
|
pretty_print_dict(v, depth+1)
|
||||||
if isinstance(v, list):
|
elif isinstance(v, list):
|
||||||
print((" ") * depth + ("%s: " % k))
|
print((" ") * depth + ("%s: " % k))
|
||||||
for value in v:
|
for value in v:
|
||||||
print((" ") * (depth+1) + "- " + value)
|
print((" ") * (depth+1) + "- " + value)
|
||||||
|
|
|
@ -9,8 +9,49 @@ import string
|
||||||
import getpass
|
import getpass
|
||||||
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
|
from yunohost import YunoHostError, win_msg, colorize, validate, get_required_args
|
||||||
|
|
||||||
def user_list(args, connections): # TODO : fix
|
def user_list(args, connections):
|
||||||
print(args)
|
"""
|
||||||
|
List YunoHost users from LDAP
|
||||||
|
|
||||||
|
Keyword argument:
|
||||||
|
args -- Dictionnary of values (can be empty)
|
||||||
|
connections -- LDAP connection
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Dict
|
||||||
|
"""
|
||||||
|
yldap = connections['ldap']
|
||||||
|
user_attrs = ['uid', 'mail', 'cn']
|
||||||
|
attrs = []
|
||||||
|
result_dict = {}
|
||||||
|
if args['offset']: offset = int(args['offset'])
|
||||||
|
else: offset = 0
|
||||||
|
if args['limit']: limit = int(args['limit'])
|
||||||
|
else: limit = 1000
|
||||||
|
if args['filter']: filter = args['filter']
|
||||||
|
else: filter = 'uid=*'
|
||||||
|
if args['fields']:
|
||||||
|
for attr in args['fields']:
|
||||||
|
if attr in user_attrs:
|
||||||
|
attrs.append(attr)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise YunoHostError(22, _("Invalid field : ") + attr)
|
||||||
|
else:
|
||||||
|
attrs = user_attrs
|
||||||
|
|
||||||
|
result = yldap.search('ou=users,dc=yunohost,dc=org', filter, attrs)
|
||||||
|
|
||||||
|
if 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") }
|
||||||
|
|
||||||
|
return result_dict
|
||||||
|
|
||||||
|
|
||||||
def user_create(args, connections):
|
def user_create(args, connections):
|
||||||
|
@ -21,7 +62,7 @@ def user_create(args, connections):
|
||||||
args -- Dictionnary of values (can be empty)
|
args -- Dictionnary of values (can be empty)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Boolean
|
Dict
|
||||||
"""
|
"""
|
||||||
yldap = connections['ldap']
|
yldap = connections['ldap']
|
||||||
args = get_required_args(args, {
|
args = get_required_args(args, {
|
||||||
|
|
Loading…
Reference in a new issue