Skip to content

Commit

Permalink
Merge pull request #163 from shikshalokam/master
Browse files Browse the repository at this point in the history
private and public project issue
  • Loading branch information
aks30 authored Mar 28, 2023
2 parents f0ac563 + 2166e80 commit 4453b31
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
3 changes: 2 additions & 1 deletion controllers/v1/project/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion generics/constants/endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
54 changes: 53 additions & 1 deletion generics/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -738,6 +789,7 @@ module.exports = {
createSolution: createSolution,
solutionBasedOnRoleAndLocation : solutionBasedOnRoleAndLocation,
solutionDetailsBasedOnRoleAndLocation : solutionDetailsBasedOnRoleAndLocation,
getDownloadableUrl : getDownloadableUrl
getDownloadableUrl : getDownloadableUrl,
checkIfSolutionIsTargetedForUserProfile:checkIfSolutionIsTargetedForUserProfile
};

14 changes: 11 additions & 3 deletions module/project/templates/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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){
Expand Down
8 changes: 5 additions & 3 deletions module/userProjects/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 4453b31

Please sign in to comment.