From e627de93ec21fb8b81e93a6f95fa11531968bc82 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 24 Mar 2020 10:51:03 +0530 Subject: [PATCH 1/3] fixing public challenge api is not accessable issue. --- .circleci/config.yml | 2 +- src/common/tcApiHelper.js | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6bb70a8..8a72aa0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,7 +102,7 @@ workflows: context : org-global filters: branches: - only: [dev, 'bug/rate-limit'] + only: [dev, 'bug/community-notification'] - "build-prod": context : org-global filters: diff --git a/src/common/tcApiHelper.js b/src/common/tcApiHelper.js index 221125b..ed67c59 100644 --- a/src/common/tcApiHelper.js +++ b/src/common/tcApiHelper.js @@ -84,7 +84,7 @@ function* getUsersByHandles(handles) { return []; } // use 'OR' to link the handle matches - const query = _.map(handles, (h) => 'handle:"' + h.trim().replace('"', '\\"') + '"').join(' OR '); + const query = _.map(handles, (h) => 'handle:"' + h.trim().replace('"', '\\"') + '"').join(' OR '); return yield searchUsersByQuery(query); } @@ -188,10 +188,20 @@ function* notifyUserViaEmail(user, message) { * @returns {Object} the challenge details */ function* getChallenge(challengeId) { - // this is public API, M2M token is not needed + const token = yield getM2MToken(); + // this is public API, but some challege is not accessable so using m2m token const url = `${config.TC_API_V4_BASE_URL}/challenges/${challengeId}`; logger.info(`calling public challenge api ${url}`); - const res = yield request.get(url); + const res = yield request + .get(url) + .set('Authorization', `Bearer ${token}`) + .catch((err) => { + const errorDetails = _.get(err, 'message'); + throw new Error( + `Error in call public challenge api by id ${challengeId}` + + (errorDetails ? ' Server response: ' + errorDetails : '') + ); + }); if (!_.get(res, 'body.result.success')) { throw new Error(`Failed to get challenge by id ${challengeId}`); } From 42780fa4373c941172fe9f72d211b1fc8a4ab641 Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 24 Mar 2020 12:54:14 +0530 Subject: [PATCH 2/3] considering track prefrence from bacic profile --- src/common/broadcastAPIHelper.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/broadcastAPIHelper.js b/src/common/broadcastAPIHelper.js index 32c4988..13cd875 100644 --- a/src/common/broadcastAPIHelper.js +++ b/src/common/broadcastAPIHelper.js @@ -151,15 +151,18 @@ async function checkUserSkillsAndTracks(userId, bulkMessage, m) { /** * checking if user participated in specific challenges */ - let key = t.toLowerCase() - if (key === "develop") { + let key = t.toUpperCase()() + if (key === "DEVLOP") { trackMatch = uDevChallenges > 0 ? true : trackMatch - } else if (key === "design") { + } else if (key === "DESIGN") { trackMatch = uDesignChallenges > 0 ? true : trackMatch - } else if (key === "data_science") { + } else if (key === "DATA_SCIENCE") { trackMatch = uDSChallenges > 0 ? true : trackMatch } + // checking bacic member profile track preference + trackMatch = (_.indexOf(_.get(m[0], "tracks"), key) >= 0) ? true : trackMatch }) + } else { trackMatch = true // no condition, means allow for all } From 93282c04cdbe6ed13711373145ff303cb738b9fc Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 24 Mar 2020 13:16:28 +0530 Subject: [PATCH 3/3] typo --- src/common/broadcastAPIHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/broadcastAPIHelper.js b/src/common/broadcastAPIHelper.js index 13cd875..0ac38c6 100644 --- a/src/common/broadcastAPIHelper.js +++ b/src/common/broadcastAPIHelper.js @@ -151,7 +151,7 @@ async function checkUserSkillsAndTracks(userId, bulkMessage, m) { /** * checking if user participated in specific challenges */ - let key = t.toUpperCase()() + let key = t.toUpperCase() if (key === "DEVLOP") { trackMatch = uDevChallenges > 0 ? true : trackMatch } else if (key === "DESIGN") {