X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fcore%2Fmodules%2Fapi%2FprojectManagementAPI.js;h=195f45700d315797c6de5fb2c5fa3f829b2c3299;hb=08e8a038f222c66ce6f55760a766e90b87b3c50b;hp=8eace6b29e6f80f8bd7913038ef1034b127e83cb;hpb=5a83ca0dc3306b54e1db18b9e05e860fed21324e;p=osm%2FUI.git diff --git a/skyquake/framework/core/modules/api/projectManagementAPI.js b/skyquake/framework/core/modules/api/projectManagementAPI.js index 8eace6b29..195f45700 100644 --- a/skyquake/framework/core/modules/api/projectManagementAPI.js +++ b/skyquake/framework/core/modules/api/projectManagementAPI.js @@ -62,6 +62,7 @@ ProjectManagement.get = function(req) { }); }); }; + ProjectManagement.create = function(req) { var self = this; var api_server = req.query['api_server']; @@ -103,16 +104,21 @@ ProjectManagement.create = function(req) { }); }; ProjectManagement.update = function(req) { + //"rw-project:project" var self = this; var api_server = req.query['api_server']; var bodyData = req.body; - data = { - "project":[bodyData] + var data = { + "rw-project:project" : { + "name": bodyData.name, + "description": bodyData.description, + "project-config": bodyData['project-config'] + } } var updateTasks = []; - var updateUser = rp({ - uri: utils.confdPort(api_server) + '/api/config/project', + var updateProject= rp({ + uri: utils.confdPort(api_server) + '/api/config/project/', method: 'PUT', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { 'Authorization': req.session && req.session.authorization @@ -122,7 +128,7 @@ ProjectManagement.update = function(req) { rejectUnauthorized: false, resolveWithFullResponse: true }); - updateTasks.push(updateUser) + updateTasks.push(updateProject) return new Promise(function(resolve, reject) { Promise.all([ updateTasks @@ -175,4 +181,96 @@ ProjectManagement.delete = function(req) { }); }) } + + +ProjectManagement.getPlatform = function(req, userId) { + var self = this; + var api_server = req.query['api_server']; + var user = req.params['userId'] || userId; + return new Promise(function(resolve, reject) { + var url = utils.confdPort(api_server) + '/api/operational/rbac-platform-config'; + if(user) { + url = url + '/user/' + user; + } + Promise.all([ + rp({ + uri: url, + method: 'GET', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.session && req.session.authorization + }), + forever: constants.FOREVER_ON, + rejectUnauthorized: false, + resolveWithFullResponse: true + }) + ]).then(function(result) { + var response = {}; + response['data'] = {}; + if (result[0].body) { + if(user) { + response['data']['platform'] = JSON.parse(result[0].body)['rw-rbac-platform:user']; + } else { + 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; + data.user = JSON.parse(data.user) + var updateTasks = []; + + var updatePlatform = rp({ + uri: utils.confdPort(api_server) + '/api/config/rbac-platform-config', + method: 'PUT', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.session && req.session.authorization + }), + forever: constants.FOREVER_ON, + json: data, + rejectUnauthorized: false, + resolveWithFullResponse: true + }); + updateTasks.push(updatePlatform) + 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;