Platform Role Assignments take 2
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Thu, 23 Mar 2017 02:49:54 +0000 (22:49 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Thu, 23 Mar 2017 02:49:54 +0000 (22:49 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/framework/core/modules/api/projectManagementAPI.js
skyquake/framework/core/modules/routes/projectManagement.js
skyquake/plugins/user_management/config.json
skyquake/plugins/user_management/src/dashboard/dashboard.jsx
skyquake/plugins/user_management/src/platformRoleManagement/platformRoleManagement.jsx
skyquake/plugins/user_management/src/platformRoleManagement/platformRoleManagementActions.js
skyquake/plugins/user_management/src/platformRoleManagement/platformRoleManagementSource.js
skyquake/plugins/user_management/src/platformRoleManagement/platformRoleManagementStore.js

index d73eb21..44d2ac5 100644 (file)
@@ -62,6 +62,7 @@ ProjectManagement.get = function(req) {
         });
     });
 };
+
 ProjectManagement.create = function(req) {
     var self = this;
     var api_server = req.query['api_server'];
@@ -175,4 +176,87 @@ ProjectManagement.delete = function(req) {
         });
     })
 }
+
+
+ProjectManagement.getPlatform = function(req) {
+    var self = this;
+    var api_server = req.query['api_server'];
+
+    return new Promise(function(resolve, reject) {
+        Promise.all([
+            rp({
+                uri: utils.confdPort(api_server) + '/api/operational/rbac-platform-config',
+                method: 'GET',
+                headers: _.extend({}, constants.HTTP_HEADERS.accept.data, {
+                    'Authorization': req.get('Authorization')
+                }),
+                forever: constants.FOREVER_ON,
+                rejectUnauthorized: false,
+                resolveWithFullResponse: true
+            })
+        ]).then(function(result) {
+            var response = {};
+            response['data'] = {};
+            if (result[0].body) {
+                response['data']['platform'] = JSON.parse(result[0].body)['rw-rbac-platform:rbac-platform-config'];
+            }
+            response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK
+
+            resolve(response);
+        }).catch(function(error) {
+            var response = {};
+            console.log('Problem with ProjectManagement.getPlatform', error);
+            response.statusCode = error.statusCode || 500;
+            response.errorMessage = {
+                error: 'Failed to get ProjectManagement.getPlatform' + error
+            };
+            reject(response);
+        });
+    });
+};
+
+ProjectManagement.updatePlatform = function(req) {
+    var self = this;
+    var api_server = req.query['api_server'];
+    var bodyData = req.body;
+    data = bodyData;
+    var updateTasks = [];
+
+    var updateUser = rp({
+                uri: utils.confdPort(api_server) + '/api/config/rbac-platform-config',
+                method: 'PUT',
+                headers: _.extend({}, constants.HTTP_HEADERS.accept.data, {
+                    'Authorization': req.get('Authorization')
+                }),
+                forever: constants.FOREVER_ON,
+                json: data,
+                rejectUnauthorized: false,
+                resolveWithFullResponse: true
+            });
+    updateTasks.push(updateUser)
+    return new Promise(function(resolve, reject) {
+        Promise.all([
+            updateTasks
+        ]).then(function(result) {
+            var response = {};
+            response['data'] = {};
+            if (result[0].body) {
+                response['data'] = result[0].body;
+            }
+            response.statusCode = constants.HTTP_RESPONSE_CODES.SUCCESS.OK
+
+            resolve(response);
+        }).catch(function(error) {
+            var response = {};
+            console.log('Problem with ProjectManagement.updatePlatform', error);
+            response.statusCode = error.statusCode || 500;
+            response.errorMessage = {
+                error: 'Failed to passwordChange user' + error
+            };
+            reject(response);
+        });
+    });
+};
+
+
 module.exports = ProjectManagement;
index a8f9a4d..ef52ba3 100644 (file)
@@ -65,6 +65,21 @@ Router.delete('/project/:projectname', cors(), function(req, res) {
     });
 });
 
+Router.put('/platform', cors(), function(req, res) {
+    ProjectManagementAPI.updatePlatform(req).then(function(response) {
+        utils.sendSuccessResponse(response, res);
+    }, function(error) {
+        utils.sendErrorResponse(error, res);
+    });
+});
+
+Router.get('/platform', cors(), function(req, res) {
+    ProjectManagementAPI.getPlatform(req).then(function(response) {
+        utils.sendSuccessResponse(response, res);
+    }, function(error) {
+        utils.sendErrorResponse(error, res);
+    });
+});
 module.exports = Router;
 
 
index 0e66f6f..4ee344e 100644 (file)
@@ -14,6 +14,6 @@
         "label": "Platform Role Management",
         "route": "platform",
         "component": "./platformRoleManagement/platformRoleManagement.jsx",
-        "type": "internal"
+        "type": "external"
     }]
 }
index c86d6b1..6012050 100644 (file)
@@ -24,9 +24,9 @@ class UserManagementDashboard extends React.Component {
     constructor(props) {
         super(props);
         this.Store = this.props.flux.stores.hasOwnProperty('UserManagementStore') ? this.props.flux.stores.UserManagementStore : this.props.flux.createStore(UserManagementStore);
-        this.Store.getUsers();
-        this.state = this.Store.getState();
-        this.actions = this.state.actions;
+       this.state = this.Store.getState();
+       this.actions = this.state.actions;
+
     }
     componentDidUpdate() {
         let self = this;
@@ -38,6 +38,7 @@ class UserManagementDashboard extends React.Component {
     }
     componentWillMount() {
         this.Store.listen(this.updateState);
+        this.Store.getUsers();
     }
     componentWillUnmount() {
         this.Store.unlisten(this.updateState);
index 49efb82..39ca9ef 100644 (file)
@@ -5,7 +5,7 @@
 import React from 'react';
 import ReactDOM from 'react-dom';
 import AppHeader from 'widgets/header/header.jsx';
-import ProjectManagementStore from './platformRoleManagementStore.js';
+import PlatformRoleManagementStore from './platformRoleManagementStore.js';
 import SkyquakeComponent from 'widgets/skyquake_container/skyquakeComponent.jsx';
 import 'style/layout.scss';
 import './platformRoleManagement.scss';
@@ -23,15 +23,14 @@ import imgRemove from '../../node_modules/open-iconic/svg/trash.svg'
 class PlatformRoleManagement extends React.Component {
     constructor(props) {
         super(props);
-        this.Store = this.props.flux.stores.hasOwnProperty('ProjectManagementStore') ? this.props.flux.stores.ProjectManagementStore : this.props.flux.createStore(ProjectManagementStore);
-        this.Store.getProjects();
-        this.Store.getUsers();
+        this.Store = this.props.flux.stores.hasOwnProperty('PlatformRoleManagementStore') ? this.props.flux.stores.PlatformRoleManagementStore : this.props.flux.createStore(PlatformRoleManagementStore);
         this.state = this.Store.getState();
         this.actions = this.state.actions;
+        this.Store.getPlatform();
+        this.Store.getUsers();
     }
     componentDidUpdate() {
-        let self = this;
-        ReactDOM.findDOMNode(this.projectList).addEventListener('transitionend', this.onTransitionEnd, false);
+
     }
     componentWillMount() {
         this.Store.listen(this.updateState);
@@ -86,65 +85,41 @@ class PlatformRoleManagement extends React.Component {
                 'name': this.state['name']
             });
     }
-    createProject = (e) => {
+    updatePlatform = (e) => {
         let self = this;
         e.preventDefault();
         e.stopPropagation();
-        let projectUsers = self.state.projectUsers;
-        let selectedUsers = [];
-        //Remove null values from role
-        projectUsers.map((u) => {
-           u.role && u.role.map((r,i) => {
-             let role = {};
-             //you may add a user without a role or a keys, but if one is present then the other must be as well.
-            if(!r || ((r.role || r['keys']) && (!r.role || !r['keys']))) {
-                projectUsers.splice(i, 1);
-            } else {
-                return u;
-            }
-           })
-        })
-        this.Store.createProject({
-            'name': self.state['name'],
-            'description': self.state.description,
-            'project-config' : {
-                'user': projectUsers
+        let platformUsers = self.state.platformUsers;
+        let cleanUsers = this.cleanUsers(platformUsers);
+
+
+        this.Store.updatePlatform({
+                'user': platformUsers
             }
-        });
+        );
     }
-    updateProject = (e) => {
-        let self = this;
-        e.preventDefault();
-        e.stopPropagation();
-        let projectUsers = self.state.projectUsers;
-
+     cleanUsers(projectUsers) {
+        let cleanUsers = [];
         //Remove null values from role
         projectUsers.map((u) => {
-           u.role && u.role.map((r,i) => {
-             let role = {};
-             //you may add a user without a role or a keys, but if one is present then the other must be as well.
-            if(!r || ((r.role || r['keys']) && (!r.role || !r['keys']))) {
-                projectUsers.splice(i, 1);
-            } else {
-                return u;
-            }
-           })
-        })
-
-        this.Store.updateProject(_.merge({
-            'name': self.state['name'],
-            'description': self.state.description,
-            'project-config' : {
-                'user': projectUsers
-            }
-        }));
+            let cleanRoles = [];
+            u.role && u.role.map((r,i) => {
+                let role = {};
+                if(r.role){
+                    //removing key for rbac-platform
+                    delete r.keys;
+                    cleanRoles.push(r)
+                }
+            });
+           u.role = cleanRoles;
+           cleanUsers.push(u);
+        });
+        return cleanUsers;
     }
      evaluateSubmit = (e) => {
         if (e.keyCode == 13) {
             if (this.props.isEdit) {
-                this.updateProject(e);
-            } else {
-                this.createProject(e);
+                this.updatePlatform(e);
             }
             e.preventDefault();
             e.stopPropagation();
@@ -209,9 +184,9 @@ class PlatformRoleManagement extends React.Component {
                 <Button label="EDIT" type="submit" onClick={this.editProject} />
             </ButtonGroup>
         );
-        let projectUsers = [];
-        self.state.projectUsers.map((u) => {
-            projectUsers.push(u['user-name']);
+        let platformUsers = [];
+        self.state.platformUsers.map((u) => {
+            platformUsers.push(u['user-name']);
         });
 
         if(!this.state.isReadOnly) {
@@ -219,14 +194,14 @@ class PlatformRoleManagement extends React.Component {
                                 state.isEdit ?
                                 (
                                     <ButtonGroup className="buttonGroup">
-                                        <Button label="Update" type="submit" onClick={this.updateProject} />
+                                        <Button label="Update" type="submit" onClick={this.updatePlatform} />
                                         <Button label="Delete" onClick={this.deleteProject} />
                                         <Button label="Cancel" onClick={this.cancelEditProject} />
                                     </ButtonGroup>
                                 )
                                 : (
                                     <ButtonGroup className="buttonGroup">
-                                        <Button label="Create" type="submit" onClick={this.createProject}  />
+                                        <Button label="Create" type="submit" onClick={this.updatePlatform}  />
                                     </ButtonGroup>
                                 )
                             )
@@ -257,10 +232,10 @@ class PlatformRoleManagement extends React.Component {
                             </thead>
                             <tbody>
                                 {
-                            state.projectUsers.map((u,i)=> {
-                                let userRoles = u.role.map((r) => {
+                            state.platformUsers.map((u,i)=> {
+                                let userRoles = u.role && u.role.map((r) => {
                                     return r.role;
-                                })
+                                }) || [];
                                 return (
                                     <tr key={i}>
                                         {!state.isReadOnly ? <td><span
@@ -284,77 +259,6 @@ class PlatformRoleManagement extends React.Component {
                         }
                             </tbody>
                         </table>
-
-
-                        { false ?
-                            <div>
-                                <div className="tableRow tableRow--header">
-                                    <div className="projectName">
-                                        User Name
-                                    </div>
-                                    <div>
-                                        Role
-                                    </div>
-                                </div>
-                                {
-                                    state.projectUsers && state.projectUsers.map((u, k) => {
-                                        return (
-                                            <div ref={(el) => this[`project-ref-${k}`] = el} className={`tableRow tableRow--data projectUsers`} key={k}>
-                                                <div className="userName" style={state.isReadOnly ? {paddingTop: '0.25rem'} : {} }>{u['user-name']}</div>
-                                                <div>
-                                                    {
-                                                        u.role && u.role.map((r, l) => {
-                                                            return (
-                                                                <div key={l}>
-                                                                    <div style={{display: 'flex'}} className="selectRole">
-                                                                        <SelectOption
-                                                                            readonly={state.isReadOnly}
-                                                                            defaultValue={r.role}
-                                                                            options={state.roles}
-                                                                            onChange={self.updateUserRoleInProject.bind(self, k, l)}
-                                                                        />
-                                                                        {!state.isReadOnly ?
-                                                                            <span
-                                                                            className="removeInput"
-                                                                            onClick={self.removeRoleFromUserInProject.bind(self, k, l)}
-                                                                            >
-                                                                                <img src={imgRemove} />
-                                                                                Remove Role
-                                                                            </span>
-                                                                            : null
-                                                                        }
-
-                                                                    </div>
-                                                                </div>
-                                                            )
-                                                        })
-                                                    }
-                                                    {!state.isReadOnly ?
-                                                        <div className="buttonGroup">
-                                                            <span className="addInput addRole" onClick={self.addRoleToUserInProject.bind(self, k)}><img src={imgAdd} />
-                                                                Add Role
-                                                            </span>
-                                                            {
-                                                                (!(u.role && u.role.length)) ?
-                                                                    <span
-                                                                        className="removeInput"
-                                                                        onClick={self.removeUserFromProject.bind(self, k)}
-                                                                    >
-                                                                        <img src={imgRemove} />
-                                                                        Remove User
-                                                                    </span> : null
-                                                            }
-                                                        </div>
-                                                        : null
-                                                    }
-                                                </div>
-                                            </div>
-                                        )
-                                    })
-                                }
-                                </div>
-                                 : null
-                             }
                             {
                                 !state.isReadOnly ?
                                     <div className="tableRow tableRow--header">
@@ -365,7 +269,7 @@ class PlatformRoleManagement extends React.Component {
                                                     defaultValue={state.selectedUser}
                                                     initial={true}
                                                     options={state.users && state.users.filter((u) => {
-                                                        return projectUsers.indexOf(u['user-name']) == -1
+                                                        return platformUsers.indexOf(u['user-name']) == -1
                                                     }).map((u) => {
                                                         return {
                                                             label: u['user-name'],
index 5f2b1ea..6ef5720 100644 (file)
@@ -16,7 +16,8 @@ module.exports = function(Alt) {
                                        'handleAddUser',
                                        'handleRemoveUserFromProject',
                                        'getProjectsSuccess',
-                                       'getUsersSuccess',
+                                       'getPlatformSuccess',
+                                       'getPlatformRoleUsersSuccess',
                                        'getProjectsNotification',
                                        'handleDisabledChange',
                                        'handlePlatformRoleUpdate',
index 72fc2d3..2024622 100644 (file)
@@ -42,22 +42,22 @@ module.exports = function(Alt) {
           interceptResponse: interceptResponse({
             'error': 'There was an error retrieving the resource orchestrator information.'
           }),
-          success: Alt.actions.global.getUsersSuccess,
+          success: Alt.actions.global.getPlatformRoleUsersSuccess,
                     loading: Alt.actions.global.showScreenLoader,
           error: Alt.actions.global.showNotification
         },
-        getProjects: {
+        getPlatform: {
           remote: function() {
               return new Promise(function(resolve, reject) {
                 // setTimeout(function() {
                 //   resolve(Projects);
                 // }, 1000)
                 $.ajax({
-                  url: `/project?api_server=${API_SERVER}`,
+                  url: `/platform?api_server=${API_SERVER}`,
                   type: 'GET',
                   beforeSend: Utils.addAuthorizationStub,
                   success: function(data, textStatus, jqXHR) {
-                    resolve(data.project);
+                    resolve(data.platform);
                   }
                 }).fail(function(xhr){
                   //Authentication and the handling of fail states should be wrapped up into a connection class.
@@ -68,15 +68,15 @@ module.exports = function(Alt) {
           interceptResponse: interceptResponse({
             'error': 'There was an error retrieving the resource orchestrator information.'
           }),
-          success: Alt.actions.global.getProjectsSuccess,
+          success: Alt.actions.global.getPlatformSuccess,
                     loading: Alt.actions.global.showScreenLoader,
           error: Alt.actions.global.showNotification
         },
-        updateProject: {
+        updatePlatform: {
           remote: function(state, project) {
             return new Promise(function(resolve, reject) {
               $.ajax({
-                  url: `/project?api_server=${API_SERVER}`,
+                  url: `/platform?api_server=${API_SERVER}`,
                   type: 'PUT',
                   data: project,
                   beforeSend: Utils.addAuthorizationStub,
index 87eeb61..89f77b2 100644 (file)
@@ -12,10 +12,10 @@ export default class PlatformRoleManagementStore {
         this.projects = [];
         this['name'] = '';
         this['description'] = 'Some Description';
-        this.projectUsers = [];
+        this.platformUsers = [];
         this.selectedUser = null;
         this.selectedRole = null;
-        this.roles = ['super_admin', 'operator_role'
+        this.roles = ['rw-rbac-platform:platform-admin', 'rw-rbac-platform:platform-oper', 'rw-rbac-platform:super-admin'
         // 'some_other_role', 'yet_another_role', 'operator_role', 'some_other_role', 'yet_another_role'
         ];
         this.users = [];
@@ -63,7 +63,7 @@ export default class PlatformRoleManagementStore {
         let ProjectUser = {
             'name': project['name'],
             'description': project['description'],
-            'projectUsers': project['project-config'] && project['project-config']['user'] || []
+            'platformUsers': project['project-config'] && project['project-config']['user'] || []
         }
         let state = _.merge({
             activeIndex: projectIndex,
@@ -136,7 +136,7 @@ export default class PlatformRoleManagementStore {
                 projectOpen: true,
                 activeIndex: null,
                 isReadOnly: false,
-                projectUsers: []
+                platformUsers: []
             }
         ))
     }
@@ -149,78 +149,93 @@ export default class PlatformRoleManagementStore {
     handleAddUser() {
         let u = JSON.parse(this.selectedUser);
         let r = this.selectedRole;
-        let projectUsers = this.projectUsers;
+        let platformUsers = this.platformUsers;
+        let keys = ","
         console.log('adding user')
-        projectUsers.push({
+        platformUsers.push({
           'user-name': u['user-name'],
           'user-domain': u['user-domain'],
           "role":[{
                       "role": r,
-                      "keys": r
+                      "keys": keys
             }
           ]
         })
-        this.setState({projectUsers, selectedUser: null})
+        this.setState({platformUsers, selectedUser: null})
     }
     handleToggleUserRoleInProject(data) {
         let self = this;
         let {userIndex, roleIndex, checked} = data;
-        let projectUsers = this.projectUsers;
+        let platformUsers = this.platformUsers;
         let selectedRole = self.roles[roleIndex];
+        let keys = ","
         if(checked) {
-            projectUsers[userIndex].role.push({
-                role: self.roles[roleIndex],
-                keys: self.roles[roleIndex]
+            if(!platformUsers[userIndex].role) platformUsers[userIndex].role = [];
+            platformUsers[userIndex].role.push({
+                role: selectedRole,
+                keys: keys
             })
         } else {
-            let role = projectUsers[userIndex].role;
-            let roleIndex = _.findIndex(role, {role:selectedRole, keys: selectedRole})
-            projectUsers[userIndex].role.splice(roleIndex, 1)
+            let role = platformUsers[userIndex].role;
+            let roleIndex = _.findIndex(role, {role:selectedRole, keys: keys})
+            platformUsers[userIndex].role.splice(roleIndex, 1)
         }
-       self.setState({projectUsers});
+       self.setState({platformUsers});
 
     }
     handleUpdateUserRoleInProject(data) {
         let {userIndex, roleIndex, value} = data;
-        let projectUsers = this.projectUsers;
-        projectUsers[userIndex].role[roleIndex].role = value;
-        projectUsers[userIndex].role[roleIndex]['keys'] = value;
+        let platformUsers = this.platformUsers;
+        platformUsers[userIndex].role[roleIndex].role = value;
+        platformUsers[userIndex].role[roleIndex]['keys'] = value;
 
     }
     addRoleToUserInProject(userIndex) {
-        let projectUsers = this.projectUsers;
-        if(!projectUsers[userIndex].role) {
-            projectUsers[userIndex].role = [];
+        let platformUsers = this.platformUsers;
+        if(!platformUsers[userIndex].role) {
+            platformUsers[userIndex].role = [];
         }
-        projectUsers[userIndex].role.push({
+        platformUsers[userIndex].role.push({
               'role': null,
               //temp until we get actual keys
-              'keys' : 'some key'
+              'keys' : ','
             });
         this.setState({
-            projectUsers
+            platformUsers
         })
     }
     handleRemoveRoleFromUserInProject (data) {
         let {userIndex, roleIndex} = data;
-        let projectUsers = this.projectUsers;
-        projectUsers[userIndex].role.splice(roleIndex, 1);
+        let platformUsers = this.platformUsers;
+        platformUsers[userIndex].role.splice(roleIndex, 1);
         this.setState({
-            projectUsers
+            platformUsers
         })
     }
     handleRemoveUserFromProject (userIndex) {
-        let projectUsers = this.projectUsers;
-        projectUsers.splice(userIndex, 1);
+        let platformUsers = this.platformUsers;
+        platformUsers.splice(userIndex, 1);
         this.setState({
-            projectUsers
+            platformUsers
         })
     }
     getProjectsSuccess(projects) {
         this.alt.actions.global.hideScreenLoader.defer();
         this.setState({projects: projects});
     }
-    getUsersSuccess(users) {
+    getPlatformSuccess(platform) {
+        this.alt.actions.global.hideScreenLoader.defer();
+        let platformUsers = platform.user
+        let state = _.merge({
+            platform: platform,
+            projectOpen: true,
+            isEdit: true,
+            isReadOnly: true,
+            platformUsers: platformUsers
+        });
+        this.setState(state)
+    }
+    getPlatformRoleUsersSuccess(users) {
         console.log(users)
         this.alt.actions.global.hideScreenLoader.defer();
         this.setState({users});