X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=skyquake%2Fframework%2Fcore%2Fmodules%2Fapi%2FprojectManagementAPI.js;h=c00de3240af57d80647515221167177f2a4917bc;hb=f10b035a0b8e43fb54d76cdf373aaa7775476416;hp=d73eb215c980cdcf13a69fef3b79d3cac871658b;hpb=9ba0c5e5f242e6e5be9af960f49fc9765b8eb0ed;p=osm%2FUI.git diff --git a/skyquake/framework/core/modules/api/projectManagementAPI.js b/skyquake/framework/core/modules/api/projectManagementAPI.js index d73eb215c..c00de3240 100644 --- a/skyquake/framework/core/modules/api/projectManagementAPI.js +++ b/skyquake/framework/core/modules/api/projectManagementAPI.js @@ -36,7 +36,7 @@ ProjectManagement.get = function(req) { uri: utils.confdPort(api_server) + '/api/operational/project', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -62,6 +62,7 @@ ProjectManagement.get = function(req) { }); }); }; + ProjectManagement.create = function(req) { var self = this; var api_server = req.query['api_server']; @@ -75,7 +76,7 @@ ProjectManagement.create = function(req) { uri: utils.confdPort(api_server) + '/api/config/project', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -115,7 +116,7 @@ ProjectManagement.update = function(req) { uri: utils.confdPort(api_server) + '/api/config/project', method: 'PUT', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -157,7 +158,7 @@ ProjectManagement.delete = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); rp({ url: url, @@ -175,4 +176,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 updateUser = 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(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;