From 70eb31898372e29ae48c2d14bb88459fa2ab2685 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Mon, 13 Apr 2020 19:26:05 +0300 Subject: [PATCH 1/8] fix: resize email user photo size to 80 --- config/default.js | 3 +++ config/development.js | 3 +++ config/production.js | 3 +++ connect/constants.js | 3 +++ connect/notificationServices/email.js | 4 +++- 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 config/development.js create mode 100644 config/production.js diff --git a/config/default.js b/config/default.js index 9563efe..9d426a7 100644 --- a/config/default.js +++ b/config/default.js @@ -34,6 +34,9 @@ module.exports = { API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/notifications', TC_API_BASE_URL: process.env.TC_API_BASE_URL || '', + // CloudFront CDN URL. It's used to host and resize images like user avatars. + TC_CDN_URL: process.env.TC_CDN_URL || '', + // Configuration for generating machine to machine auth0 token. // The token will be used for calling another internal API. AUTH0_URL: process.env.AUTH0_URL, diff --git a/config/development.js b/config/development.js new file mode 100644 index 0000000..f4ad9c8 --- /dev/null +++ b/config/development.js @@ -0,0 +1,3 @@ +module.exports = { + TC_CDN_URL: 'https://d1aahxkjiobka8.cloudfront.net', +}; diff --git a/config/production.js b/config/production.js new file mode 100644 index 0000000..7ee53e0 --- /dev/null +++ b/config/production.js @@ -0,0 +1,3 @@ +module.exports = { + TC_CDN_URL: 'https://d2nl5eqipnb33q.cloudfront.net' +}; diff --git a/connect/constants.js b/connect/constants.js index 3768ac5..4022ef1 100644 --- a/connect/constants.js +++ b/connect/constants.js @@ -1,4 +1,7 @@ module.exports = { + // size for user photos in emails + EMAIL_USER_PHOTO_SIZE: 80, + // periods of time in cron format (node-cron) SCHEDULED_EVENT_PERIOD: { every10minutes: '*/10 * * * *', diff --git a/connect/notificationServices/email.js b/connect/notificationServices/email.js index 3d608fc..fbc1dd2 100644 --- a/connect/notificationServices/email.js +++ b/connect/notificationServices/email.js @@ -13,6 +13,7 @@ const { SCHEDULED_EVENT_PERIOD, SETTINGS_EMAIL_SERVICE_ID, ACTIVE_USER_STATUSES, + EMAIL_USER_PHOTO_SIZE, } = require('../constants'); const { EVENT_BUNDLES } = require('../events-config'); const helpers = require('../helpers'); @@ -236,7 +237,8 @@ function handler(topicName, messageJSON, notification) { projectId: messageJSON.projectId, authorHandle: notification.contents.userHandle, authorFullName: notification.contents.userFullName, - photoURL: notification.contents.photoURL, + photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` + + `?size=${EMAIL_USER_PHOTO_SIZE}`, type: notificationType, emailToAffectedUser: notification.contents.userEmail === userEmail, }, From b98052f9bdf6c0d19d2828b2be6624a47e128b98 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Tue, 14 Apr 2020 10:28:28 +0300 Subject: [PATCH 2/8] chore: remove config files with real values --- config/development.js | 3 --- config/production.js | 3 --- 2 files changed, 6 deletions(-) delete mode 100644 config/development.js delete mode 100644 config/production.js diff --git a/config/development.js b/config/development.js deleted file mode 100644 index f4ad9c8..0000000 --- a/config/development.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - TC_CDN_URL: 'https://d1aahxkjiobka8.cloudfront.net', -}; diff --git a/config/production.js b/config/production.js deleted file mode 100644 index 7ee53e0..0000000 --- a/config/production.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - TC_CDN_URL: 'https://d2nl5eqipnb33q.cloudfront.net' -}; From 6efe6ce2e29884e08aeb7f5be9098911bdd7439c Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 14 Apr 2020 13:53:07 +0530 Subject: [PATCH 3/8] Fixed typo --- emails/src/template.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emails/src/template.html b/emails/src/template.html index 14c2a4a..51c2b7b 100644 --- a/emails/src/template.html +++ b/emails/src/template.html @@ -87,7 +87,7 @@ - + From 57748f1fbead02cefbef415d3fa466afe37a9fec Mon Sep 17 00:00:00 2001 From: Sachin Maheshwari Date: Tue, 28 Apr 2020 17:57:02 +0530 Subject: [PATCH 4/8] adding country code filteration for broadcast --- .circleci/config.yml | 2 +- src/common/broadcastAPIHelper.js | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a72aa0..6c2bee9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -102,7 +102,7 @@ workflows: context : org-global filters: branches: - only: [dev, 'bug/community-notification'] + only: [dev, 'feature/broadcast2'] - "build-prod": context : org-global filters: diff --git a/src/common/broadcastAPIHelper.js b/src/common/broadcastAPIHelper.js index 0ac38c6..1feb73d 100644 --- a/src/common/broadcastAPIHelper.js +++ b/src/common/broadcastAPIHelper.js @@ -118,11 +118,13 @@ async function callApi(url, machineToken) { * @param {Object} m memberInfo * */ -async function checkUserSkillsAndTracks(userId, bulkMessage, m) { +async function filterOnMemberCondition(userId, bulkMessage, m) { try { const skills = _.get(bulkMessage, 'recipients.skills') const tracks = _.get(bulkMessage, 'recipients.tracks') - let skillMatch, trackMatch = false // default + const countryCodes = _.get(bulkMessage, 'recipients.countryCodes') + + let skillMatch, trackMatch, countryCodeMatch = false // default if (skills && skills.length > 0) { const ms = _.get(m[0], "skills") // get member skills const memberSkills = [] @@ -166,10 +168,23 @@ async function checkUserSkillsAndTracks(userId, bulkMessage, m) { } else { trackMatch = true // no condition, means allow for all } - const flag = (skillMatch && trackMatch) ? true : false + + if (countryCodes.length > 0) { + const mcc = _.get(m[0], 'competitionCountryCode') // get member country code + countryCodeMatch = false + if (_.indexOf(countryCodes, mcc) >= 0) { + countryCodeMatch = true + logger.info(`BroadcastMessageId: ${bulkMessage.id},` + + ` '${mcc}' country code matached for user id ${userId}`) + } + } else { + countryCodeMatch = true // no codition on country code + } + + const flag = (skillMatch && trackMatch && countryCodeMatch) ? true : false return flag } catch (e) { - throw new Error(`checkUserSkillsAndTracks() : ${e}`) + throw new Error(`filterOnMemberCondition() : ${e}`) } } @@ -232,7 +247,7 @@ async function checkUserGroup(userId, bulkMessage, userGroupInfo) { async function checkBroadcastMessageForUser(userId, bulkMessage, memberInfo, userGroupInfo) { return new Promise(function (resolve, reject) { Promise.all([ - checkUserSkillsAndTracks(userId, bulkMessage, memberInfo), + filterOnMemberCondition(userId, bulkMessage, memberInfo), checkUserGroup(userId, bulkMessage, userGroupInfo), ]).then((results) => { let flag = true // TODO need to be sure about default value From dc13318a8cf379753eac915259b4acf124fe7fbf Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 29 Apr 2020 12:57:13 +0300 Subject: [PATCH 5/8] fix: don't reassign event data --- connect/notificationServices/email.js | 29 ++++++++++++++------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/connect/notificationServices/email.js b/connect/notificationServices/email.js index fbc1dd2..7340a82 100644 --- a/connect/notificationServices/email.js +++ b/connect/notificationServices/email.js @@ -229,19 +229,7 @@ function handler(topicName, messageJSON, notification) { const categories = [`${config.ENV}:${eventType}`.toLowerCase()]; const eventMessage = { - data: { - name: user.firstName + ' ' + user.lastName, - handle: user.handle, - date: (new Date()).toISOString(), - projectName: notification.contents.projectName, - projectId: messageJSON.projectId, - authorHandle: notification.contents.userHandle, - authorFullName: notification.contents.userFullName, - photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` - + `?size=${EMAIL_USER_PHOTO_SIZE}`, - type: notificationType, - emailToAffectedUser: notification.contents.userEmail === userEmail, - }, + data: {}, recipients, version: 'v3', from: { @@ -250,8 +238,21 @@ function handler(topicName, messageJSON, notification) { }, categories, }; + // first we put `notification.contents` to the `data`, so we would reassign any values there + _.assign(eventMessage.data, notification.contents, { + name: user.firstName + ' ' + user.lastName, + handle: user.handle, + date: (new Date()).toISOString(), + projectName: notification.contents.projectName, + projectId: messageJSON.projectId, + authorHandle: notification.contents.userHandle, + authorFullName: notification.contents.userFullName, + photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` + + `?size=${EMAIL_USER_PHOTO_SIZE}`, + type: notificationType, + emailToAffectedUser: notification.contents.userEmail === userEmail, + }); eventMessage.data[eventMessage.data.type] = true; - _.assign(eventMessage.data, notification.contents); // message service may return tags // to understand if post notification is regarding phases or no, we will try to get phaseId from the tags From cb6534719729e7a3c3cdfd9f47f91d59f2dff6ab Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 29 Apr 2020 14:10:26 +0300 Subject: [PATCH 6/8] Revert "fix: don't reassign event data" This reverts commit dc13318a8cf379753eac915259b4acf124fe7fbf. --- connect/notificationServices/email.js | 29 +++++++++++++-------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/connect/notificationServices/email.js b/connect/notificationServices/email.js index 7340a82..fbc1dd2 100644 --- a/connect/notificationServices/email.js +++ b/connect/notificationServices/email.js @@ -229,7 +229,19 @@ function handler(topicName, messageJSON, notification) { const categories = [`${config.ENV}:${eventType}`.toLowerCase()]; const eventMessage = { - data: {}, + data: { + name: user.firstName + ' ' + user.lastName, + handle: user.handle, + date: (new Date()).toISOString(), + projectName: notification.contents.projectName, + projectId: messageJSON.projectId, + authorHandle: notification.contents.userHandle, + authorFullName: notification.contents.userFullName, + photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` + + `?size=${EMAIL_USER_PHOTO_SIZE}`, + type: notificationType, + emailToAffectedUser: notification.contents.userEmail === userEmail, + }, recipients, version: 'v3', from: { @@ -238,21 +250,8 @@ function handler(topicName, messageJSON, notification) { }, categories, }; - // first we put `notification.contents` to the `data`, so we would reassign any values there - _.assign(eventMessage.data, notification.contents, { - name: user.firstName + ' ' + user.lastName, - handle: user.handle, - date: (new Date()).toISOString(), - projectName: notification.contents.projectName, - projectId: messageJSON.projectId, - authorHandle: notification.contents.userHandle, - authorFullName: notification.contents.userFullName, - photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` - + `?size=${EMAIL_USER_PHOTO_SIZE}`, - type: notificationType, - emailToAffectedUser: notification.contents.userEmail === userEmail, - }); eventMessage.data[eventMessage.data.type] = true; + _.assign(eventMessage.data, notification.contents); // message service may return tags // to understand if post notification is regarding phases or no, we will try to get phaseId from the tags From eb38194e8cfec53c622143ed4b2d3e05224d5454 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 29 Apr 2020 14:12:16 +0300 Subject: [PATCH 7/8] fix: photo URL --- connect/notificationServices/email.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/connect/notificationServices/email.js b/connect/notificationServices/email.js index fbc1dd2..3b50afe 100644 --- a/connect/notificationServices/email.js +++ b/connect/notificationServices/email.js @@ -237,8 +237,6 @@ function handler(topicName, messageJSON, notification) { projectId: messageJSON.projectId, authorHandle: notification.contents.userHandle, authorFullName: notification.contents.userFullName, - photoURL: `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` - + `?size=${EMAIL_USER_PHOTO_SIZE}`, type: notificationType, emailToAffectedUser: notification.contents.userEmail === userEmail, }, @@ -252,6 +250,9 @@ function handler(topicName, messageJSON, notification) { }; eventMessage.data[eventMessage.data.type] = true; _.assign(eventMessage.data, notification.contents); + // set `photoURL` after we already applied `notification.contents`, so `photoURL` doesn't get overwritten + eventMessage.data.photoURL = `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}` + + `?size=${EMAIL_USER_PHOTO_SIZE}`; // message service may return tags // to understand if post notification is regarding phases or no, we will try to get phaseId from the tags From a47a3ec183172fc41a758815e915ba699b001494 Mon Sep 17 00:00:00 2001 From: Maksym Mykhailenko Date: Wed, 29 Apr 2020 14:42:40 +0300 Subject: [PATCH 8/8] chore: add TC_CDN_URL config variable --- connect/config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/connect/config.js b/connect/config.js index 48751c7..ec7304b 100644 --- a/connect/config.js +++ b/connect/config.js @@ -37,4 +37,5 @@ module.exports = { CONNECT_URL: process.env.CONNECT_URL || 'https://connect.topcoder-dev.com', ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || "https://accounts.topcoder-dev.com", + TC_CDN_URL: process.env.TC_CDN_URL, };
Connect is the world’s first project management crowdsorcing platform utilizing the power of Topcoder communities
Connect is the world’s first project management crowdsourcing platform utilizing the power of Topcoder communities
201 S Capitol Ave #1100
Indianapolis, IN 46225 United States