PlatformRoleManagement: removing current user from payload, as user can not edit...
authorLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 25 Apr 2017 17:00:12 +0000 (13:00 -0400)
committerLaurence Maultsby <laurence.maultsby@riftio.com>
Tue, 25 Apr 2017 17:00:12 +0000 (13:00 -0400)
Signed-off-by: Laurence Maultsby <laurence.maultsby@riftio.com>
skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js
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 f0a8eeb..b3e55ad 100644 (file)
@@ -79,9 +79,7 @@ export default class ProjectManagementStore {
     }
     editProject(isReadOnly) {
         this.viewProject([this.projects[this.activeIndex], this.activeIndex, isReadOnly]);
-        // this.setState({
-        //     isReadOnly: isEdit
-        // })
+
     }
     handleCloseProjectPanel() {
         this.setState({
index de5064b..216bea8 100644 (file)
@@ -53,58 +53,35 @@ class PlatformRoleManagement extends React.Component {
     platformChange = (platformRole, e) => {
         this.actions.handlePlatformRoleUpdate(platformRole, e.currentTarget.checked);
     }
-    addProjectRole = (e) => {
-        this.actions.handleAddProjectItem();
-    }
-    removeProjectRole = (i, e) => {
-        this.actions.handleRemoveProjectItem(i);
-    }
-    updateProjectRole = (i, e) => {
-        this.actions.handleUpdateProjectRole(i, e)
-    }
-    addProject = () => {
-        this.actions.handleAddProject();
-    }
-    viewProject = (un, index) => {
-        this.actions.viewProject(un, index);
-    }
     editProject = () => {
-        this.actions.editProject(false);
+        this.actions.editPlatform(false);
     }
-    cancelEditProject = () => {
-        this.actions.editProject(true)
+    cancelEditPlatform = () => {
+        this.actions.editPlatform(true)
     }
     closePanel = () => {
         this.actions.handleCloseProjectPanel();
     }
-
-    deleteProject = (e) => {
-        e.preventDefault();
-        e.stopPropagation();
-        this.Store.deleteProject({
-                'name': this.state['name']
-            });
-    }
     updatePlatform = (e) => {
         let self = this;
         e.preventDefault();
         e.stopPropagation();
         let platformUsers = self.state.platformUsers;
         let cleanUsers = this.cleanUsers(platformUsers);
-
-
         this.Store.updatePlatform({
-                'user': JSON.stringify(platformUsers)
+                'user': JSON.stringify(cleanUsers)
             }
         );
     }
-     cleanUsers(projectUsers) {
+     cleanUsers(platformUsers) {
+        let self = this;
         let cleanUsers = [];
         //Remove null values from role
-        projectUsers.map((u) => {
+        platformUsers.map((u) => {
             let cleanRoles = [];
             u.role && u.role.map((r,i) => {
                 let role = {};
+                //Platform user can not change role of itself.
                 if(r.role){
                     //removing key for rbac-platform
                     delete r.keys;
@@ -112,7 +89,9 @@ class PlatformRoleManagement extends React.Component {
                 }
             });
            u.role = cleanRoles;
-           cleanUsers.push(u);
+           if (u['user-name'] != self.context.userProfile.userId) {
+                cleanUsers.push(u);
+           }
         });
         return cleanUsers;
     }
@@ -195,8 +174,7 @@ class PlatformRoleManagement extends React.Component {
                                 (
                                     <ButtonGroup className="buttonGroup">
                                         <Button label="Update" type="submit" onClick={this.updatePlatform} />
-                                        <Button label="Delete" onClick={this.deleteProject} />
-                                        <Button label="Cancel" onClick={this.cancelEditProject} />
+                                        <Button label="Cancel" onClick={this.cancelEditPlatform} />
                                     </ButtonGroup>
                                 )
                                 : (
@@ -298,7 +276,8 @@ class PlatformRoleManagement extends React.Component {
 }
 // onClick={this.Store.update.bind(null, Account)}
 PlatformRoleManagement.contextTypes = {
-    router: React.PropTypes.object
+    router: React.PropTypes.object,
+    userProfile: React.PropTypes.object
 };
 
 PlatformRoleManagement.defaultProps = {
index 6ef5720..95bfd3f 100644 (file)
@@ -8,7 +8,8 @@ module.exports = function(Alt) {
                                        'handleRemoveProjectItem',
                                        'handleUpdateProjectRole',
                                        'viewProject',
-                                       'editProject',
+                                       'editPlatform',
+                                       'handleCancelEdit',
                                        'handleCloseProjectPanel',
                                        'handleHideColumns',
                                        'handleSelectedUser',
@@ -29,7 +30,7 @@ module.exports = function(Alt) {
                                        'handleToggleUserRoleInProject',
                                        'addRoleToUserInProject',
                                        'handleRemoveRoleFromUserInProject',
-                                       'updateProjectSuccess',
+                                       'updatePlatformSuccess',
                                        'createProjectSuccess',
                                        'deleteProjectSuccess'
                                        );
index 724312e..0a0d4c3 100644 (file)
@@ -99,67 +99,9 @@ module.exports = function(Alt) {
           interceptResponse: interceptResponse({
             'error': 'There was an error updating the project.'
           }),
-          success: Alt.actions.global.updateProjectSuccess,
+          success: Alt.actions.global.updatePlatformSuccess,
           loading: Alt.actions.global.showScreenLoader,
           error: Alt.actions.global.showNotification
-        },
-        deleteProject: {
-          remote: function(state, project) {
-            return new Promise(function(resolve, reject) {
-              $.ajax({
-                url: `/project/${project['name']}?api_server=${API_SERVER}`,
-                type: 'DELETE',
-                beforeSend: Utils.addAuthorizationStub,
-                success: function(data, textStatus, jqXHR) {
-                  resolve(data);
-                }
-              }).fail(function(xhr){
-                //Authentication and the handling of fail states should be wrapped up into a connection class.
-                Utils.checkAuthentication(xhr.status);
-                let msg = xhr.responseText;
-                  if(xhr.errorMessage) {
-                    msg = xhr.errorMessage
-                  }
-                  reject(msg);
-              });
-            });
-          },
-          interceptResponse: interceptResponse({
-            'error': 'There was an error deleting the user.'
-          }),
-          success: Alt.actions.global.deleteProjectSuccess,
-          loading: Alt.actions.global.showScreenLoader,
-          error: Alt.actions.global.showNotification
-        },
-        createProject: {
-            remote: function(state, project) {
-
-              return new Promise(function(resolve, reject) {
-                $.ajax({
-                  url: `/project?api_server=${API_SERVER}`,
-                  type: 'POST',
-                  data: project,
-                  beforeSend: Utils.addAuthorizationStub,
-                  success: function(data, textStatus, jqXHR) {
-                    resolve(data);
-                  }
-                }).fail(function(xhr){
-                  //Authentication and the handling of fail states should be wrapped up into a connection class.
-                  Utils.checkAuthentication(xhr.status);
-                  let msg = xhr.responseText;
-                  if(xhr.errorMessage) {
-                    msg = xhr.errorMessage
-                  }
-                  reject(msg);
-                });
-              });
-            },
-            interceptResponse: interceptResponse({
-              'error': 'There was an error updating the account.'
-            }),
-            success: Alt.actions.global.createProjectSuccess,
-            loading: Alt.actions.global.showScreenLoader,
-            error: Alt.actions.global.showNotification
         }
       }
 }
index ef03b9d..dd8704d 100644 (file)
@@ -56,27 +56,20 @@ export default class PlatformRoleManagementStore {
             projectRoles
         });
     }
-    viewProject(data) {
-        let project = data[0];
-        let projectIndex = data[1];
-
-        let ProjectUser = {
-            'name': project['name'],
-            'description': project['description'],
-            'platformUsers': project['project-config'] && project['project-config']['user'] || []
-        }
+    editPlatform(isReadOnly) {
         let state = _.merge({
-            activeIndex: projectIndex,
-            projectOpen: true,
             isEdit: true,
-            isReadOnly: true
-        }, ProjectUser);
+            isReadOnly: isReadOnly,
+        }, {
+            'platformUsers': this.cachedUsers
+        });
         this.setState(state)
     }
-    editProject(isEdit) {
-        this.setState({
-            isReadOnly: isEdit
-        })
+    // editPlatform(isReadOnly) {
+    //     this.platformEdit(isReadOnly);
+    // }
+    handleCancelEdit() {
+
     }
     handleCloseProjectPanel() {
         this.setState({
@@ -223,7 +216,8 @@ export default class PlatformRoleManagementStore {
             projectOpen: true,
             isEdit: true,
             isReadOnly: true,
-            platformUsers: platformUsers
+            platformUsers: platformUsers,
+            cachedUsers: platformUsers
         });
         this.setState(state)
     }
@@ -232,15 +226,12 @@ export default class PlatformRoleManagementStore {
         this.alt.actions.global.hideScreenLoader.defer();
         this.setState({users});
     }
-    updateProjectSuccess() {
+    updatePlatformSuccess() {
         this.alt.actions.global.hideScreenLoader.defer();
-        let projects = this.projects || [];
-        projects[this.activeIndex] = {
-            'name': this['name'],
-            'description': this['description']
-        }
+        let platformUsers = this.platformUsers;
         this.setState({
-            projects,
+            platformUsers,
+            cachedUsers: platformUsers,
             isEdit: true,
             isReadOnly: true
         })