Skip to content

Commit 4969dd1

Browse files
author
sachin-maheshwari
authored
Merge pull request #192 from topcoder-platform/dev
Broadcast and "Connect" email template changes (image resizing)
2 parents 34e23e7 + 5eee152 commit 4969dd1

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ workflows:
102102
context : org-global
103103
filters:
104104
branches:
105-
only: [dev, 'bug/community-notification']
105+
only: [dev, 'feature/broadcast2']
106106
- "build-prod":
107107
context : org-global
108108
filters:

config/default.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.exports = {
3434
API_CONTEXT_PATH: process.env.API_CONTEXT_PATH || '/v5/notifications',
3535
TC_API_BASE_URL: process.env.TC_API_BASE_URL || '',
3636

37+
// CloudFront CDN URL. It's used to host and resize images like user avatars.
38+
TC_CDN_URL: process.env.TC_CDN_URL || '',
39+
3740
// Configuration for generating machine to machine auth0 token.
3841
// The token will be used for calling another internal API.
3942
AUTH0_URL: process.env.AUTH0_URL,

connect/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ module.exports = {
3737

3838
CONNECT_URL: process.env.CONNECT_URL || 'https://connect.topcoder-dev.com',
3939
ACCOUNTS_APP_URL: process.env.ACCOUNTS_APP_URL || "https://accounts.topcoder-dev.com",
40+
TC_CDN_URL: process.env.TC_CDN_URL,
4041
};

connect/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
2+
// size for user photos in emails
3+
EMAIL_USER_PHOTO_SIZE: 80,
4+
25
// periods of time in cron format (node-cron)
36
SCHEDULED_EVENT_PERIOD: {
47
every10minutes: '*/10 * * * *',

connect/notificationServices/email.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const {
1313
SCHEDULED_EVENT_PERIOD,
1414
SETTINGS_EMAIL_SERVICE_ID,
1515
ACTIVE_USER_STATUSES,
16+
EMAIL_USER_PHOTO_SIZE,
1617
} = require('../constants');
1718
const { EVENT_BUNDLES } = require('../events-config');
1819
const helpers = require('../helpers');
@@ -236,7 +237,6 @@ function handler(topicName, messageJSON, notification) {
236237
projectId: messageJSON.projectId,
237238
authorHandle: notification.contents.userHandle,
238239
authorFullName: notification.contents.userFullName,
239-
photoURL: notification.contents.photoURL,
240240
type: notificationType,
241241
emailToAffectedUser: notification.contents.userEmail === userEmail,
242242
},
@@ -250,6 +250,9 @@ function handler(topicName, messageJSON, notification) {
250250
};
251251
eventMessage.data[eventMessage.data.type] = true;
252252
_.assign(eventMessage.data, notification.contents);
253+
// set `photoURL` after we already applied `notification.contents`, so `photoURL` doesn't get overwritten
254+
eventMessage.data.photoURL = `${config.TC_CDN_URL}/avatar/${encodeURIComponent(notification.contents.photoURL)}`
255+
+ `?size=${EMAIL_USER_PHOTO_SIZE}`;
253256

254257
// message service may return tags
255258
// to understand if post notification is regarding phases or no, we will try to get phaseId from the tags

emails/src/template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
<td class="footer-space"></td>
8888
<td class="footer-content" align="center">
8989
<table>
90-
<tr><td>Connect is the world’s first project management crowdsorcing platform utilizing the power of Topcoder communities</td></tr>
90+
<tr><td>Connect is the world’s first project management crowdsourcing platform utilizing the power of Topcoder communities</td></tr>
9191
<tr class="empty-10"><td></td></tr>
9292
<tr><td>201 S Capitol Ave #1100</td></tr>
9393
<tr><td>Indianapolis, IN 46225 United States</td></tr>

src/common/broadcastAPIHelper.js

+20-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,13 @@ async function callApi(url, machineToken) {
118118
* @param {Object} m memberInfo
119119
*
120120
*/
121-
async function checkUserSkillsAndTracks(userId, bulkMessage, m) {
121+
async function filterOnMemberCondition(userId, bulkMessage, m) {
122122
try {
123123
const skills = _.get(bulkMessage, 'recipients.skills')
124124
const tracks = _.get(bulkMessage, 'recipients.tracks')
125-
let skillMatch, trackMatch = false // default
125+
const countryCodes = _.get(bulkMessage, 'recipients.countryCodes')
126+
127+
let skillMatch, trackMatch, countryCodeMatch = false // default
126128
if (skills && skills.length > 0) {
127129
const ms = _.get(m[0], "skills") // get member skills
128130
const memberSkills = []
@@ -166,10 +168,23 @@ async function checkUserSkillsAndTracks(userId, bulkMessage, m) {
166168
} else {
167169
trackMatch = true // no condition, means allow for all
168170
}
169-
const flag = (skillMatch && trackMatch) ? true : false
171+
172+
if (countryCodes.length > 0) {
173+
const mcc = _.get(m[0], 'competitionCountryCode') // get member country code
174+
countryCodeMatch = false
175+
if (_.indexOf(countryCodes, mcc) >= 0) {
176+
countryCodeMatch = true
177+
logger.info(`BroadcastMessageId: ${bulkMessage.id},` +
178+
` '${mcc}' country code matached for user id ${userId}`)
179+
}
180+
} else {
181+
countryCodeMatch = true // no codition on country code
182+
}
183+
184+
const flag = (skillMatch && trackMatch && countryCodeMatch) ? true : false
170185
return flag
171186
} catch (e) {
172-
throw new Error(`checkUserSkillsAndTracks() : ${e}`)
187+
throw new Error(`filterOnMemberCondition() : ${e}`)
173188
}
174189
}
175190

@@ -232,7 +247,7 @@ async function checkUserGroup(userId, bulkMessage, userGroupInfo) {
232247
async function checkBroadcastMessageForUser(userId, bulkMessage, memberInfo, userGroupInfo) {
233248
return new Promise(function (resolve, reject) {
234249
Promise.all([
235-
checkUserSkillsAndTracks(userId, bulkMessage, memberInfo),
250+
filterOnMemberCondition(userId, bulkMessage, memberInfo),
236251
checkUserGroup(userId, bulkMessage, userGroupInfo),
237252
]).then((results) => {
238253
let flag = true // TODO need to be sure about default value

0 commit comments

Comments
 (0)