Commit 0076ccde authored by Michael Ott's avatar Michael Ott
Browse files

add get user

parent 2f511134
......@@ -309,7 +309,18 @@ function WebBackend.users(WebBackend me)
me.create_json_response(ERROR_NOT_IMPLEMENTED, "Not implemented");
end if
else
me.create_json_response(ERROR_NOT_IMPLEMENTED, "Not implemented");
string str, todo;
integer id, len;
str = .substr(me.path, 8, .inf);
len = .instr(str, "/");
if len != .nul and len != 0
todo = .substr(str, len + 1, .inf);
str = .substr(str, 0, len - 1);
end if
id = me.decode(str);
me.get_user(id);
end if
end function result
......@@ -493,7 +504,7 @@ end function result
//
// Description
// ===========
// Create user
// Get user list
//
// Return Value
// ============
......@@ -538,6 +549,46 @@ function WebBackend.get_user_list(WebBackend me)
me.create_json_response(ERROR_OK, "", data);
end function result;
//////////////////////////////////////////////////////////////////////////
// WebBackend.get_user()
//
// Parameters
// ==========
// me WebBackend object
// integer user_id User id
//
// Description
// ===========
// Get information about a user
//
// Return Value
// ============
// True if there no problem
//////////////////////////////////////////////////////////////////////////
function WebBackend.get_user(WebBackend me, integer user_id)
boolean result;
ppcstype1record record;
result = .false;
record =@ me.find_user(user_id);
if record !@= .nul
JSON_OBJECT data;
data =@ JSON_OBJECT.new(.false, me.encoding);
data.members.addmember(KEY_ID, \
JSON_STRING.new(simpolstringtojsonblob(me.encode(record!CustomerNumber), me.encoding)));
data.members.addmember(KEY_LOGIN, JSON_STRING.new(simpolstringtojsonblob(record!LoginName, me.encoding)));
data.members.addmember(KEY_NAME, JSON_STRING.new(simpolstringtojsonblob(record!Nameline, me.encoding)));
data.members.addmember(KEY_MAIL_ADDRESS, \
JSON_STRING.new(simpolstringtojsonblob(record!EMailAddress, me.encoding)));
data.members.addmember(KEY_ROLE, JSON_STRING.new(simpolstringtojsonblob(record!rights, me.encoding)));
me.create_json_response(ERROR_OK, "", data);
result = .true;
end if
end function result;
//////////////////////////////////////////////////////////////////////////
// WebBackend.find_user()
//
......@@ -558,12 +609,16 @@ function WebBackend.find_user(WebBackend me, integer user_id)
ppcstype1record record;
integer errno;
record =@ .nul
record =@ .nul;
errno = 0;
record =@ me.user_data.CustomerNumber.index.selectkey(user_id, error = errno);
if record =@= .nul
me.create_json_response(ERROR_AUTH, "Cannot find user");
me.log_handler.info_message("Cannot find user with id " + .tostr(user_id, 10));
else if record!project != me.project
me.create_json_response(ERROR_AUTH, "Cannot find user");
me.log_handler.info_message("Cannot find user with id " + .tostr(user_id, 10));
record =@ .nul;
end if
end function record
......@@ -76,6 +76,7 @@ type WebBackend export
function users readonly;
function create_user readonly;
function get_user_list readonly;
function get_user readonly;
function find_user;
end type
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment