From: Laurence Maultsby Date: Tue, 9 May 2017 18:38:41 +0000 (-0400) Subject: Added projects to user management X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fprojects;p=osm%2FUI.git Added projects to user management Signed-off-by: Laurence Maultsby --- 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 = {}; diff --git a/skyquake/plugins/user_management/src/dashboard/dashboard.jsx b/skyquake/plugins/user_management/src/dashboard/dashboard.jsx index 7af061421..70386c7ac 100644 --- a/skyquake/plugins/user_management/src/dashboard/dashboard.jsx +++ b/skyquake/plugins/user_management/src/dashboard/dashboard.jsx @@ -321,18 +321,43 @@ class UserManagementDashboard extends React.Component { - - - + { + !state.isEditUser ? + + + + + + + + + + { + this.state.projects && this.state.projects.ids && this.state.projects.ids.map((p,i)=> { + let project = self.state.projects.data[p]; + let userRoles = []; + return ( + + + + + ) + }) + } + +
ProjectRole
+ {p} + + { + project.map(function(k) { + return
{k}
+ }) + } +
+
+ : null + } + {passwordSectionHTML} diff --git a/skyquake/plugins/user_management/src/dashboard/userMgmtStore.js b/skyquake/plugins/user_management/src/dashboard/userMgmtStore.js index b68c72cd2..19742475d 100644 --- a/skyquake/plugins/user_management/src/dashboard/userMgmtStore.js +++ b/skyquake/plugins/user_management/src/dashboard/userMgmtStore.js @@ -74,6 +74,7 @@ export default class UserManagementStore { platformRoles: user.platformRoles || this.platformRoles, disabled: user.hasOwnProperty('disabled').toString().toUpperCase(), projectRoles: user.projectRoles || this.projectRoles, + projects: user.projects, currentPassword: user.password } let state = _.merge({