X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FUI.git;a=blobdiff_plain;f=skyquake%2Fframework%2Fcore%2Fmodules%2Fapi%2FuserManagementAPI.js;fp=skyquake%2Fframework%2Fcore%2Fmodules%2Fapi%2FuserManagementAPI.js;h=fdce725b03b3d738e4428e6be84b220e17b42471;hp=1aee575d73193623c5224121746ba4dfbb5f0165;hb=0d60d777e67c32b42692dc8e952827671ff3b8d1;hpb=d5f18198d2750fb2a4613846a9885f7b74b6ca93 diff --git a/skyquake/framework/core/modules/api/userManagementAPI.js b/skyquake/framework/core/modules/api/userManagementAPI.js index 1aee575d7..fdce725b0 100644 --- a/skyquake/framework/core/modules/api/userManagementAPI.js +++ b/skyquake/framework/core/modules/api/userManagementAPI.js @@ -32,8 +32,7 @@ UserManagement.get = function(req) { var api_server = req.query['api_server']; return new Promise(function(resolve, reject) { - Promise.all([ - rp({ + var userConfig = rp({ uri: utils.confdPort(api_server) + '/api/operational/user-config/user', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { @@ -42,15 +41,53 @@ UserManagement.get = function(req) { forever: constants.FOREVER_ON, rejectUnauthorized: false, resolveWithFullResponse: true + }); + var userOp = rp({ + uri: utils.confdPort(api_server) + '/api/operational/user-state/user', + method: 'GET', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.session && req.session.authorization + }), + forever: constants.FOREVER_ON, + rejectUnauthorized: false, + resolveWithFullResponse: true }) + Promise.all([ + userConfig, + userOp ]).then(function(result) { var response = {}; response['data'] = {}; + var resultData = []; if (result[0].body) { - response['data']['user'] = JSON.parse(result[0].body)['rw-user:user']; + resultData.push(JSON.parse(result[0].body)['rw-user:user'].sort()); + } + if (result[1].body) { + resultData.push(JSON.parse(result[1].body)['rw-user:user'].sort()); } response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK - + response['data']['user'] = resultData[0].map(function(d,i) { + var mergedData = _.merge(d, resultData[1][i]); + mergedData.projects = { + ids: [], + data: {} + }; + var projects = mergedData.projects; + mergedData.role && mergedData.role.map(function(r) { + if ((r.role != "rw-project:user-self" )&& (r.role != "rw-rbac-platform:user-self")) { + var projectId = r.keys.split(';')[0]; + if (projectId == "") { + projectId = "platform" + } + if (!projects.data[projectId]) { + projects.ids.push(projectId); + projects.data[projectId] = []; + } + projects.data[projectId].push(r.role); + } + }) + return mergedData; + }) resolve(response); }).catch(function(error) { var response = {};