Skip to content

Commit 74297fb

Browse files
author
vikasrohit
authored
Merge pull request #66 from topcoder-platform/dev
Production Release: To support connect 2.4.6
2 parents 57cc4fc + 3bda4df commit 74297fb

31 files changed

+18299
-1509
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ workflows:
8282
- "build-dev":
8383
filters:
8484
branches:
85-
only: [dev]
85+
only: [dev, architectt1-feature/emailTemplatesClean]
8686
- "build-prod":
8787
filters:
8888
branches:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
log.txt
55
.DS_Store
66
dist
7+
src/emails/**/*.css

connect/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
ADMINISTRATOR_ROLE_ID: 1,
1818
// id of the BOT user which creates post with various events in discussions
1919
TCWEBSERVICE_ID: process.env.TCWEBSERVICE_ID || '22838965',
20+
CODERBOT_USER_ID: process.env.CODERBOT_USER_ID || 'CoderBot',
2021

2122
// Configuration for generating machine to machine auth0 token.
2223
// The token will be used for calling another internal API.
@@ -39,4 +40,6 @@ module.exports = {
3940
REPLY_EMAIL_DOMAIN: process.env.REPLY_EMAIL_DOMAIN,
4041
REPLY_EMAIL_FROM: process.env.REPLY_EMAIL_FROM,
4142
DEFAULT_REPLY_EMAIL: process.env.DEFAULT_REPLY_EMAIL,
43+
44+
CONNECT_URL: process.env.CONNECT_URL || 'https://connect.topcoder-dev.com',
4245
};

connect/connectNotificationServer.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
7575
const handle = matches[1] ? matches[1].toString() : matches[2].toString();
7676
notifications.push({
7777
userHandle: handle,
78-
newType: BUS_API_EVENT.CONNECT.MENTIONED_IN_POST,
78+
newType: BUS_API_EVENT.CONNECT.POST.MENTION,
7979
contents: {
8080
toUserHandle: true,
8181
},
@@ -85,12 +85,13 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
8585
// only one per userHandle
8686
notifications = _.uniqBy(notifications, 'userHandle');
8787

88-
return new Promise((resolve) => {
88+
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
8989
const handles = _.map(notifications, 'userHandle');
9090
if (handles.length > 0) {
9191
service.getUsersByHandle(handles).then((users) => {
9292
_.forEach(notifications, (notification) => {
93-
notification.userId = _.find(users, { handle: notification.userHandle }).userId.toString();
93+
const mentionedUser = _.find(users, { handle: notification.userHandle });
94+
notification.userId = mentionedUser ? mentionedUser.userId.toString() : notification.userHandle;
9495
});
9596
resolve(notifications);
9697
});
@@ -271,8 +272,9 @@ notificationServer.setConfig({ LOG_LEVEL: 'debug' });
271272
// it is defined as: function(topic, message, callback),
272273
// the topic is topic name,
273274
// the message is JSON event message,
275+
// logger object used to log in parent thread
274276
// the callback is function(error, userIds), where userIds is an array of user ids to receive notifications
275-
const handler = (topic, message, callback) => {
277+
const handler = (topic, message, logger, callback) => {
276278
const projectId = message.projectId;
277279
if (!projectId) {
278280
return callback(new Error('Missing projectId in the event message.'));
@@ -285,7 +287,9 @@ const handler = (topic, message, callback) => {
285287

286288
// filter out `notifications.connect.project.topic.created` events send by bot
287289
// because they create too much clutter and duplicate info
288-
if (topic === BUS_API_EVENT.CONNECT.TOPIC_CREATED && message.userId.toString() === config.TCWEBSERVICE_ID) {
290+
const botIds = [config.TCWEBSERVICE_ID, config.CODERBOT_USER_ID];
291+
if (topic === BUS_API_EVENT.CONNECT.TOPIC.CREATED && botIds.contains(message.userId.toString())) {
292+
logger.info(`Ignoring, to avoid noise, Bot topic ${topic}`);
289293
return callback(null, []);
290294
}
291295

@@ -328,11 +332,13 @@ const handler = (topic, message, callback) => {
328332
_.map(allNotifications, (notification) => {
329333
notification.version = eventConfig.version;
330334
notification.contents.projectName = project.name;
335+
notification.contents.timestamp = (new Date()).toISOString();
331336
// if found a user then add user handle
332337
if (users.length) {
333338
notification.contents.userHandle = users[0].handle;
334339
notification.contents.userFullName = `${users[0].firstName} ${users[0].lastName}`;
335340
notification.contents.userEmail = users[0].email;
341+
notification.contents.photoURL = users[0].photoURL;
336342
}
337343
});
338344
callback(null, allNotifications);
@@ -358,7 +364,10 @@ if (config.ENABLE_EMAILS) {
358364
notificationServer
359365
.initDatabase()
360366
.then(() => notificationServer.start())
361-
.catch((e) => console.log(e)); // eslint-disable-line no-console
367+
.catch((e) => {
368+
console.log(e); // eslint-disable-line no-console
369+
notificationServer.logger.error('Notification server errored out');
370+
});
362371

363372
// if no need to init database, then directly start the server:
364373
// notificationServer.start();

connect/constants.js

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,64 @@ module.exports = {
44
every10minutes: '*/10 * * * *',
55
hourly: '0 * * * *',
66
daily: '0 7 * * *', // every day at 7am
7+
everyOtherDay: '0 7 */2 * *', // every other day at 7 am
78
weekly: '0 7 * * 6', // every Saturday at 7am
89
},
910

1011
// email service id for settings
1112
SETTINGS_EMAIL_SERVICE_ID: 'email',
13+
SETTINGS_EMAIL_BUNDLING_SERVICE_ID: 'emailBundling',
1214

1315
BUS_API_EVENT: {
1416
CONNECT: {
15-
TOPIC_CREATED: 'notifications.connect.project.topic.created',
16-
TOPIC_DELETED: 'notifications.connect.project.topic.deleted',
17-
POST_CREATED: 'notifications.connect.project.post.created',
18-
POST_UPDATED: 'notifications.connect.project.post.edited',
19-
POST_DELETED: 'notifications.connect.project.post.deleted',
20-
MENTIONED_IN_POST: 'notifications.connect.project.post.mention',
17+
POST: {
18+
UPDATED: 'notifications.connect.project.post.edited',
19+
CREATED: 'notifications.connect.project.post.created',
20+
DELETED: 'notifications.connect.project.post.deleted',
21+
MENTION: 'notifications.connect.project.post.mention',
22+
},
23+
MEMBER: {
24+
JOINED: 'notifications.connect.project.member.joined',
25+
LEFT: 'notifications.connect.project.member.left',
26+
REMOVED: 'notifications.connect.project.member.removed',
27+
MANAGER_JOINED: 'notifications.connect.project.member.managerJoined',
28+
COPILOT_JOINED: 'notifications.connect.project.member.copilotJoined',
29+
ASSIGNED_AS_OWNER: 'notifications.connect.project.member.assignedAsOwner',
30+
},
31+
PROJECT: {
32+
ACTIVE: 'notifications.connect.project.active',
33+
APPROVED: 'notifications.connect.project.approved',
34+
CANCELED: 'notifications.connect.project.canceled',
35+
COMPLETED: 'notifications.connect.project.completed',
36+
CREATED: 'notifications.connect.project.created',
37+
FILE_UPLOADED: 'notifications.connect.project.fileUploaded',
38+
LINK_CREATED: 'notifications.connect.project.linkCreated',
39+
PAUSED: 'notifications.connect.project.paused',
40+
SUBMITTED_FOR_REVIEW: 'notifications.connect.project.submittedForReview',
41+
SPECIFICATION_MODIFIED: 'connect.action.project.product.update.spec',
42+
},
43+
PROJECT_PLAN: {
44+
READY: 'connect.action.project.plan.ready',
45+
MODIFIED: 'connect.action.project.plan.updated',
46+
PROGRESS_UPDATED: 'connect.action.project.updated.progress',
47+
PHASE_ACTIVATED: 'notifications.connect.project.phase.transition.active',
48+
PHASE_COMPLETED: 'notifications.connect.project.phase.transition.completed',
49+
PHASE_PAYMENT_UPDATED: 'notifications.connect.project.phase.update.payment',
50+
PHASE_PROGRESS_UPDATED: 'notifications.connect.project.phase.update.progress',
51+
PHASE_SCOPE_UPDATED: 'notifications.connect.project.phase.update.scope',
52+
MILESTONE_ACTIVATED: 'connect.action.timeline.milestone.transition.active',
53+
MILESTONE_COMPLETED: 'connect.action.timeline.milestone.transition.completed',
54+
WAITING_FOR_CUSTOMER_INPUT: 'connect.action.timeline.milestone.waiting.customer',
55+
},
56+
TOPIC: {
57+
CREATED: 'notifications.connect.project.topic.created',
58+
DELETED: 'notifications.connect.project.topic.deleted',
59+
},
2160
},
2261
EMAIL: {
23-
TOPIC_CREATED: 'notifications.action.email.connect.project.topic.created',
24-
POST_CREATED: 'notifications.action.email.connect.project.post.created',
25-
MENTIONED_IN_POST: 'notifications.action.email.connect.project.post.mention',
26-
BUNDLED: 'notifications.action.email.connect.project.bundled',
62+
// TODO: after a proper named email topic is created, this is being used as the email event's topic
63+
GENERAL: 'notifications.action.email.connect.project.notifications.generic',
64+
BUNDLED: 'notifications.action.email.connect.project.notifications.bundled',
2765
},
2866
},
2967
};

0 commit comments

Comments
 (0)