});
});
};
+
ProjectManagement.create = function(req) {
var self = this;
var api_server = req.query['api_server'];
});
})
}
+
+
+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;
});
});
+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;
"label": "Platform Role Management",
"route": "platform",
"component": "./platformRoleManagement/platformRoleManagement.jsx",
- "type": "internal"
+ "type": "external"
}]
}
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;
}
componentWillMount() {
this.Store.listen(this.updateState);
+ this.Store.getUsers();
}
componentWillUnmount() {
this.Store.unlisten(this.updateState);
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';
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);
'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();
<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) {
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>
)
)
</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
}
</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">
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'],
'handleAddUser',
'handleRemoveUserFromProject',
'getProjectsSuccess',
- 'getUsersSuccess',
+ 'getPlatformSuccess',
+ 'getPlatformRoleUsersSuccess',
'getProjectsNotification',
'handleDisabledChange',
'handlePlatformRoleUpdate',
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.
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,
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 = [];
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,
projectOpen: true,
activeIndex: null,
isReadOnly: false,
- projectUsers: []
+ platformUsers: []
}
))
}
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});