Added projects to user management projects
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 9 May 2017 18:38:41 +0000 (14:38 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 9 May 2017 18:38:41 +0000 (14:38 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/framework/core/modules/api/userManagementAPI.js
skyquake/plugins/user_management/src/dashboard/dashboard.jsx
skyquake/plugins/user_management/src/dashboard/userMgmtStore.js

index 1aee575..fdce725 100644 (file)
@@ -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 = {};
index 7af0614..70386c7 100644 (file)
@@ -321,18 +321,43 @@ class UserManagementDashboard extends React.Component {
                                 <Input label="Platform Admin" onChange={this.platformChange.bind(null, 'platform_admin')}  checked={state.platformRoles.platform_admin} type="checkbox" />
                                 <Input label="Platform Oper" onChange={this.platformChange.bind(null, 'platform_oper')}  checked={state.platformRoles.platform_oper} type="checkbox" />
                             </FormSection>
-                            <FormSection title="PROJECT ROLES" style={{display:'none'}}>
-                                <InputCollection
-                                    inital={true}
-                                    type='select'
-                                    readonly={state.isReadOnly}
-                                    options={state.projectRolesOptions}
-                                    collection={state.projectRoles}
-                                    onChange={this.updateProjectRole}
-                                    AddItemFn={this.addProjectRole}
-                                    RemoveItemFn={this.removeProjectRole}
-                                    />
-                            </FormSection>
+                            {
+                                !state.isEditUser ?
+                                <FormSection title="PROJECT ROLES">
+                                    <table className="userProfile-table">
+                                        <thead>
+                                            <tr>
+                                                <td>Project</td>
+                                                <td>Role</td>
+                                            </tr>
+                                        </thead>
+                                        <tbody>
+                                            {
+                                                this.state.projects && this.state.projects.ids && this.state.projects.ids.map((p,i)=> {
+                                                    let project = self.state.projects.data[p];
+                                                    let userRoles = [];
+                                                    return (
+                                                        <tr key={i}>
+                                                            <td>
+                                                                {p}
+                                                            </td>
+                                                            <td>
+                                                                {
+                                                                    project.map(function(k) {
+                                                                        return <div>{k}</div>
+                                                                    })
+                                                                }
+                                                            </td>
+                                                        </tr>
+                                                    )
+                                                })
+                                            }
+                                        </tbody>
+                                    </table>
+                                </FormSection>
+                                : null
+                            }
+
                             {passwordSectionHTML}
 
                         </Panel>
index b68c72c..1974247 100644 (file)
@@ -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({