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/broadcastAPIHelper.js b/src/common/broadcastAPIHelper.js index 32c4988..0ac38c6 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 } 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}`); }