From 76d6ae42bcc1718047241fce2975d92526e51658 Mon Sep 17 00:00:00 2001 From: Sahil-tarento <140611066+Sahil-tarento@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:55:36 +0530 Subject: [PATCH] 4.8.15 dev v1 (#375) * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type (#363) * Updated log details for Parichay login error * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type 1. Added the v5 of the apis for the assessment. * Update proxies_v8.ts * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type 1. FIxed Build fail issue. --------- Co-authored-by: karthik-tarento * Added ui-proxy for interest-capture APIs (#365) * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type (#367) * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type * KB-4705 | DEV| Assessment | BE | Consumption Logic for the QuestionWeightage Assessment Type (#369) * added updateDemandstatus ui-proxy. (#366) * added updateDemandstatus ui-proxy. * added role for updatedemandstatus * Updating roles in demads api * Updateing proxy url * Fix the build issue * changes some role for deamnd API * orgBookmark API addition * second commit for role chnages for demand's API's * orgBookmark update the read and delete API * Added the ui-proxy for playList v2 and CRUD and search for announcement --------- Co-authored-by: tarentomaheshvakkund <139739142+tarentomaheshvakkund@users.noreply.github.com> Co-authored-by: karthik-tarento Co-authored-by: ruksana2808 <111083125+ruksana2808@users.noreply.github.com> Co-authored-by: pathiktarento1089 <123535830+pathiktarento1089@users.noreply.github.com> Co-authored-by: pathiknandi --- src/protectedApi_v8/user/evaluate.ts | 40 +++++- src/proxies_v8/proxies_v8.ts | 28 ++++ src/publicApi_v8/ssoUserHelper.ts | 6 +- src/utils/proxyCreator.ts | 20 +++ src/utils/whitelistApis.ts | 207 ++++++++++++++++++++++++++- 5 files changed, 293 insertions(+), 8 deletions(-) diff --git a/src/protectedApi_v8/user/evaluate.ts b/src/protectedApi_v8/user/evaluate.ts index f5feab71..55ba65b1 100644 --- a/src/protectedApi_v8/user/evaluate.ts +++ b/src/protectedApi_v8/user/evaluate.ts @@ -10,6 +10,7 @@ const API_END_POINTS = { assessmentSubmitV2: `${CONSTANTS.KONG_API_BASE}/v2/user`, assessmentSubmitV3: `${CONSTANTS.KONG_API_BASE}/v3/user`, assessmentSubmitV4: `${CONSTANTS.KONG_API_BASE}/v4/user`, + assessmentSubmitV5: `${CONSTANTS.KONG_API_BASE}/v5/user`, iapSubmitAssessment: `${CONSTANTS.SB_EXT_API_BASE_2}/v3/iap-assessment`, postAssessment: `${CONSTANTS.POST_ASSESSMENT_BASE}/lmsapi/v1/post_assessment`, } @@ -170,5 +171,40 @@ evaluateApi.post('/assessment/submit/v4', async (req, res) => { error: GENERAL_ERR_MSG, } ) - } -}) + }}) + + evaluateApi.post('/assessment/submit/v5', async (req, res) => { + try { + const userId = extractUserIdFromRequest(req) + const url = `${API_END_POINTS.assessmentSubmitV5}/assessment/submit` + const requestBody = { + ...req.body, + } + let rootOrgId = '' + // tslint:disable-next-line + if (typeof req.session != "undefined" && typeof req.session.rootOrgId != "undefined") { + // tslint:disable-next-line + rootOrgId = req.session.rootOrgId + } + const response = await axios({ + ...axiosRequestConfig, + data: requestBody, + headers: { + Authorization: CONSTANTS.SB_API_KEY, + userId, + 'x-authenticated-user-orgid': rootOrgId, + // tslint:disable-next-line: no-duplicate-string + 'x-authenticated-user-token': extractUserToken(req), + }, + method: 'POST', + url, + }) + res.status(response.status).send(response.data) + } catch (error) { + res.status((error && error.response && error.response.status) || 500).send( + (error && error.response && error.response.data) || { + error: GENERAL_ERR_MSG, + } + ) + } + }) diff --git a/src/proxies_v8/proxies_v8.ts b/src/proxies_v8/proxies_v8.ts index 568713eb..9cf90924 100644 --- a/src/proxies_v8/proxies_v8.ts +++ b/src/proxies_v8/proxies_v8.ts @@ -10,6 +10,7 @@ import { ilpProxyCreatorRoute, // proxyCreatorDiscussion, proxyAssessmentRead, + proxyAssessmentReadV2, proxyContent, proxyContentLearnerVM, proxyCreatorForms, @@ -709,6 +710,29 @@ proxiesV8.use('/demand/content/*', proxiesV8.use('/playList/*', proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) ) + +proxiesV8.use('/question/v5/read', + // tslint:disable-next-line: max-line-length + proxyQuestionRead(express.Router(), `${CONSTANTS.KONG_API_BASE}` + '/player/question/v5/list') +) + +proxiesV8.use('/assessment/v5/read/*', + // tslint:disable-next-line: max-line-length + proxyAssessmentReadV2(express.Router(), `${CONSTANTS.KONG_API_BASE}` + '/player/questionset/v5/hierarchy') +) + +proxiesV8.use('/interest/*', + proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) +) + +proxiesV8.use('/assessment/save/', + proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) +) + +proxiesV8.use('/announcements/*', + proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) +) + function removePrefix(prefix: string, s: string) { return s.substr(prefix.length) } @@ -909,6 +933,10 @@ proxiesV8.use('/careers/*', proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) ) +proxiesV8.use('/orgBookmark/*', + proxyCreatorSunbird(express.Router(), `${CONSTANTS.KONG_API_BASE}`) +) + export interface IUserProfile { channel: string firstName: string diff --git a/src/publicApi_v8/ssoUserHelper.ts b/src/publicApi_v8/ssoUserHelper.ts index 14307456..313a2ad7 100644 --- a/src/publicApi_v8/ssoUserHelper.ts +++ b/src/publicApi_v8/ssoUserHelper.ts @@ -140,13 +140,13 @@ export async function updateKeycloakSession(emailId: string, req: any, res: any) keycloakClient.authenticated(req, (error: any) => { logInfo('ssoUserHelper::keycloakClient::authenticated..') if (error) { - logError('googleauthhelper:createSession error creating session') - result.errMessage = 'GOOGLE_CREATE_SESSION_FAILED' + logError('ssoUserHelper:: keycloak.authenticate failed Email: ' + emailId + ', Error: ' + JSON.stringify(error)) + result.errMessage = 'FAILED_TO_CREATE_KEYCLOAK_SESSION' } }) return Promise.resolve(result) } catch (err) { - logError('googleOauthHelper: createSession failed. Error: ' + JSON.stringify(err)) + logError('ssoUserHelper: createSession failed for Email: ' + emailId + ', Error: ' + JSON.stringify(err)) result.errMessage = 'FAILED_TO_CREATE_KEYCLOAK_SESSION' } return Promise.resolve(result) diff --git a/src/utils/proxyCreator.ts b/src/utils/proxyCreator.ts index 18e54cf1..4bb54eb3 100644 --- a/src/utils/proxyCreator.ts +++ b/src/utils/proxyCreator.ts @@ -364,3 +364,23 @@ export function proxyCreatorForms(route: Router, _timeout = 10000): Router { }) return route } + +export function proxyAssessmentReadV2(route: Router, targetUrl: string, _timeout = 10000): Router { + route.all('/*', (req, res) => { + let url = removePrefix(`${PROXY_SLUG}/assessment/v5/read`, req.originalUrl) + // Check if the target URL already contains query parameters + if (url.includes('?')) { + url = targetUrl + url + '&hierarchy=detail' + } else { + url = targetUrl + url + '?hierarchy=detail' + } + // tslint:disable-next-line: no-console + console.log('REQ_URL_UPDATED proxyAssessmentReadV5', url) + proxy.web(req, res, { + changeOrigin: true, + ignorePath: true, + target: url, + }) + }) + return route +} diff --git a/src/utils/whitelistApis.ts b/src/utils/whitelistApis.ts index 45eb691b..06b06cde 100644 --- a/src/utils/whitelistApis.ts +++ b/src/utils/whitelistApis.ts @@ -3142,7 +3142,9 @@ export const API_LIST = { checksNeeded: [CHECK.ROLE], // tslint:disable-next-line: object-literal-sort-keys ROLE_CHECK: [ - ROLE.PUBLIC, + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, ], }, '/proxies/v8/demand/content/read/:do_id': { @@ -3156,14 +3158,15 @@ export const API_LIST = { checksNeeded: [CHECK.ROLE], // tslint:disable-next-line: object-literal-sort-keys ROLE_CHECK: [ - ROLE.PUBLIC, + ROLE.MDO_ADMIN, + ROLE.SPV_ADMIN, ], }, '/proxies/v8/demand/content/search': { checksNeeded: [CHECK.ROLE], // tslint:disable-next-line: object-literal-sort-keys ROLE_CHECK: [ - ROLE.PUBLIC, + ROLE.PUBLIC, ], }, '/proxies/v8/playList/create': { @@ -3203,6 +3206,181 @@ export const API_LIST = { ROLE.SPV_PUBLISHER, ], }, + '/proxies/v8/user/assessment/v5/result': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/user/assessment/v5/retake/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/protected/v8/user/evaluate/assessment/submit/v5': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/assessment/v5/read/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/question/v5/read': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/interest/v1/create': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.CBP_ADMIN, + ROLE.CONTENT_CREATOR, + ], + }, + '/proxies/v8/interest/v1/search': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/interest/v1/assign': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/interest/v1/read/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/assessment/save': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/demand/content/v1/update/status': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/orgBookmark/v1/create': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/orgBookmark/v1/update': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/orgBookmark/v1/search': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/orgBookmark/v1/read/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/orgBookmark/v1/delete/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/playList/v2/search': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/playList/read/:id/:orgId': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/announcements/v1/create': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/announcements/v1/update': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_ADMIN, + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, + '/proxies/v8/announcements/v1/search': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/announcements/v1/read/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.PUBLIC, + ], + }, + '/proxies/v8/announcements/v1/delete/:id': { + checksNeeded: [CHECK.ROLE], + // tslint:disable-next-line: object-literal-sort-keys + ROLE_CHECK: [ + ROLE.MDO_LEADER, + ROLE.SPV_ADMIN, + ], + }, }, URL_PATTERN: [ @@ -3613,5 +3791,28 @@ export const API_LIST = { '/proxies/v8/playList/update', '/proxies/v8/playList/search', '/proxies/v8/playList/delete/:do_id', + '/proxies/v8/user/assessment/v5/result', + '/proxies/v8/user/assessment/v5/retake/:id', + '/protected/v8/user/evaluate/assessment/submit/v5', + '/proxies/v8/assessment/v5/read/:id', + '/proxies/v8/question/v5/read', + '/proxies/v8/interest/v1/create', + '/proxies/v8/interest/v1/search', + '/proxies/v8/interest/v1/assign', + '/proxies/v8/interest/v1/read/:id', + '/proxies/v8/assessment/save', + '/proxies/v8/demand/content/v1/update/status', + '/proxies/v8/orgBookmark/v1/create', + '/proxies/v8/orgBookmark/v1/update', + '/proxies/v8/orgBookmark/v1/search', + '/proxies/v8/orgBookmark/v1/read/:id', + '/proxies/v8/orgBookmark/v1/delete/:id', + '/proxies/v8/playList/v2/search', + '/proxies/v8/playList/read/:id/:orgId', + '/proxies/v8/announcements/v1/create', + '/proxies/v8/announcements/v1/update', + '/proxies/v8/announcements/v1/search', + '/proxies/v8/announcements/v1/read/:id', + '/proxies/v8/announcements/v1/delete/:id', ], }