Skip to content

Commit

Permalink
Merge pull request #164 from shikshalokam/master
Browse files Browse the repository at this point in the history
PII Changes for Project
  • Loading branch information
aks30 authored Apr 27, 2023
2 parents 4453b31 + a9c4c04 commit b013b95
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ config/credentials/*
*.DS_Store

package-lock.json
keycloak-public-keys/
22 changes: 22 additions & 0 deletions controllers/v1/programUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* name : programUsers.js
* author : Ankit Shahu
* 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";
}

};

52 changes: 52 additions & 0 deletions databaseQueries/programUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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",
skipFields = "none"
) {
return new Promise(async (resolve, reject) => {
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);
}
});
}

};
3 changes: 2 additions & 1 deletion generics/constants/api-responses.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "Failed to join program",
};
1 change: 1 addition & 0 deletions generics/constants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@ 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",
PROGRAM_JOIN: "/v1/programs/join",
IS_TARGETED_BASED_ON_USER_PROFILE : "/v1/solutions/isTargetedBasedOnUserProfile",
};
74 changes: 67 additions & 7 deletions generics/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,71 @@ const solutionDetailsBasedOnRoleAndLocation = function ( token,bodyData,solution
})
}

/**
* program Join Api.
* @function
* @name joinProgram
* @param {String} userToken - User token.
* @param {Object} bodyData - Requested body data.
* @param {String} programId - program id.
* @returns {JSON} - Program Join Status.
*/
const joinProgram = function (programId,bodyData,userToken) {
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,
},

};

if ( bodyData.appVersion !== "" ) {
options.headers.appversion = bodyData.appVersion;
delete bodyData.appVersion
}

if ( bodyData.appName !== "" ) {
options.headers.appname = bodyData.appName;
delete bodyData.appName
}


options.json = 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);
}
})
}


const checkIfSolutionIsTargetedForUserProfile = function ( token,bodyData,solutionId ) {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -770,12 +835,6 @@ const checkIfSolutionIsTargetedForUserProfile = function ( token,bodyData,soluti
}
})
}






module.exports = {
entityTypesDocuments : entityTypesDocuments,
rolesDocuments : rolesDocuments,
Expand All @@ -789,7 +848,8 @@ module.exports = {
createSolution: createSolution,
solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation,
solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation,
getDownloadableUrl : getDownloadableUrl,
getDownloadableUrl : getDownloadableUrl,
joinProgram: joinProgram,
checkIfSolutionIsTargetedForUserProfile:checkIfSolutionIsTargetedForUserProfile
};

34 changes: 34 additions & 0 deletions models/programUsers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
module.exports = {
name: "programUsers",
schema: {
programId: {
type : "ObjectId",
required: true,
index: true
},
userId: {
type: String,
index: true,
required: true,
},
resourcesStarted: {
type: Boolean,
index: true,
default: false
},
userProfile: {
type : Object,
required: true
},
userRoleInformation: Object,
appInformation: Object
},
compoundIndex: [
{
"name" :{ userId: 1, programId: 1 },
"indexType" : { unique: true }
}
]
};


34 changes: 32 additions & 2 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ 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");
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
Expand Down Expand Up @@ -1115,7 +1117,36 @@ module.exports = class UserProjectsHelper {
solutionDetails = solutionDetails.data[0];

}


// 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 programUsers = await programUsersQueries.programUsersDocuments(
{
userId : userId,
programId : solutionDetails.programId
},
[
"_id",
"resourcesStarted"
]
);

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,
Expand Down Expand Up @@ -1954,7 +1985,6 @@ module.exports = class UserProjectsHelper {

let totalCount = 0;
let data = [];

if( projects.success && projects.data && projects.data.data && Object.keys(projects.data.data).length > 0 ) {

totalCount = projects.data.count;
Expand Down

0 comments on commit b013b95

Please sign in to comment.