}
editProject(isReadOnly) {
this.viewProject([this.projects[this.activeIndex], this.activeIndex, isReadOnly]);
- // this.setState({
- // isReadOnly: isEdit
- // })
+
}
handleCloseProjectPanel() {
this.setState({
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;
}
});
u.role = cleanRoles;
- cleanUsers.push(u);
+ if (u['user-name'] != self.context.userProfile.userId) {
+ cleanUsers.push(u);
+ }
});
return cleanUsers;
}
(
<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>
)
: (
}
// onClick={this.Store.update.bind(null, Account)}
PlatformRoleManagement.contextTypes = {
- router: React.PropTypes.object
+ router: React.PropTypes.object,
+ userProfile: React.PropTypes.object
};
PlatformRoleManagement.defaultProps = {
'handleRemoveProjectItem',
'handleUpdateProjectRole',
'viewProject',
- 'editProject',
+ 'editPlatform',
+ 'handleCancelEdit',
'handleCloseProjectPanel',
'handleHideColumns',
'handleSelectedUser',
'handleToggleUserRoleInProject',
'addRoleToUserInProject',
'handleRemoveRoleFromUserInProject',
- 'updateProjectSuccess',
+ 'updatePlatformSuccess',
'createProjectSuccess',
'deleteProjectSuccess'
);
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
}
}
}
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({
projectOpen: true,
isEdit: true,
isReadOnly: true,
- platformUsers: platformUsers
+ platformUsers: platformUsers,
+ cachedUsers: platformUsers
});
this.setState(state)
}
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
})