From 4f21926a94cb95542f590b5d989f33dfa59b678d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Wed, 1 Feb 2023 09:12:21 +0530 Subject: [PATCH 01/20] Added Program Join and consent --- controllers/v1/programUsers.js | 22 ++++++++++++ databaseQueries/programUsers.js | 23 ++++++++++++ generics/constants/api-responses.js | 3 +- generics/constants/endpoints.js | 3 +- generics/services/core.js | 56 ++++++++++++++++++++++++++++- models/programUsers.js | 29 +++++++++++++++ module/userProjects/helper.js | 15 +++++++- 7 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 controllers/v1/programUsers.js create mode 100644 databaseQueries/programUsers.js create mode 100644 models/programUsers.js diff --git a/controllers/v1/programUsers.js b/controllers/v1/programUsers.js new file mode 100644 index 00000000..3a9c4923 --- /dev/null +++ b/controllers/v1/programUsers.js @@ -0,0 +1,22 @@ +/** + * name : programUsers.js + * author : Vishnu + * created-date : 9-Jan-2023 + * Description : PII data related controller. +*/ + +/** + * programUsers + * @class + */ +module.exports = class ProgramUsers extends Abstract { + constructor() { + super("programUsers"); + } + + static get name() { + return "programUsers"; + } + +}; + diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js new file mode 100644 index 00000000..2a8de03f --- /dev/null +++ b/databaseQueries/programUsers.js @@ -0,0 +1,23 @@ +module.exports= class Programs{ + static findProgramJoined(programId,userId) { + return new Promise(async (resolve, reject) => { + try { + let queryObject = { + programId :programId, + userId: userId + } + + + let programJoinedData = + await database.models.programUsers.find( + queryObject, + {} + ).lean(); + return resolve(programJoinedData); + + } catch (error) { + return reject(error); + } + }); + } +} \ No newline at end of file diff --git a/generics/constants/api-responses.js b/generics/constants/api-responses.js index 7404a87a..c05d4616 100644 --- a/generics/constants/api-responses.js +++ b/generics/constants/api-responses.js @@ -134,5 +134,6 @@ module.exports = { "CERTIFICATE_GENERATION_FAILED" : "Certificate generation failed", "NOT_ELIGIBLE_FOR_CERTIFICATE" : "Project is not eligible for certificate", "ISSUER_KID_NOT_FOUND" : "Failed to fetch certificate issuer kid", - "PROJECT_SUBMITTED_FOR_REISSUE" : "Submitted for project certificate reIssue" + "PROJECT_SUBMITTED_FOR_REISSUE" : "Submitted for project certificate reIssue", + "PROGRAM_JOIN_FAILED": "Program Join Failed" }; diff --git a/generics/constants/endpoints.js b/generics/constants/endpoints.js index c8a5bfaf..a42a043a 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", + PROGRAM_JOIN: "/v1/programs/join" }; diff --git a/generics/services/core.js b/generics/services/core.js index ec12900e..5851d8e8 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -725,6 +725,59 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution }) } +/** + * program Join Api. + * @function + * @name programJoin + * @param {String} token - User token. + * @param {Object} bodyData - Requested body data. + * @param {String} programId - program id. + * @returns {JSON} - Program Join Status. +*/ +const programJoin = function (programId,bodyData,userToken,appName,appVersion) { + return new Promise(async (resolve, reject) => { + try { + + const url = + ML_CORE_URL + CONSTANTS.endpoints.PROGRAM_JOIN + "/" + programId; + const options = { + headers : { + "content-type": "application/json", + "internal-access-token": process.env.INTERNAL_ACCESS_TOKEN, + "x-authenticated-user-token" : userToken, + "x-app-id" :appName, + "x-app-ver":appVersion + }, + json: {userRoleInformation:bodyData} + }; + request.post(url,options,kendraCallback); + + function kendraCallback(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 +791,7 @@ module.exports = { createSolution: createSolution, solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation, solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation, - getDownloadableUrl : getDownloadableUrl + getDownloadableUrl : getDownloadableUrl, + programJoin: programJoin }; diff --git a/models/programUsers.js b/models/programUsers.js new file mode 100644 index 00000000..ed287107 --- /dev/null +++ b/models/programUsers.js @@ -0,0 +1,29 @@ +module.exports = { + name: "programUsers", + schema: { + programId: { + type : "ObjectId", + required: true, + index: true + }, + userId: { + type: String, + index: true + }, + noOfResourcesStarted: { + type:Number, + index: true + }, + userProfile: Object, + userRoleInformation: Object, + appInformation: Object + }, + compoundIndex: [ + { + "name" :{ userId: 1, programId: 1 }, + "indexType" : { unique: true } + } + ] +}; + + \ No newline at end of file diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index fc46cf9b..128952df 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -21,6 +21,7 @@ const projectTemplateTaskQueries = require(DB_QUERY_BASE_PATH + "/projectTemplat const kafkaProducersHelper = require(GENERICS_FILES_PATH + "/kafka/producers"); const removeFieldsFromRequest = ["submissionDetails"]; const programsQueries = require(DB_QUERY_BASE_PATH + "/programs"); +const programUsers = require(DB_QUERY_BASE_PATH + "/programUsers"); const userProfileService = require(GENERICS_FILES_PATH + "/services/users"); const solutionsHelper = require(MODULES_BASE_PATH + "/solutions/helper"); const certificateTemplateQueries = require(DB_QUERY_BASE_PATH + "/certificateTemplates"); @@ -1113,7 +1114,19 @@ module.exports = class UserProjectsHelper { solutionDetails = solutionDetails.data[0]; } - + // program join API call + let programJoined = await programUsers.findProgramJoined(solutionDetails.programId,userId) + + if(programJoined.length == 0){ + let programJoinAPI = await coreService.programJoin(solutionDetails.programId,bodyData,userToken,appName,appVersion) + if(!programJoinAPI.success){ + throw { + success: HTTP_STATUS_CODE['bad_request'].status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + } + } + } + let projectCreation = await this.userAssignedProjectCreation( solutionDetails.projectTemplateId, From 077dd7c33a14343b4d825e72351f2183ecb19c2e Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Wed, 1 Feb 2023 12:40:07 +0530 Subject: [PATCH 02/20] Done WIth Project --- generics/constants/api-responses.js | 2 +- generics/services/core.js | 6 ++---- module/userProjects/helper.js | 22 ++++++++++++++++------ 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/generics/constants/api-responses.js b/generics/constants/api-responses.js index c05d4616..db81c809 100644 --- a/generics/constants/api-responses.js +++ b/generics/constants/api-responses.js @@ -135,5 +135,5 @@ module.exports = { "NOT_ELIGIBLE_FOR_CERTIFICATE" : "Project is not eligible for certificate", "ISSUER_KID_NOT_FOUND" : "Failed to fetch certificate issuer kid", "PROJECT_SUBMITTED_FOR_REISSUE" : "Submitted for project certificate reIssue", - "PROGRAM_JOIN_FAILED": "Program Join Failed" + "PROGRAM_JOIN_FAILED" : "Failed to join program", }; diff --git a/generics/services/core.js b/generics/services/core.js index 5851d8e8..9fe6d6a3 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -734,7 +734,7 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution * @param {String} programId - program id. * @returns {JSON} - Program Join Status. */ -const programJoin = function (programId,bodyData,userToken,appName,appVersion) { +const programJoin = function (programId,bodyData,userToken) { return new Promise(async (resolve, reject) => { try { @@ -745,10 +745,8 @@ const programJoin = function (programId,bodyData,userToken,appName,appVersion) { "content-type": "application/json", "internal-access-token": process.env.INTERNAL_ACCESS_TOKEN, "x-authenticated-user-token" : userToken, - "x-app-id" :appName, - "x-app-ver":appVersion }, - json: {userRoleInformation:bodyData} + json: bodyData }; request.post(url,options,kendraCallback); diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 128952df..13d57e28 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1118,15 +1118,25 @@ module.exports = class UserProjectsHelper { let programJoined = await programUsers.findProgramJoined(solutionDetails.programId,userId) if(programJoined.length == 0){ - let programJoinAPI = await coreService.programJoin(solutionDetails.programId,bodyData,userToken,appName,appVersion) - if(!programJoinAPI.success){ - throw { - success: HTTP_STATUS_CODE['bad_request'].status, - message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + if ( appVersion !== "" && appVersion < 5.2 ) { + let programJoinBody = {}; + programJoinBody.userRoleInformation = req.body.userRoleInformation; + programJoinBody.isResource = true; + let joinProgramData = await coreService.programJoin ( + solutionDetails.programId, + programJoinData, + req.userDetails.userToken + ); + + if ( !joinProgramData.success ) { + return resolve({ + status: httpStatusCode.bad_request.status, + message: messageConstants.apiResponses.PROGRAM_JOIN_FAILED + }); } } } - + let projectCreation = await this.userAssignedProjectCreation( solutionDetails.projectTemplateId, From fbcfb11b941f9af5b52b0dd88e7b4c017a7651bc Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 09:05:56 +0530 Subject: [PATCH 03/20] Saving Changes --- databaseQueries/programUsers.js | 22 +++++++++++++++++++ ...Rxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 +++ module/userProjects/helper.js | 4 +++- package.json | 2 +- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js index 2a8de03f..451be006 100644 --- a/databaseQueries/programUsers.js +++ b/databaseQueries/programUsers.js @@ -20,4 +20,26 @@ module.exports= class Programs{ } }); } + + + static findProgramIds(userId) { + return new Promise(async (resolve, reject) => { + try { + let queryObject = { + userId: userId + } + + + let programJoinedData = + await database.models.programUsers.find( + queryObject, + {"programId":1} + ).lean(); + return resolve(programJoinedData); + + } catch (error) { + return reject(error); + } + }); +} } \ No newline at end of file diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA new file mode 100644 index 00000000..44c17f6c --- /dev/null +++ b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB +-----END PUBLIC KEY----- diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 13d57e28..86f7651a 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1124,7 +1124,7 @@ module.exports = class UserProjectsHelper { programJoinBody.isResource = true; let joinProgramData = await coreService.programJoin ( solutionDetails.programId, - programJoinData, + programJoinBody, req.userDetails.userToken ); @@ -1975,6 +1975,8 @@ module.exports = class UserProjectsHelper { let totalCount = 0; let data = []; + + let programJoined = await programUsers.findProgramJoined(userId) if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) { diff --git a/package.json b/package.json index ab919560..875b6517 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "cli-table": "^0.3.1", "cors": "^2.8.5", "csvtojson": "^2.0.10", - "dotenv": "^8.2.0", + "dotenv": "^8.6.0", "express": "^4.17.1", "express-fileupload": "^1.1.6", "express-validator": "^5.3.1", From 6416529870eb6c09c693f30bad97c175c3365006 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Feb 2023 12:00:57 +0530 Subject: [PATCH 04/20] saving changes --- module/userProjects/helper.js | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 86f7651a..ba2a7685 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1116,25 +1116,25 @@ module.exports = class UserProjectsHelper { } // program join API call let programJoined = await programUsers.findProgramJoined(solutionDetails.programId,userId) - + console.log(programJoined) if(programJoined.length == 0){ - if ( appVersion !== "" && appVersion < 5.2 ) { - let programJoinBody = {}; - programJoinBody.userRoleInformation = req.body.userRoleInformation; - programJoinBody.isResource = true; - let joinProgramData = await coreService.programJoin ( - solutionDetails.programId, - programJoinBody, - req.userDetails.userToken - ); - - if ( !joinProgramData.success ) { - return resolve({ - status: httpStatusCode.bad_request.status, - message: messageConstants.apiResponses.PROGRAM_JOIN_FAILED - }); - } + + let programJoinBody = {}; + programJoinBody.userRoleInformation = bodyData; + programJoinBody.isResource = true; + let joinProgramData = await coreService.programJoin ( + solutionDetails.programId, + programJoinBody, + userToken + ); + + if ( !joinProgramData.success ) { + return resolve({ + status: HTTP_STATUS_CODE.bad_request.status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + }); } + } let projectCreation = @@ -1976,7 +1976,7 @@ module.exports = class UserProjectsHelper { let totalCount = 0; let data = []; - let programJoined = await programUsers.findProgramJoined(userId) + // let programJoined = await programUsers.findProgramJoined(userId) if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) { From f18868829fd9d1ca47086d2b3a1542522a3761bc Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 13 Feb 2023 08:38:51 +0530 Subject: [PATCH 05/20] Raising Pr for project join programs --- generics/services/core.js | 1 + module/project/templates/helper.js | 12 ++ module/userProjects/helper.js | 187 +++++++++++++++++------------ 3 files changed, 120 insertions(+), 80 deletions(-) diff --git a/generics/services/core.js b/generics/services/core.js index 9fe6d6a3..96e07492 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -761,6 +761,7 @@ const programJoin = function (programId,bodyData,userToken) { } else { let response = data.body; + console.log(response); if( response.status === HTTP_STATUS_CODE['ok'].status ) { result["data"] = response.result; } else { diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 6e3404f8..3fce4fd4 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1079,6 +1079,18 @@ module.exports = class ProjectTemplatesHelper { userId : userId, projectTemplateId : templateData[0]._id },["_id"]); + + //check for program enrollment if enrolled then add programJoined true + let programJoined = await programUsers.findProgramIds(userId) + let projects = project.map((e,i)=>{ + let temp = programJoined.find((element)=> { + return element.programId.toString() == e._id.toString() + }) + if(temp.programId) { + templateData[0].programJoined = true; + } + return e; + }) if(project && project.length > 0){ templateData[0].projectId = project[0]._id; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index ba2a7685..c1ac6bf5 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1127,7 +1127,6 @@ module.exports = class UserProjectsHelper { programJoinBody, userToken ); - if ( !joinProgramData.success ) { return resolve({ status: HTTP_STATUS_CODE.bad_request.status, @@ -1229,88 +1228,88 @@ module.exports = class UserProjectsHelper { projectCreation.data["userRole"] = bodyData.role; } - if( - solutionDetails.entityType && bodyData[solutionDetails.entityType] - ) { - let entityInformation = - await surveyService.listEntitiesByLocationIds( - userToken, - [bodyData[solutionDetails.entityType]] - ); - - if( !entityInformation.success ) { - return resolve(entityInformation); - } - - let entityDetails = await _entitiesMetaInformation( - entityInformation.data - ); - - if ( entityDetails && entityDetails.length > 0 ) { - projectCreation.data["entityInformation"] = entityDetails[0]; - } + // if( + // solutionDetails.entityType && bodyData[solutionDetails.entityType] + // ) { + // let entityInformation = + // await surveyService.listEntitiesByLocationIds( + // userToken, + // [bodyData[solutionDetails.entityType]] + // ); + + // if( !entityInformation.success ) { + // return resolve(entityInformation); + // } + + // let entityDetails = await _entitiesMetaInformation( + // entityInformation.data + // ); + + // if ( entityDetails && entityDetails.length > 0 ) { + // projectCreation.data["entityInformation"] = entityDetails[0]; + // } - projectCreation.data.entityId = entityInformation.data[0]._id; - } + // projectCreation.data.entityId = entityInformation.data[0]._id; + // } } projectCreation.data.status = CONSTANTS.common.STARTED; projectCreation.data.lastDownloadedAt = new Date(); - // fetch userRoleInformation from observation if referenecFrom is observation - let addReportInfoToSolution = false; - if ( getUserProfileFromObservation ){ - - let observationDetails = await surveyService.observationDetails( - userToken, - bodyData.submissions.observationId - ); - - if( observationDetails.data && - Object.keys(observationDetails.data).length > 0 && - observationDetails.data.userRoleInformation && - Object.keys(observationDetails.data.userRoleInformation).length > 0 - ) { - - userRoleInformation = observationDetails.data.userRoleInformation; + // // fetch userRoleInformation from observation if referenecFrom is observation + // let addReportInfoToSolution = false; + // if ( getUserProfileFromObservation ){ + + // let observationDetails = await surveyService.observationDetails( + // userToken, + // bodyData.submissions.observationId + // ); + + // if( observationDetails.data && + // Object.keys(observationDetails.data).length > 0 && + // observationDetails.data.userRoleInformation && + // Object.keys(observationDetails.data.userRoleInformation).length > 0 + // ) { + + // userRoleInformation = observationDetails.data.userRoleInformation; - } + // } - if( observationDetails.data && - Object.keys(observationDetails.data).length > 0 && - observationDetails.data.userProfile && - Object.keys(observationDetails.data.userProfile).length > 0 - ) { + // if( observationDetails.data && + // Object.keys(observationDetails.data).length > 0 && + // observationDetails.data.userProfile && + // Object.keys(observationDetails.data.userProfile).length > 0 + // ) { - projectCreation.data.userProfile = observationDetails.data.userProfile; - addReportInfoToSolution = true; + // projectCreation.data.userProfile = observationDetails.data.userProfile; + // addReportInfoToSolution = true; - } else { - //Fetch user profile information by calling sunbird's user read api. - - let userProfile = await userProfileService.profile(userToken, userId); - if ( userProfile.success && - userProfile.data && - userProfile.data.response - ) { - projectCreation.data.userProfile = userProfile.data.response; - addReportInfoToSolution = true; - } - } - - } else { - //Fetch user profile information by calling sunbird's user read api. - - let userProfileData = await userProfileService.profile(userToken, userId); - if ( userProfileData.success && - userProfileData.data && - userProfileData.data.response - ) { - projectCreation.data.userProfile = userProfileData.data.response; - addReportInfoToSolution = true; - } - } + // } else { + // //Fetch user profile information by calling sunbird's user read api. + + // let userProfile = await userProfileService.profile(userToken, userId); + // if ( userProfile.success && + // userProfile.data && + // userProfile.data.response + // ) { + // projectCreation.data.userProfile = userProfile.data.response; + // addReportInfoToSolution = true; + // } + // } + + // } else { + // //Fetch user profile information by calling sunbird's user read api. + + // let userProfileData = await userProfileService.profile(userToken, userId); + // if ( userProfileData.success && + // userProfileData.data && + // userProfileData.data.response + // ) { + // projectCreation.data.userProfile = userProfileData.data.response; + // addReportInfoToSolution = true; + // } + // } projectCreation.data.userRoleInformation = userRoleInformation; @@ -1328,12 +1327,12 @@ module.exports = class UserProjectsHelper { let project = await projectQueries.createProject(projectCreation.data); - if ( addReportInfoToSolution && project.solutionId ) { - let updateSolution = await solutionsHelper.addReportInformationInSolution( - project.solutionId, - project.userProfile - ); - } + // if ( addReportInfoToSolution && project.solutionId ) { + // let updateSolution = await solutionsHelper.addReportInformationInSolution( + // project.solutionId, + // project.userProfile + // ); + // } await kafkaProducersHelper.pushProjectToKafka(project); @@ -1976,8 +1975,16 @@ module.exports = class UserProjectsHelper { let totalCount = 0; let data = []; - // let programJoined = await programUsers.findProgramJoined(userId) - + let programJoined = await programUsers.findProgramIds(userId) + projects.data.data = projects.data.data.map((e,i)=>{ + let temp = programJoined.find((element)=> { + return element.programId.toString() == e.programId.toString() + }) + if(temp.programId) { + e.programJoined = true; + } + return e; + }) if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) { totalCount = projects.data.count; @@ -2291,6 +2298,26 @@ module.exports = class UserProjectsHelper { programAndSolutionInformation.data ) } + + let programJoined = await programUsers.findProgramJoined(requestedData.programId,userId) + if(programJoined.length == 0){ + + let programJoinBody = {}; + programJoinBody.isResource = true; + let joinProgramData = await coreService.programJoin ( + solutionDetails.programId, + programJoinBody, + userToken + ); + if ( !joinProgramData.success ) { + return resolve({ + status: HTTP_STATUS_CODE.bad_request.status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + }); + } + + } + // <- Add certificate template data if ( libraryProjects.data.certificateTemplateId && From 1f63f41b8738ddf4274357ba4930cb5efc66d2fa Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Mon, 13 Feb 2023 08:48:12 +0530 Subject: [PATCH 06/20] Done with Project code --- generics/services/core.js | 1 - ...Rxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 - module/project/templates/helper.js | 4 +- module/userProjects/helper.js | 158 +++++++++--------- 4 files changed, 81 insertions(+), 85 deletions(-) delete mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/generics/services/core.js b/generics/services/core.js index 96e07492..9fe6d6a3 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -761,7 +761,6 @@ const programJoin = function (programId,bodyData,userToken) { } else { let response = data.body; - console.log(response); if( response.status === HTTP_STATUS_CODE['ok'].status ) { result["data"] = response.result; } else { diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA deleted file mode 100644 index 44c17f6c..00000000 --- a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB ------END PUBLIC KEY----- diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 3fce4fd4..41f84739 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1083,10 +1083,10 @@ module.exports = class ProjectTemplatesHelper { //check for program enrollment if enrolled then add programJoined true let programJoined = await programUsers.findProgramIds(userId) let projects = project.map((e,i)=>{ - let temp = programJoined.find((element)=> { + let programIds = programJoined.find((element)=> { return element.programId.toString() == e._id.toString() }) - if(temp.programId) { + if(programIds.programId) { templateData[0].programJoined = true; } return e; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index c1ac6bf5..9ae3468b 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1228,88 +1228,88 @@ module.exports = class UserProjectsHelper { projectCreation.data["userRole"] = bodyData.role; } - // if( - // solutionDetails.entityType && bodyData[solutionDetails.entityType] - // ) { - // let entityInformation = - // await surveyService.listEntitiesByLocationIds( - // userToken, - // [bodyData[solutionDetails.entityType]] - // ); - - // if( !entityInformation.success ) { - // return resolve(entityInformation); - // } - - // let entityDetails = await _entitiesMetaInformation( - // entityInformation.data - // ); - - // if ( entityDetails && entityDetails.length > 0 ) { - // projectCreation.data["entityInformation"] = entityDetails[0]; - // } + if( + solutionDetails.entityType && bodyData[solutionDetails.entityType] + ) { + let entityInformation = + await surveyService.listEntitiesByLocationIds( + userToken, + [bodyData[solutionDetails.entityType]] + ); + + if( !entityInformation.success ) { + return resolve(entityInformation); + } + + let entityDetails = await _entitiesMetaInformation( + entityInformation.data + ); + + if ( entityDetails && entityDetails.length > 0 ) { + projectCreation.data["entityInformation"] = entityDetails[0]; + } - // projectCreation.data.entityId = entityInformation.data[0]._id; - // } + projectCreation.data.entityId = entityInformation.data[0]._id; + } } projectCreation.data.status = CONSTANTS.common.STARTED; projectCreation.data.lastDownloadedAt = new Date(); - // // fetch userRoleInformation from observation if referenecFrom is observation - // let addReportInfoToSolution = false; - // if ( getUserProfileFromObservation ){ - - // let observationDetails = await surveyService.observationDetails( - // userToken, - // bodyData.submissions.observationId - // ); - - // if( observationDetails.data && - // Object.keys(observationDetails.data).length > 0 && - // observationDetails.data.userRoleInformation && - // Object.keys(observationDetails.data.userRoleInformation).length > 0 - // ) { - - // userRoleInformation = observationDetails.data.userRoleInformation; + // fetch userRoleInformation from observation if referenecFrom is observation + let addReportInfoToSolution = false; + if ( getUserProfileFromObservation ){ + + let observationDetails = await surveyService.observationDetails( + userToken, + bodyData.submissions.observationId + ); + + if( observationDetails.data && + Object.keys(observationDetails.data).length > 0 && + observationDetails.data.userRoleInformation && + Object.keys(observationDetails.data.userRoleInformation).length > 0 + ) { + + userRoleInformation = observationDetails.data.userRoleInformation; - // } + } - // if( observationDetails.data && - // Object.keys(observationDetails.data).length > 0 && - // observationDetails.data.userProfile && - // Object.keys(observationDetails.data.userProfile).length > 0 - // ) { + if( observationDetails.data && + Object.keys(observationDetails.data).length > 0 && + observationDetails.data.userProfile && + Object.keys(observationDetails.data.userProfile).length > 0 + ) { - // projectCreation.data.userProfile = observationDetails.data.userProfile; - // addReportInfoToSolution = true; + projectCreation.data.userProfile = observationDetails.data.userProfile; + addReportInfoToSolution = true; - // } else { - // //Fetch user profile information by calling sunbird's user read api. - - // let userProfile = await userProfileService.profile(userToken, userId); - // if ( userProfile.success && - // userProfile.data && - // userProfile.data.response - // ) { - // projectCreation.data.userProfile = userProfile.data.response; - // addReportInfoToSolution = true; - // } - // } - - // } else { - // //Fetch user profile information by calling sunbird's user read api. - - // let userProfileData = await userProfileService.profile(userToken, userId); - // if ( userProfileData.success && - // userProfileData.data && - // userProfileData.data.response - // ) { - // projectCreation.data.userProfile = userProfileData.data.response; - // addReportInfoToSolution = true; - // } - // } + } else { + //Fetch user profile information by calling sunbird's user read api. + + let userProfile = await userProfileService.profile(userToken, userId); + if ( userProfile.success && + userProfile.data && + userProfile.data.response + ) { + projectCreation.data.userProfile = userProfile.data.response; + addReportInfoToSolution = true; + } + } + + } else { + //Fetch user profile information by calling sunbird's user read api. + + let userProfileData = await userProfileService.profile(userToken, userId); + if ( userProfileData.success && + userProfileData.data && + userProfileData.data.response + ) { + projectCreation.data.userProfile = userProfileData.data.response; + addReportInfoToSolution = true; + } + } projectCreation.data.userRoleInformation = userRoleInformation; @@ -1327,12 +1327,12 @@ module.exports = class UserProjectsHelper { let project = await projectQueries.createProject(projectCreation.data); - // if ( addReportInfoToSolution && project.solutionId ) { - // let updateSolution = await solutionsHelper.addReportInformationInSolution( - // project.solutionId, - // project.userProfile - // ); - // } + if ( addReportInfoToSolution && project.solutionId ) { + let updateSolution = await solutionsHelper.addReportInformationInSolution( + project.solutionId, + project.userProfile + ); + } await kafkaProducersHelper.pushProjectToKafka(project); @@ -1977,10 +1977,10 @@ module.exports = class UserProjectsHelper { let programJoined = await programUsers.findProgramIds(userId) projects.data.data = projects.data.data.map((e,i)=>{ - let temp = programJoined.find((element)=> { + let programsIds = programJoined.find((element)=> { return element.programId.toString() == e.programId.toString() }) - if(temp.programId) { + if(programsIds.programId) { e.programJoined = true; } return e; From eebfda9d3eaa211efa695d9a5555cf368c2da604 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 14 Feb 2023 09:17:15 +0530 Subject: [PATCH 07/20] Added user Role Information --- module/userProjects/helper.js | 1 + 1 file changed, 1 insertion(+) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 9ae3468b..9ecb248e 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2303,6 +2303,7 @@ module.exports = class UserProjectsHelper { if(programJoined.length == 0){ let programJoinBody = {}; + programJoinBody.userRoleInformation = requestedData.userRoleInformation ? requestedData.userRoleInformation : {}; programJoinBody.isResource = true; let joinProgramData = await coreService.programJoin ( solutionDetails.programId, From e29e526fba1a2b65a849de350ecb4ba32c01a5df Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Mar 2023 14:49:09 +0530 Subject: [PATCH 08/20] resolved comments --- databaseQueries/programUsers.js | 96 +++++++++++-------- generics/services/core.js | 12 ++- ...Rxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 + models/programUsers.js | 11 ++- module/project/templates/helper.js | 10 +- module/userProjects/helper.js | 77 +++++++-------- 6 files changed, 115 insertions(+), 94 deletions(-) create mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js index 451be006..771e18ed 100644 --- a/databaseQueries/programUsers.js +++ b/databaseQueries/programUsers.js @@ -1,45 +1,57 @@ -module.exports= class Programs{ - static findProgramJoined(programId,userId) { - return new Promise(async (resolve, reject) => { - try { - let queryObject = { - programId :programId, - userId: userId - } - - - let programJoinedData = - await database.models.programUsers.find( - queryObject, - {} - ).lean(); - return resolve(programJoinedData); - - } catch (error) { - return reject(error); - } - }); - } - - - static findProgramIds(userId) { +module.exports = class Programs { + static programUsersDocument( + filterData = "all", + fieldsArray = "all", + skipFields = "none" + ) { return new Promise(async (resolve, reject) => { - try { - let queryObject = { - userId: userId - } - - - let programJoinedData = - await database.models.programUsers.find( - queryObject, - {"programId":1} - ).lean(); - return resolve(programJoinedData); - - } catch (error) { - return reject(error); + try { + + let queryObject = (filterData != "all") ? filterData : {}; + let projection = {} + + if (fieldsArray != "all") { + fieldsArray.forEach(field => { + projection[field] = 1; + }); } - }); + + if( skipFields !== "none" ) { + skipFields.forEach(field=>{ + projection[field] = 0; + }); + } + + let programJoinedData = await database.models.programUsers + .find(queryObject, projection) + .lean(); + return resolve(programJoinedData); + } catch (error) { + return reject(error); + } + }); + } + + + static update(query, update, options = {}) { + return new Promise(async (resolve, reject) => { + try { + + let programUsers = await database.models.programUsers.findOneAndUpdate( + query, + update, + options + ); + if( !programUsers._id ) { + throw { + message : constants.apiResponses.PROGRAM_USERS_NOT_UPDATED + }; + } + return resolve(programUsers); + + } catch (error) { + return reject(error); + } + }) } -} \ No newline at end of file +}; diff --git a/generics/services/core.js b/generics/services/core.js index 9fe6d6a3..80421953 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -729,7 +729,7 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution * program Join Api. * @function * @name programJoin - * @param {String} token - User token. + * @param {String} userToken - User token. * @param {Object} bodyData - Requested body data. * @param {String} programId - program id. * @returns {JSON} - Program Join Status. @@ -748,6 +748,16 @@ const programJoin = function (programId,bodyData,userToken) { }, json: bodyData }; + + if ( bodyData.appVersion !== "" ) { + options.headers.appversion = bodyData.appVersion; + delete bodyData.appVersion + } + + if ( bodyData.appName !== "" ) { + options.headers.appname = bodyData.appName; + delete bodyData.appName + } request.post(url,options,kendraCallback); function kendraCallback(err, data) { diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA new file mode 100644 index 00000000..44c17f6c --- /dev/null +++ b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB +-----END PUBLIC KEY----- diff --git a/models/programUsers.js b/models/programUsers.js index ed287107..447e7e45 100644 --- a/models/programUsers.js +++ b/models/programUsers.js @@ -8,13 +8,18 @@ module.exports = { }, userId: { type: String, - index: true + index: true, + required: true, }, noOfResourcesStarted: { type:Number, - index: true + index: true, + default: 0 + }, + userProfile: { + type : Object, + required: true }, - userProfile: Object, userRoleInformation: Object, appInformation: Object }, diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 41f84739..98ac6ce3 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1081,15 +1081,15 @@ module.exports = class ProjectTemplatesHelper { },["_id"]); //check for program enrollment if enrolled then add programJoined true - let programJoined = await programUsers.findProgramIds(userId) - let projects = project.map((e,i)=>{ - let programIds = programJoined.find((element)=> { - return element.programId.toString() == e._id.toString() + let programJoined = await programUsers.programUsersDocument({userId: userId},["programId"]) + project.map((projects)=>{ + let programIds = programJoined.find((program)=> { + return program.programId.toString() == projects._id.toString() }) if(programIds.programId) { templateData[0].programJoined = true; } - return e; + return projects; }) if(project && project.length > 0){ diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 9ecb248e..2ea4fdb6 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1115,25 +1115,34 @@ module.exports = class UserProjectsHelper { } // program join API call - let programJoined = await programUsers.findProgramJoined(solutionDetails.programId,userId) - console.log(programJoined) - if(programJoined.length == 0){ - - let programJoinBody = {}; - programJoinBody.userRoleInformation = bodyData; - programJoinBody.isResource = true; - let joinProgramData = await coreService.programJoin ( - solutionDetails.programId, - programJoinBody, - userToken - ); - if ( !joinProgramData.success ) { - return resolve({ - status: HTTP_STATUS_CODE.bad_request.status, - message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED - }); + if ( appVersion === "" || appVersion < 5.2 ) { + let query = { + userId: userId, + programId: solutionDetails.programId } + let programJoined = await programUsers.programUsersDocument(query) + if(programJoined.length == 0){ + let programJoinBody = {}; + programJoinBody.userRoleInformation = bodyData; + programJoinBody.isResource = true; + let joinProgramData = await coreService.programJoin ( + solutionDetails.programId, + programJoinBody, + userToken + ); + if ( !joinProgramData.success ) { + return resolve({ + status: HTTP_STATUS_CODE.bad_request.status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + }); + } + }else{ + await programUsers.update( + { _id : programUsers[0]._id }, + { '$inc' : { noOfResourcesStarted : 1 } } + ); + } } let projectCreation = @@ -1974,16 +1983,17 @@ module.exports = class UserProjectsHelper { let totalCount = 0; let data = []; - - let programJoined = await programUsers.findProgramIds(userId) - projects.data.data = projects.data.data.map((e,i)=>{ - let programsIds = programJoined.find((element)=> { - return element.programId.toString() == e.programId.toString() + //this is to check if user has already joined program or not + let programJoined = await programUsers.programUsersDocument({userId: userId},["programId"]) + projects.data.data = projects.data.data.map((project)=>{ + //maps projects which have joined program + let programsIds = programJoined.find((program)=> { + return program.programId.toString() == project.programId.toString() }) if(programsIds.programId) { - e.programJoined = true; + project.programJoined = true; } - return e; + return project; }) if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) { @@ -2299,25 +2309,6 @@ module.exports = class UserProjectsHelper { ) } - let programJoined = await programUsers.findProgramJoined(requestedData.programId,userId) - if(programJoined.length == 0){ - - let programJoinBody = {}; - programJoinBody.userRoleInformation = requestedData.userRoleInformation ? requestedData.userRoleInformation : {}; - programJoinBody.isResource = true; - let joinProgramData = await coreService.programJoin ( - solutionDetails.programId, - programJoinBody, - userToken - ); - if ( !joinProgramData.success ) { - return resolve({ - status: HTTP_STATUS_CODE.bad_request.status, - message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED - }); - } - - } // <- Add certificate template data if ( From 31c72e5636dd646a9cd2bcc6abc6f0e40ca03928 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Mar 2023 14:49:26 +0530 Subject: [PATCH 09/20] resolved comments --- .../GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA deleted file mode 100644 index 44c17f6c..00000000 --- a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB ------END PUBLIC KEY----- From f078a0481c1c3a64d2e9058e50d7b4da48619759 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 7 Mar 2023 14:51:36 +0530 Subject: [PATCH 10/20] resolved comments --- generics/services/core.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/generics/services/core.js b/generics/services/core.js index 80421953..0ada43bf 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -746,7 +746,7 @@ const programJoin = function (programId,bodyData,userToken) { "internal-access-token": process.env.INTERNAL_ACCESS_TOKEN, "x-authenticated-user-token" : userToken, }, - json: bodyData + }; if ( bodyData.appVersion !== "" ) { @@ -758,6 +758,9 @@ const programJoin = function (programId,bodyData,userToken) { options.headers.appname = bodyData.appName; delete bodyData.appName } + + + options.json = bodyData request.post(url,options,kendraCallback); function kendraCallback(err, data) { From f1a910c1ff3cc67d5616715472fa2a8f9c11a5d0 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Wed, 8 Mar 2023 15:37:01 +0530 Subject: [PATCH 11/20] resolved comments --- databaseQueries/programUsers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js index 771e18ed..b4dc37b4 100644 --- a/databaseQueries/programUsers.js +++ b/databaseQueries/programUsers.js @@ -1,4 +1,4 @@ -module.exports = class Programs { +module.exports = class programUsers { static programUsersDocument( filterData = "all", fieldsArray = "all", From f68f14f2bc4ef5b08f423ced1b706f87841f379c Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 23 Mar 2023 17:00:47 +0530 Subject: [PATCH 12/20] 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 2283a2f1..665ce211 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 243d700fc7d9f5c0063a618b06addae801a6231b Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 6 Apr 2023 07:49:41 +0530 Subject: [PATCH 13/20] fixed comments' --- generics/services/core.js | 6 +-- ...Rxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 ++ module/project/templates/helper.js | 11 ----- module/userProjects/helper.js | 45 +++++++------------ 4 files changed, 22 insertions(+), 43 deletions(-) create mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/generics/services/core.js b/generics/services/core.js index 0ada43bf..10ef42a9 100644 --- a/generics/services/core.js +++ b/generics/services/core.js @@ -728,13 +728,13 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution /** * program Join Api. * @function - * @name programJoin + * @name joinProgram * @param {String} userToken - User token. * @param {Object} bodyData - Requested body data. * @param {String} programId - program id. * @returns {JSON} - Program Join Status. */ -const programJoin = function (programId,bodyData,userToken) { +const joinProgram = function (programId,bodyData,userToken) { return new Promise(async (resolve, reject) => { try { @@ -803,6 +803,6 @@ module.exports = { solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation, solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation, getDownloadableUrl : getDownloadableUrl, - programJoin: programJoin + joinProgram: joinProgram }; diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA new file mode 100644 index 00000000..44c17f6c --- /dev/null +++ b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB +-----END PUBLIC KEY----- diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 98ac6ce3..5b2ca248 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1080,17 +1080,6 @@ module.exports = class ProjectTemplatesHelper { projectTemplateId : templateData[0]._id },["_id"]); - //check for program enrollment if enrolled then add programJoined true - let programJoined = await programUsers.programUsersDocument({userId: userId},["programId"]) - project.map((projects)=>{ - let programIds = programJoined.find((program)=> { - return program.programId.toString() == projects._id.toString() - }) - if(programIds.programId) { - templateData[0].programJoined = true; - } - return projects; - }) if(project && project.length > 0){ templateData[0].projectId = project[0]._id; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 2ea4fdb6..56bfd4f5 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1114,35 +1114,22 @@ module.exports = class UserProjectsHelper { solutionDetails = solutionDetails.data[0]; } - // program join API call - if ( appVersion === "" || appVersion < 5.2 ) { - let query = { - userId: userId, - programId: solutionDetails.programId - } - let programJoined = await programUsers.programUsersDocument(query) - if(programJoined.length == 0){ - - let programJoinBody = {}; - programJoinBody.userRoleInformation = bodyData; - programJoinBody.isResource = true; - let joinProgramData = await coreService.programJoin ( - solutionDetails.programId, - programJoinBody, - userToken - ); - if ( !joinProgramData.success ) { - return resolve({ - status: HTTP_STATUS_CODE.bad_request.status, - message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED - }); - } - }else{ - await programUsers.update( - { _id : programUsers[0]._id }, - { '$inc' : { noOfResourcesStarted : 1 } } - ); - } + + // program join API call it will increment the noOfResourcesStarted counter and will make user join program + // before creating any project this api has to called + let programJoinBody = {}; + programJoinBody.userRoleInformation = bodyData; + programJoinBody.isResource = true; + let joinProgramData = await coreService.joinProgram ( + solutionDetails.programId, + programJoinBody, + userToken + ); + if ( !joinProgramData.success ) { + return resolve({ + status: HTTP_STATUS_CODE.bad_request.status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + }); } let projectCreation = From 73fa151fc1b9919feebbbd03b5e2f9afd0d2d7d1 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 6 Apr 2023 07:50:01 +0530 Subject: [PATCH 14/20] fixed comments --- .../GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA deleted file mode 100644 index 44c17f6c..00000000 --- a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB ------END PUBLIC KEY----- From 7eb8d542cc7f65401225a9184a64d7678c92e09d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Thu, 6 Apr 2023 11:14:39 +0530 Subject: [PATCH 15/20] fixed comments --- databaseQueries/programUsers.js | 22 ---------------------- module/userProjects/helper.js | 12 ------------ 2 files changed, 34 deletions(-) diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js index b4dc37b4..f96cb292 100644 --- a/databaseQueries/programUsers.js +++ b/databaseQueries/programUsers.js @@ -32,26 +32,4 @@ module.exports = class programUsers { }); } - - static update(query, update, options = {}) { - return new Promise(async (resolve, reject) => { - try { - - let programUsers = await database.models.programUsers.findOneAndUpdate( - query, - update, - options - ); - if( !programUsers._id ) { - throw { - message : constants.apiResponses.PROGRAM_USERS_NOT_UPDATED - }; - } - return resolve(programUsers); - - } catch (error) { - return reject(error); - } - }) -} }; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 56bfd4f5..ae76b362 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1970,18 +1970,6 @@ module.exports = class UserProjectsHelper { let totalCount = 0; let data = []; - //this is to check if user has already joined program or not - let programJoined = await programUsers.programUsersDocument({userId: userId},["programId"]) - projects.data.data = projects.data.data.map((project)=>{ - //maps projects which have joined program - let programsIds = programJoined.find((program)=> { - return program.programId.toString() == project.programId.toString() - }) - if(programsIds.programId) { - project.programJoined = true; - } - return project; - }) if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) { totalCount = projects.data.count; From 41a9314b87a46b538388a6d8a310b2eb144cecc6 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 7 Apr 2023 14:58:43 +0530 Subject: [PATCH 16/20] resolved conflict --- .../GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA diff --git a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA b/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA deleted file mode 100644 index 44c17f6c..00000000 --- a/keycloak-public-keys/GRxx8ur43pXH3_QMzBWerQPWrX02PJkK9Czl3hc60fA +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAoRbRlp/1x0h5a9Rb3E7+nU17mdnU1Grv2/a6ixhdBr1f9mjKEn7F/5eIfCQL3H82stxZyskeWaetL1mNJkAHFcJx+03DoKnGP6K+PZ3Svbw67ehgqyp+OozZCNXHzrM1DUVpvhYgsnvkqm+E1QyrsmrghSE+bAHqJep4S/70z12t8rwMNB6OxcbhrHBU93TxszxHHLZL9eaa2DCwGsTbYml0V2vFPsN4HUhXtnht9uoC2bjAXyBsrSNy/aoCsoI0erV8Vyw2FKfwEGBDFROjcWhKOdwb36TmEDf+g4OBSqAhEyewhTwcP7ESpjhyA3Ae1cH9cKOBmQTU+OmzS89h8QIDAQAB ------END PUBLIC KEY----- From d383bf79eec7202010b581a81920f769984fdd47 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 7 Apr 2023 15:25:49 +0530 Subject: [PATCH 17/20] resolved conflicts --- module/project/templates/helper.js | 2 +- module/userProjects/helper.js | 13 ------------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/module/project/templates/helper.js b/module/project/templates/helper.js index 73f326d4..cff8689c 100644 --- a/module/project/templates/helper.js +++ b/module/project/templates/helper.js @@ -1079,6 +1079,7 @@ module.exports = class ProjectTemplatesHelper { userId : userId, projectTemplateId : templateData[0]._id, } + if( isAPrivateProgram !== ""){ projectIdQuery.isAPrivateProgram = isAPrivateProgram } @@ -1086,7 +1087,6 @@ module.exports = class ProjectTemplatesHelper { let project = await projectQueries.projectDocument({ projectIdQuery },["_id"]); - if(project && project.length > 0){ templateData[0].projectId = project[0]._id; diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 6a6aea92..83a11929 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -1070,18 +1070,6 @@ module.exports = class UserProjectsHelper { let userRoleInformation = _.omit(bodyData,["referenceFrom","submissions","hasAcceptedTAndC"]); if (projectId === "") { -<<<<<<< HEAD - const userRoleInformations = userRoleInformation.role.split(",") - userRoleInformations.push() - const projectDetails = await projectQueries.projectDocument({ - solutionId: solutionId, - userId: userId, - userRole:{ - $regex: userRoleInformations.join("|"), - $options: "i" - }, - "userRoleInformation.state": userRoleInformation.state -======= // 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 @@ -1089,7 +1077,6 @@ module.exports = class UserProjectsHelper { solutionId: solutionId, userId: userId, isAPrivateProgram: targetedSolutionId.data.isATargetedSolution ? false : true ->>>>>>> refs/remotes/origin/master }, ["_id"]); if( projectDetails.length > 0 ) { projectId = projectDetails[0]._id; From bc836f113b9e27f945abe0cd0d0c6e74d2d30440 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Fri, 7 Apr 2023 15:30:33 +0530 Subject: [PATCH 18/20] resolved conflicts --- controllers/v1/programUsers.js | 2 +- databaseQueries/programUsers.js | 17 +++++++++++++++++ module/userProjects/helper.js | 2 -- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/controllers/v1/programUsers.js b/controllers/v1/programUsers.js index 3a9c4923..35d8ef63 100644 --- a/controllers/v1/programUsers.js +++ b/controllers/v1/programUsers.js @@ -1,6 +1,6 @@ /** * name : programUsers.js - * author : Vishnu + * author : Ankit Shahu * created-date : 9-Jan-2023 * Description : PII data related controller. */ diff --git a/databaseQueries/programUsers.js b/databaseQueries/programUsers.js index f96cb292..479b8b8e 100644 --- a/databaseQueries/programUsers.js +++ b/databaseQueries/programUsers.js @@ -1,4 +1,21 @@ +/** + * name : programUsers.js + * author : Ankit Shahu + * created-date : 07-04-2023 + * Description : program users helper for DB interactions. + */ module.exports = class programUsers { + + /** + * program users details. + * @method + * @name programUsersDocument + * @param {Array} [filterData = "all"] - program users filter query. + * @param {Array} [fieldsArray = "all"] - projected fields. + * @param {Array} [skipFields = "none"] - field not to include + * @returns {Array} program users details. + */ + static programUsersDocument( filterData = "all", fieldsArray = "all", diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 83a11929..722298b5 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -2285,8 +2285,6 @@ module.exports = class UserProjectsHelper { programAndSolutionInformation.data ) } - - // <- Add certificate template data if ( libraryProjects.data.certificateTemplateId && From 7cd790e603ce26656167d825bc97a1b951b594c6 Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 11 Apr 2023 19:18:56 +0530 Subject: [PATCH 19/20] Done with ED-98 Project PII --- .gitignore | 1 + models/programUsers.js | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ede208e0..90cf764a 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,4 @@ config/credentials/* *.DS_Store package-lock.json +keycloak-public-keys/ \ No newline at end of file diff --git a/models/programUsers.js b/models/programUsers.js index 447e7e45..58b00a3e 100644 --- a/models/programUsers.js +++ b/models/programUsers.js @@ -11,10 +11,10 @@ module.exports = { index: true, required: true, }, - noOfResourcesStarted: { - type:Number, + resourcesStarted: { + type: Boolean, index: true, - default: 0 + default: false }, userProfile: { type : Object, From 504994266739d962ebaf36bd3bae0d8599b18a1d Mon Sep 17 00:00:00 2001 From: ankitshahu Date: Tue, 11 Apr 2023 19:54:42 +0530 Subject: [PATCH 20/20] Added validation for program join API --- module/userProjects/helper.js | 39 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/module/userProjects/helper.js b/module/userProjects/helper.js index 722298b5..71e341b2 100644 --- a/module/userProjects/helper.js +++ b/module/userProjects/helper.js @@ -28,6 +28,7 @@ const certificateTemplateQueries = require(DB_QUERY_BASE_PATH + "/certificateTem const certificateService = require(GENERICS_FILES_PATH + "/services/certificate"); const certificateValidationsHelper = require(MODULES_BASE_PATH + "/certificateValidations/helper"); const _ = require("lodash"); +const programUsersQueries = require(DB_QUERY_BASE_PATH + "/programUsers"); /** * UserProjectsHelper @@ -1119,21 +1120,33 @@ module.exports = class UserProjectsHelper { // program join API call it will increment the noOfResourcesStarted counter and will make user join program // before creating any project this api has to called - let programJoinBody = {}; - programJoinBody.userRoleInformation = bodyData; - programJoinBody.isResource = true; - let joinProgramData = await coreService.joinProgram ( - solutionDetails.programId, - programJoinBody, - userToken + let programUsers = await programUsersQueries.programUsersDocuments( + { + userId : userId, + programId : solutionDetails.programId + }, + [ + "_id", + "resourcesStarted" + ] ); - if ( !joinProgramData.success ) { - return resolve({ - status: HTTP_STATUS_CODE.bad_request.status, - message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED - }); + + if (!programUsers.length > 0 || ( programUsers.length > 0 && programUsers[0].resourcesStarted == false)) { + let programJoinBody = {}; + programJoinBody.userRoleInformation = bodyData; + programJoinBody.isResource = true; + let joinProgramData = await coreService.joinProgram ( + solutionDetails.programId, + programJoinBody, + userToken + ); + if ( !joinProgramData.success ) { + return resolve({ + status: HTTP_STATUS_CODE.bad_request.status, + message: CONSTANTS.apiResponses.PROGRAM_JOIN_FAILED + }); + } } - let projectCreation = await this.userAssignedProjectCreation( solutionDetails.projectTemplateId,