From: Laurence Maultsby Date: Fri, 28 Apr 2017 19:42:20 +0000 (-0400) Subject: cloneDeep on projectUsers to prevent data mutation X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=a719495cecbdffc6c5bbd078f725e3a9b3045b3f;p=osm%2FUI.git cloneDeep on projectUsers to prevent data mutation Signed-off-by: Laurence Maultsby --- diff --git a/skyquake/plugins/project_management/src/dashboard/dashboard.jsx b/skyquake/plugins/project_management/src/dashboard/dashboard.jsx index 843301d03..e9847e5f4 100644 --- a/skyquake/plugins/project_management/src/dashboard/dashboard.jsx +++ b/skyquake/plugins/project_management/src/dashboard/dashboard.jsx @@ -20,7 +20,7 @@ import SelectOption from 'widgets/form_controls/selectOption.jsx'; import 'widgets/form_controls/formControls.scss'; import imgAdd from '../../node_modules/open-iconic/svg/plus.svg' import imgRemove from '../../node_modules/open-iconic/svg/trash.svg' - +import _ from 'lodash'; import ROLES from 'utils/roleConstants.js'; const PROJECT_ROLES = ROLES.PROJECT; const PLATFORM = ROLES.PLATFORM; @@ -118,18 +118,18 @@ class ProjectManagementDashboard extends React.Component { let self = this; e.preventDefault(); e.stopPropagation(); - let projectName = self.state['name']; - let projectUsers = self.state.projectUsers; + let projectName = self.state['name']; + let projectUsers = _.cloneDeep(self.state.projectUsers); let cleanUsers = this.cleanUsers(projectUsers, projectName); - this.Store.updateProject(_.merge({ + this.Store.updateProject({ 'name': projectName, 'description': self.state.description, 'project-config' : { 'user': cleanUsers } - })); + }); } cleanUsers(projectUsers, projectName) { let cleanUsers = []; diff --git a/skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js b/skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js index 70f5f2f61..0c14dd906 100644 --- a/skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js +++ b/skyquake/plugins/project_management/src/dashboard/projectMgmtStore.js @@ -177,23 +177,8 @@ export default class ProjectManagementStore { if (!projectUsers[userIndex].role) { projectUsers[userIndex].role = []; } - if (!projectUsers[userIndex]['rw-project-mano:mano-role']) { - projectUsers[userIndex]['rw-project-mano:mano-role'] = []; - } - switch (ROLES.PROJECT.TYPE[self.roles[roleIndex]]) { - case 'rw-project' : - projectUsers[userIndex].role.push({ - role: selectedRole - }); - break; - case 'rw-project-mano' : - projectUsers[userIndex]["rw-project-mano:mano-role"].push({ - role: selectedRole - }); - break; - } projectUsers[userIndex].role.push({ - role: selectedRole + role: self.roles[roleIndex] }) } else { let role = projectUsers[userIndex].role;