Correct PUT method handling & Add infos to user_info

This commit is contained in:
Kload 2013-09-23 10:29:49 +00:00
parent badc24cb98
commit 5c7f66eb3c
2 changed files with 10 additions and 5 deletions

View file

@ -8,9 +8,9 @@ import json
sys.path.append('/usr/share/pyshared') sys.path.append('/usr/share/pyshared')
from twisted.python.log import ILogObserver, FileLogObserver, startLogging from twisted.python.log import ILogObserver, FileLogObserver, startLogging, msg
from twisted.python.logfile import DailyLogFile from twisted.python.logfile import DailyLogFile
from twisted.web.server import Site from twisted.web.server import Site, http
from twisted.internet import reactor from twisted.internet import reactor
from twisted.application import internet,service from twisted.application import internet,service
from txrestapi.resource import APIResource from txrestapi.resource import APIResource
@ -56,14 +56,17 @@ def http_exec(request, **kwargs):
return 'Unauthorized' return 'Unauthorized'
path = request.path path = request.path
given_args = request.args if request.method == 'PUT':
given_args = http.parse_qs(request.content.read(), 1)
else:
given_args = request.args
if kwargs: if kwargs:
for k, v in kwargs.iteritems(): for k, v in kwargs.iteritems():
dynamic_key = path.split('/')[-1] dynamic_key = path.split('/')[-1]
path = path.replace(dynamic_key, '{'+ k +'}') path = path.replace(dynamic_key, '{'+ k +'}')
given_args[k] = [v] given_args[k] = [v]
print given_args msg(given_args)
# Sanitize arguments # Sanitize arguments
dict = action_dict[request.method +' '+ path] dict = action_dict[request.method +' '+ path]
if 'arguments' in dict: possible_args = dict['arguments'] if 'arguments' in dict: possible_args = dict['arguments']

View file

@ -260,7 +260,7 @@ def user_info(username):
""" """
with YunoHostLDAP() as yldap: with YunoHostLDAP() as yldap:
user_attrs = ['cn', 'mail', 'uid', 'maildrop'] user_attrs = ['cn', 'mail', 'uid', 'maildrop', 'givenName', 'sn']
if len(username.split('@')) is 2: if len(username.split('@')) is 2:
filter = 'mail='+ username filter = 'mail='+ username
@ -277,6 +277,8 @@ def user_info(username):
result_dict = { result_dict = {
'Username': user['uid'][0], 'Username': user['uid'][0],
'Fullname': user['cn'][0], 'Fullname': user['cn'][0],
'Firstname': user['givenName'][0],
'Lastname': user['sn'][0],
'Mail': user['mail'][0] 'Mail': user['mail'][0]
} }