Skip to content

Commit

Permalink
Issue #7254 merge: Merge pull request #7254 from samagra-comms/releas…
Browse files Browse the repository at this point in the history
…e-4.3.0-hc

Fix - UCI Base URL
  • Loading branch information
vinukumar-vs authored Sep 24, 2021
2 parents d928088 + b4f35ba commit 62a5c6e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ src/desktop/openrap-sunbirded-plugin/data/frameworks
src/desktop/openrap-sunbirded-plugin/data
src/desktop/telemetry_archived
src/desktop/node_modules
src/desktop/chromedriverlog.txt
src/desktop/chromedriverlog.txt

.prettierignore
1 change: 1 addition & 0 deletions src/app/helpers/environmentVariablesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let envVariables = {

// discussion forum
discussions_middleware: env.discussions_middleware || 'http://discussionsmw-service:3002',
uci_service_base_url: env.uci_service_base_url || "http://uci-service:9999",

// Application Start-up - Hosts and PORT Configuration
PORTAL_PORT: env.sunbird_port || 3000,
Expand Down
85 changes: 83 additions & 2 deletions src/app/helpers/whitelistApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,7 +1759,72 @@ const API_LIST = {
'/v1/user-extension/solutions': {
checksNeeded: ['ROLE_CHECK'],
ROLE_CHECK: [ROLE.PROGRAM_MANAGER, ROLE.PROGRAM_DESIGNER]
}
},
// UCI Related APIs
"/uci/admin/v1/bot/get": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/search": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/pause/:botId": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/start/:botId": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/delete/:botId": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/getByParam": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/create": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/bot/update/:id": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/userSegment/get": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/userSegment/search": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/userSegment/create": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/userSegment/queryBuilder": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/conversationLogic/create": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/conversationLogic/update/:id": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/conversationLogic/delete/:id": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
"/uci/admin/v1/forms/upload": {
checksNeeded: ["ROLE_CHECK"],
ROLE_CHECK: [ROLE.ORG_ADMIN],
},
},
URL_PATTERN: [
'/learner/user/v1/feed/delete',
Expand Down Expand Up @@ -1878,7 +1943,23 @@ const API_LIST = {
'/assessment/observations/mlsurvey/v1/updateEntities/:id',
'/assessment/observationSubmissions/mlsurvey/v1/update/:id',
'/action/collection/v1/import/:id',
'/action/collection/v1/export/:id'
'/action/collection/v1/export/:id',
'/uci/admin/v1/bot/get',
'/uci/admin/v1/bot/search',
'/uci/admin/v1/bot/pause/:botId',
'/uci/admin/v1/bot/start/:botId',
'/uci/admin/v1/bot/delete/:botId',
'/uci/admin/v1/bot/getByParam',
'/uci/admin/v1/bot/create',
'/uci/admin/v1/bot/update/:id',
'/uci/admin/v1/userSegment/get',
'/uci/admin/v1/userSegment/search',
'/uci/admin/v1/userSegment/create',
'/uci/admin/v1/userSegment/queryBuilder',
'/uci/admin/v1/conversationLogic/create',
'/uci/admin/v1/conversationLogic/update/:id',
'/uci/admin/v1/conversationLogic/delete/:id',
'/uci/admin/v1/forms/upload',
]
};
module.exports = API_LIST;
12 changes: 5 additions & 7 deletions src/app/routes/uci.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const proxyUtils = require('../proxy/proxyUtils.js');
const BASE_REPORT_URL = "/admin";
const proxy = require('express-http-proxy');
const { discussions_middleware } = require('../helpers/environmentVariablesHelper.js');
const { uci_service_base_url } = require('../helpers/environmentVariablesHelper.js');
const jwt = require('jsonwebtoken');
const _ = require('lodash')
const bodyParser = require('body-parser');
Expand Down Expand Up @@ -37,23 +37,21 @@ module.exports = function (app) {

function addHeaders() {
return function (proxyReqOpts, srcReq) {
// let decoratedHeaders = proxyUtils.decorateRequestHeaders(discussions_middleware)()
proxyReqOpts.headers['Authorization'] = 'Bearer ' + srcReq.session['nodebb_authorization_token'];
return proxyReqOpts;
return proxyUtils.decorateRequestHeaders(uci_service_base_url)()
}
}

function proxyObject() {
return proxy(discussions_middleware, {
return proxy(uci_service_base_url, {
proxyReqOptDecorator: addHeaders(),
proxyReqPathResolver: function (req) {
let urlParam = req.originalUrl;
console.log("Request comming from :", urlParam)
let query = require('url').parse(req.url).query;
if (query) {
return require('url').parse(discussions_middleware + urlParam + '?' + query).path
return require('url').parse(uci_service_base_url + urlParam + '?' + query).path
} else {
return require('url').parse(discussions_middleware + urlParam).path
return require('url').parse(uci_service_base_url + urlParam).path
}
},
userResDecorator: (proxyRes, proxyResData, req, res) => {
Expand Down

0 comments on commit 62a5c6e

Please sign in to comment.