diff --git a/app.js b/app.js index 066afc79..30806a0d 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(); }); diff --git a/controllers/v1/project/templates.js b/controllers/v1/project/templates.js index 486ad6c2..1cc19f70 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/generics/constants/endpoints.js b/generics/constants/endpoints.js index c8a5bfaf..bec01de6 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", + IS_TARGETED_BASED_ON_USER_PROFILE : "/v1/solutions/isTargetedBasedOnUserProfile", }; diff --git a/generics/services/core.js b/generics/services/core.js index ec12900e..8a1ace5c 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -725,6 +725,57 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution }) } + +const checkIfSolutionIsTargetedForUserProfile = function ( token,bodyData,solutionId ) { + return new Promise(async (resolve, reject) => { + try { + + const url = + ML_CORE_URL + CONSTANTS.endpoints.IS_TARGETED_BASED_ON_USER_PROFILE + "/" + 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,verifyTargetedSolutionCallback); + + function verifyTargetedSolutionCallback(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, + checkIfSolutionIsTargetedForUserProfile:checkIfSolutionIsTargetedForUserProfile }; diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 6e3404f8..cff8689c 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 = {}; @@ -1074,10 +1074,18 @@ module.exports = class ProjectTemplatesHelper { if( !templateData[0].isReusable && userId !== "") { templateData[0].projectId = ""; + + const projectIdQuery = { + userId : userId, + projectTemplateId : templateData[0]._id, + } + + if( isAPrivateProgram !== ""){ + projectIdQuery.isAPrivateProgram = isAPrivateProgram + } let project = await projectQueries.projectDocument({ - userId : userId, - projectTemplateId : templateData[0]._id + projectIdQuery },["_id"]); if(project && project.length > 0){ diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 2283a2f1..f35f82a3 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1069,12 +1069,14 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { - + // 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) + //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 + userId: userId, + isAPrivateProgram: targetedSolutionId.data.isATargetedSolution ? false : true }, ["_id"]); - if( projectDetails.length > 0 ) { projectId = projectDetails[0]._id; } else {