From 48a7533056e28c4a16b45e51a04e2cb32fdf3def Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 23 Mar 2023 17:03:35 +0530 Subject: [PATCH 01/10] fixed non targeted to targeted project issue --- module/userProjects/helper.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 2283a2f..665ce21 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1069,10 +1069,16 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - + const userRoleInformations = userRoleInformation.role.split(",") + userRoleInformations.push() const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, - userId: userId + userId: userId, + userRole:{ + $regex: userRoleInformations.join("|"), + $options: "i" + }, + "userRoleInformation.state": userRoleInformation.state }, ["_id"]); if( projectDetails.length > 0 ) { From 947561874c4f3bb9180cb44e310753670ff569f1 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 24 Mar 2023 18:53:22 +0530 Subject: [PATCH 02/10] added integrated api to check solution is targeted or not --- generics/constants/endpoints.js | 3 +- generics/services/core.js | 54 ++++++++++++++++++++++++++++++++- module/userProjects/helper.js | 11 +++---- 3 files changed, 59 insertions(+), 9 deletions(-) diff --git a/generics/constants/endpoints.js b/generics/constants/endpoints.js index c8a5bfa..3fbded5 100644 --- a/generics/constants/endpoints.js +++ b/generics/constants/endpoints.js @@ -51,5 +51,6 @@ module.exports = { CERTIFICATE_CREATE : "/api/v1/ProjectCertificate", PROJECT_CERTIFICATE_API_CALLBACK : "/v1/userProjects/certificateCallback", USER_READ_PRIVATE : "/private/user/v1/read", // !Caution: End point for reading user details without token. Do not use for public work flow - GET_CERTIFICATE_KID : "/api/v1/PublicKey/search" + GET_CERTIFICATE_KID : "/api/v1/PublicKey/search", + VERIFY_TARGETED_SOLUTION : "/v1/solutions/verfiySolution", }; diff --git a/generics/services/core.js b/generics/services/core.js index ec12900..a77d020 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -725,6 +725,57 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution }) } + +const verifyTargetedSolution = function ( token,bodyData,solutionId ) { + return new Promise(async (resolve, reject) => { + try { + + const url = + ML_CORE_URL + CONSTANTS.endpoints.VERIFY_TARGETED_SOLUTION + "/" + solutionId; + + const options = { + headers : { + "content-type": "application/json", + "internal-access-token": process.env.INTERNAL_ACCESS_TOKEN, + "x-authenticated-user-token" : token + }, + json : bodyData + }; + + request.post(url,options,varifyTergetedSolutionCallbeck); + + function varifyTergetedSolutionCallbeck(err, data) { + + let result = { + success : true + }; + + if (err) { + result.success = false; + } else { + + let response = data.body; + if( response.status === HTTP_STATUS_CODE['ok'].status ) { + result["data"] = response.result; + } else { + result.success = false; + } + } + + return resolve(result); + } + + } catch (error) { + return reject(error); + } + }) +} + + + + + + module.exports = { entityTypesDocuments : entityTypesDocuments, rolesDocuments : rolesDocuments, @@ -738,6 +789,7 @@ module.exports = { createSolution: createSolution, solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation, solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation, - getDownloadableUrl : getDownloadableUrl + getDownloadableUrl : getDownloadableUrl, + verifyTargetedSolution:verifyTargetedSolution }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 665ce21..fbb6f21 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1069,16 +1069,13 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - const userRoleInformations = userRoleInformation.role.split(",") - userRoleInformations.push() + + const targetedSolutionId = await coreService.verifyTargetedSolution(userToken,bodyData,solutionId) + const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, userId: userId, - userRole:{ - $regex: userRoleInformations.join("|"), - $options: "i" - }, - "userRoleInformation.state": userRoleInformation.state + isAPrivateProgram: targetedSolutionId.data.isATargetedSolution ? false : true }, ["_id"]); if( projectDetails.length > 0 ) { From 0518231629e61f2cc73ebd83e6d8b6041f428a0d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 24 Mar 2023 18:54:29 +0530 Subject: [PATCH 03/10] added integrated api to check solution is targeted or not --- generics/services/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generics/services/core.js b/generics/services/core.js index a77d020..1f96019 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -742,9 +742,9 @@ const verifyTargetedSolution = function ( token,bodyData,solutionId ) { json : bodyData }; - request.post(url,options,varifyTergetedSolutionCallbeck); + request.post(url,options,verifyTergetedSolutionCallbeck); - function varifyTergetedSolutionCallbeck(err, data) { + function verifyTergetedSolutionCallbeck(err, data) { let result = { success : true From 7a5d78ddb254ff73cdb6d28a00db0c41dd54da4d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 24 Mar 2023 19:09:41 +0530 Subject: [PATCH 04/10] added integrated api to check solution is targeted or not --- generics/constants/endpoints.js | 2 +- generics/services/core.js | 6 +++--- module/userProjects/helper.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/generics/constants/endpoints.js b/generics/constants/endpoints.js index 3fbded5..bec01de 100644 --- a/generics/constants/endpoints.js +++ b/generics/constants/endpoints.js @@ -52,5 +52,5 @@ module.exports = { PROJECT_CERTIFICATE_API_CALLBACK : "/v1/userProjects/certificateCallback", USER_READ_PRIVATE : "/private/user/v1/read", // !Caution: End point for reading user details without token. Do not use for public work flow GET_CERTIFICATE_KID : "/api/v1/PublicKey/search", - VERIFY_TARGETED_SOLUTION : "/v1/solutions/verfiySolution", + IS_TARGETED_BASED_ON_USER_PROFILE : "/v1/solutions/isTargetedBasedOnUserProfile", }; diff --git a/generics/services/core.js b/generics/services/core.js index 1f96019..65c7226 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -726,12 +726,12 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution } -const verifyTargetedSolution = function ( token,bodyData,solutionId ) { +const isTargetedBasedOnUserProfile = function ( token,bodyData,solutionId ) { return new Promise(async (resolve, reject) => { try { const url = - ML_CORE_URL + CONSTANTS.endpoints.VERIFY_TARGETED_SOLUTION + "/" + solutionId; + ML_CORE_URL + CONSTANTS.endpoints.IS_TARGETED_BASED_ON_USER_PROFILE + "/" + solutionId; const options = { headers : { @@ -790,6 +790,6 @@ module.exports = { solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation, solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation, getDownloadableUrl : getDownloadableUrl, - verifyTargetedSolution:verifyTargetedSolution + isTargetedBasedOnUserProfile:isTargetedBasedOnUserProfile }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index fbb6f21..c22bbaa 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1070,7 +1070,7 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - const targetedSolutionId = await coreService.verifyTargetedSolution(userToken,bodyData,solutionId) + const targetedSolutionId = await coreService.isTargetedBasedOnUserProfile(userToken,bodyData,solutionId) const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, From 43787723f9a8c83f067e7401cd4dd55b7fb24a6c Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 24 Mar 2023 19:17:50 +0530 Subject: [PATCH 05/10] added integrated api to check solution is targeted or not --- generics/services/core.js | 4 ++-- module/userProjects/helper.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/generics/services/core.js b/generics/services/core.js index 65c7226..8edf078 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -742,9 +742,9 @@ const isTargetedBasedOnUserProfile = function ( token,bodyData,solutionId ) { json : bodyData }; - request.post(url,options,verifyTergetedSolutionCallbeck); + request.post(url,options,verifyTargetedSolutionCallbeck); - function verifyTergetedSolutionCallbeck(err, data) { + function verifyTargetedSolutionCallbeck(err, data) { let result = { success : true diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index c22bbaa..99ae764 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1069,9 +1069,9 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - + // This is used to check solution is targetted or not const targetedSolutionId = await coreService.isTargetedBasedOnUserProfile(userToken,bodyData,solutionId) - + //based on above api will check for projects wether its is private project or public project const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, userId: userId, From d697df9bde5024047f3ff636e0794e315b1a72d8 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 24 Mar 2023 19:19:40 +0530 Subject: [PATCH 06/10] added integrated api to check solution is targeted or not --- generics/services/core.js | 4 ++-- module/userProjects/helper.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generics/services/core.js b/generics/services/core.js index 8edf078..b4a1e24 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -726,7 +726,7 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution } -const isTargetedBasedOnUserProfile = function ( token,bodyData,solutionId ) { +const checkIfSolutionIsTargetedForUserProfile = function ( token,bodyData,solutionId ) { return new Promise(async (resolve, reject) => { try { @@ -790,6 +790,6 @@ module.exports = { solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation, solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation, getDownloadableUrl : getDownloadableUrl, - isTargetedBasedOnUserProfile:isTargetedBasedOnUserProfile + checkIfSolutionIsTargetedForUserProfile:checkIfSolutionIsTargetedForUserProfile }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 99ae764..4cef506 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1070,7 +1070,7 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { // This is used to check solution is targetted or not - const targetedSolutionId = await coreService.isTargetedBasedOnUserProfile(userToken,bodyData,solutionId) + const targetedSolutionId = await coreService.checkIfSolutionIsTargetedForUserProfile(userToken,bodyData,solutionId) //based on above api will check for projects wether its is private project or public project const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, From df010cbcdfd27b415d7250d7aa1834faebbdfc4b Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 27 Mar 2023 14:01:01 +0530 Subject: [PATCH 07/10] fixed code --- generics/services/core.js | 4 ++-- module/userProjects/helper.js | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/generics/services/core.js b/generics/services/core.js index b4a1e24..8a1ace5 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -742,9 +742,9 @@ const checkIfSolutionIsTargetedForUserProfile = function ( token,bodyData,soluti json : bodyData }; - request.post(url,options,verifyTargetedSolutionCallbeck); + request.post(url,options,verifyTargetedSolutionCallback); - function verifyTargetedSolutionCallbeck(err, data) { + function verifyTargetedSolutionCallback(err, data) { let result = { success : true diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 4cef506..090b503 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1071,12 +1071,18 @@ module.exports = class UserProjectsHelper { if (projectId === "") { // This is used to check solution is targetted or not const targetedSolutionId = await coreService.checkIfSolutionIsTargetedForUserProfile(userToken,bodyData,solutionId) - //based on above api will check for projects wether its is private project or public project - const projectDetails = await projectQueries.projectDocument({ + + let projectDocumentQuery = { solutionId: solutionId, userId: userId, - isAPrivateProgram: targetedSolutionId.data.isATargetedSolution ? false : true - }, ["_id"]); + } + + if(targetedSolutionId.data.isATargetedSolution){ + projectDocumentQuery.isAPrivateProgram = false + } + //based on above api will check for projects wether its is private project or public project + const projectDetails = await projectQueries.projectDocument(projectDocumentQuery, ["_id"]); + if( projectDetails.length > 0 ) { projectId = projectDetails[0]._id; From 52e557331005434ce64c0ffd150dae80acc68e2f Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 28 Mar 2023 02:23:59 +0530 Subject: [PATCH 08/10] Fixed Public and private project for solution --- controllers/v1/project/templates.js | 3 ++- module/project/templates/helper.js | 5 +++-- module/userProjects/helper.js | 17 +++++------------ 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/controllers/v1/project/templates.js b/controllers/v1/project/templates.js index 486ad6c..1cc19f7 100644 --- a/controllers/v1/project/templates.js +++ b/controllers/v1/project/templates.js @@ -680,7 +680,8 @@ module.exports = class ProjectTemplates extends Abstract { await projectTemplatesHelper.details( req.params._id ? req.params._id : "", req.query.link ? req.query.link : "", - req.userDetails && req.userDetails.userInformation && req.userDetails.userInformation.userId ? req.userDetails.userInformation.userId : "" + req.userDetails && req.userDetails.userInformation && req.userDetails.userInformation.userId ? req.userDetails.userInformation.userId : "", + req.query.isAPrivateProgram ? req.query.isAPrivateProgram : "" ); projectTemplatesDetails.result = projectTemplatesDetails.data; diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 6e3404f..26081a2 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -975,7 +975,7 @@ module.exports = class ProjectTemplatesHelper { * @returns {Array} Project templates data. */ - static details( templateId="", link="", userId="" ) { + static details( templateId="", link="", userId="", isAPrivateProgram ) { return new Promise(async (resolve, reject) => { try { let solutionsResult = {}; @@ -1077,7 +1077,8 @@ module.exports = class ProjectTemplatesHelper { let project = await projectQueries.projectDocument({ userId : userId, - projectTemplateId : templateData[0]._id + projectTemplateId : templateData[0]._id, + isAPrivateProgram : isAPrivateProgram },["_id"]); if(project && project.length > 0){ diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 090b503..f35f82a 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1069,21 +1069,14 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - // This is used to check solution is targetted or not + // This will check wether the user user is targeted to solution or not based on his userRoleInformation const targetedSolutionId = await coreService.checkIfSolutionIsTargetedForUserProfile(userToken,bodyData,solutionId) - - let projectDocumentQuery = { + //based on above api will check for projects wether its is private project or public project + const projectDetails = await projectQueries.projectDocument({ solutionId: solutionId, userId: userId, - } - - if(targetedSolutionId.data.isATargetedSolution){ - projectDocumentQuery.isAPrivateProgram = false - } - //based on above api will check for projects wether its is private project or public project - const projectDetails = await projectQueries.projectDocument(projectDocumentQuery, ["_id"]); - - + isAPrivateProgram: targetedSolutionId.data.isATargetedSolution ? false : true + }, ["_id"]); if( projectDetails.length > 0 ) { projectId = projectDetails[0]._id; } else { From d9b0420636a9501e93067bd413613fb3e990729f Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 28 Mar 2023 11:57:05 +0530 Subject: [PATCH 09/10] Fixed Public and private project for solution --- module/project/templates/helper.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 26081a2..cff8689 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1074,11 +1074,18 @@ module.exports = class ProjectTemplatesHelper { if( !templateData[0].isReusable && userId !== "") { templateData[0].projectId = ""; - - let project = await projectQueries.projectDocument({ + + const projectIdQuery = { userId : userId, projectTemplateId : templateData[0]._id, - isAPrivateProgram : isAPrivateProgram + } + + if( isAPrivateProgram !== ""){ + projectIdQuery.isAPrivateProgram = isAPrivateProgram + } + + let project = await projectQueries.projectDocument({ + projectIdQuery },["_id"]); if(project && project.length > 0){ From c5ac1c7de293bac62395ea9fa44549e8617a2f68 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 28 Mar 2023 13:14:06 +0530 Subject: [PATCH 10/10] Fixed Public and private project for solution --- app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.js b/app.js index 066afc7..30806a0 100644 --- a/app.js +++ b/app.js @@ -45,12 +45,12 @@ app.use(express.static("public")); app.all('*', (req, res, next) => { console.log({"Debugging ML Projects Service": true}); - console.log("-------Request log starts here------------------"); + console.log("<------------Request log starts here------------------>"); console.log("Request URL: ", req.url); console.log("Request Headers: ", JSON.stringify(req.headers)); console.log("Request Body: ", JSON.stringify(req.body)); // console.log("Request Files: ", req.files); - console.log("-------Request log ends here------------------"); + console.log("<---------------Request log ends here------------------>"); next(); });