Skip to content

Commit 5bcb288

Browse files
author
vikasrohit
authored
Merge pull request #79 from topcoder-platform/dev
Support release for Connect Production release 2.4.8
2 parents c3382be + 66329d4 commit 5bcb288

File tree

7 files changed

+129
-8
lines changed

7 files changed

+129
-8
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1-
# TOPCODER NOTIFICATIONS SERIES - NOTIFICATIONS SERVER
2-
1+
# TOPCODER NOTIFICATIONS
2+
3+
## Description
4+
This repository hosts the API and processors for enabling notifications in various topcoder apps. Currently it is limited to provide this facility to the [Connect](https://github.com/appirio-tech/connect-app) application. Theoretcially, it is a generic framework and application which could be used for sending and consuming notificaitons by any other topcoder app. In very simple words to send notifications using this application:
5+
6+
1. Send an event to bus
7+
2. Listen that event in tc-notifications
8+
3. There is a config in tc-notifications for each event it want to listen and we can specify rules who are the target users to whom we should send notifications for this event
9+
4. By default it saves all notifications which are generated after parsing the rules specified in step 3 and these are the treated web notifications which we show in the app directly
10+
5. Then there is option to add notification handlers where we get all these notifications one by one and we can process them further for more channels e.g. we send notification emails for each of notification generated
11+
6. When one wants to show the notifications, we use the notifications api (hosted inside the tc-notifications itself as separate service) to fetch notifications, mark notifications read or unread etc.
12+
13+
tc-notifications (as a standard nodejs app) provides generic framework around notifications, it does not have config (used in step 3 of previous list) for specific apps. So, to have config for specific apps, we have to start the notification consumers per app e.g. for connect, we have a folder [`connect`](https://github.com/topcoder-platform/tc-notifications/blob/dev/connect) which hosts start script to start notification consumers with connect specific configuration ([`events-config.js`](https://github.com/topcoder-platform/tc-notifications/blob/dev/connect/events-config.js)). It also adds email notification service which sends emails for notifications as per notification settings (coming from common framework laid by tc-notifications) for the user.
14+
15+
### Steps needed to enable other apps to use the notifications are:
16+
1. Have a separate start up script (in a new folder at the root of the repo) for the concerned app. I would call this as notification consumer/processor.
17+
2. Write [`events-config.js`](https://github.com/topcoder-platform/tc-notifications/blob/dev/connect/events-config.js) (name is not important, we have to read this file in the start up script written in step 1) for app specific notifications
18+
3. Write additional notification services (eg. if you want to send email or slack or any other notification) and add them to startup script
19+
4. Specify a node script in package.json to launch the start up script written in step 1
20+
5. Either add deployment for this new notification consumer/processor in existing deployment script (if you want to host the processor as separate service in the same ECS cluster) or write a new script if you want to keep the deployment separate.
321

422
## Dependencies
523
- nodejs https://nodejs.org/en/ (v6+)

connect/connectNotificationServer.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,9 @@ const handler = (topic, message, logger, callback) => {
323323

324324
// if message has userId such messages will likely need userHandle and user full name
325325
// so let's get it
326+
const ids = [message.initiatorUserId];
326327
if (message.userId) {
327-
const ids = [message.userId];
328+
ids.push(message.userId);
328329
return service.getUsersById(ids);
329330
}
330331
return [];
@@ -335,10 +336,15 @@ const handler = (topic, message, logger, callback) => {
335336
notification.contents.timestamp = (new Date()).toISOString();
336337
// if found a user then add user handle
337338
if (users.length) {
338-
notification.contents.userHandle = users[0].handle;
339-
notification.contents.userFullName = `${users[0].firstName} ${users[0].lastName}`;
340-
notification.contents.userEmail = users[0].email;
341-
notification.contents.photoURL = users[0].photoURL;
339+
const affectedUser = _.find(users, u => u.userId === message.userId);
340+
const initiatorUser = _.find(users, u => u.userId === message.initiatorUserId);
341+
if (affectedUser) {
342+
notification.contents.userHandle = affectedUser.handle;
343+
notification.contents.userFullName = `${affectedUser.firstName} ${affectedUser.lastName}`;
344+
notification.contents.userEmail = affectedUser.email;
345+
notification.contents.photoURL = affectedUser.photoURL;
346+
}
347+
notification.contents.initiatorUser = initiatorUser;
342348
}
343349
});
344350
callback(null, allNotifications);

connect/constants.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module.exports = {
2828
MANAGER_JOINED: 'notifications.connect.project.member.managerJoined',
2929
COPILOT_JOINED: 'notifications.connect.project.member.copilotJoined',
3030
ASSIGNED_AS_OWNER: 'notifications.connect.project.member.assignedAsOwner',
31+
INVITE_CREATED: 'notifications.connect.project.member.invite.created',
32+
INVITE_UPDATED: 'notifications.connect.project.member.invite.updated',
3133
},
3234
PROJECT: {
3335
ACTIVE: 'notifications.connect.project.active',

connect/events-config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ const EVENTS = [
103103
}, {
104104
type: BUS_API_EVENT.CONNECT.MEMBER.MANAGER_JOINED,
105105
projectRoles: [PROJECT_ROLE_OWNER, PROJECT_ROLE_COPILOT, PROJECT_ROLE_MANAGER],
106+
}, {
107+
type: BUS_API_EVENT.CONNECT.MEMBER.INVITE_CREATED,
108+
projectRoles: [],
109+
toUserHandle: true,
106110
},
107111

108112
// Project activity
@@ -255,6 +259,7 @@ const EVENT_BUNDLES = {
255259
BUS_API_EVENT.CONNECT.MEMBER.LEFT,
256260
BUS_API_EVENT.CONNECT.MEMBER.MANAGER_JOINED,
257261
BUS_API_EVENT.CONNECT.MEMBER.REMOVED,
262+
BUS_API_EVENT.CONNECT.MEMBER.INVITE_CREATED,
258263
],
259264
},
260265
PROJECT_PLAN: {

connect/notificationServices/email.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ function handler(topicName, messageJSON, notification) {
233233
authorFullName: notification.contents.userFullName,
234234
photoURL: notification.contents.photoURL,
235235
type: notificationType,
236+
emailToAffectedUser: notification.contents.userEmail === userEmail,
236237
},
237238
recipients,
238239
version:"v3",
@@ -291,6 +292,19 @@ function handler(topicName, messageJSON, notification) {
291292
bundlePeriod = bundlePeriod && bundlePeriod.trim().length > 0 ? bundlePeriod : null;
292293
// if bundling is not explicitly set and the event is not a messaging event, assume bundling enabled
293294
if (!bundlePeriod && !messagingEvent) {
295+
// finds the event category for the notification type
296+
let eventBundleCategory = _.findKey(EVENT_BUNDLES, b => b.types && b.types.indexOf(notificationType) !== -1);
297+
if (eventBundleCategory) {
298+
const eventBundle = EVENT_BUNDLES[eventBundleCategory];
299+
// if we find the event category for the notification, use the bundle settings from the first event
300+
if (eventBundle && eventBundle.types && eventBundle.types.length) {
301+
const firstEvtInBundle = eventBundle.types[0];
302+
const firstEvtBundleSettingPath = `notifications['${firstEvtInBundle}'].${SETTINGS_EMAIL_SERVICE_ID}.bundlePeriod`
303+
let firstEvtBundlePeriod = _.get(settings, firstEvtBundleSettingPath);
304+
bundlePeriod = firstEvtBundlePeriod
305+
logger.debug('Assuming bundle period of first event in the event category=>', bundlePeriod);
306+
}
307+
}
294308
// if bundle period is not set, assume it to be daily for default case
295309
bundlePeriod = !bundlePeriod ? 'daily' : bundlePeriod;
296310
}

emails/src/partials/invites.html

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{{#if [EMAIL_INVITES]}}
2+
3+
<link rel="stylesheet" type="text/css" href="../styles/main.scss">
4+
5+
<tr class="post-head">
6+
<td class="main-td">
7+
<table class="main-child">
8+
<tr>
9+
<td class="empty-child-one"></td>
10+
<td class="comment-box"><img src="https://image.ibb.co/etWM7J/comment.jpg" alt="IMG"></td>
11+
<td class="empty-child-two"></td>
12+
<td>
13+
<strong>{{title}}</a>.
14+
</td>
15+
</tr>
16+
</table>
17+
</td>
18+
</tr>
19+
<tr class="empty-20">
20+
<td class="main-td">
21+
<table class="main-child">
22+
<tr><td></td></tr>
23+
</table>
24+
</td>
25+
</tr>
26+
27+
28+
<tr class="post-details">
29+
<td class="main-td">
30+
<table class="main-child">
31+
<tr>
32+
<td class="empty-child-one"></td>
33+
<td>You are invited to join the <strong>{{projectName}}</strong> on Topcoder Connect. To join the project, please register for a Topcoder account using <strong>Register</strong> button below.</td>
34+
</tr>
35+
</table>
36+
</td>
37+
</tr>
38+
39+
40+
<tr class="empty-50">
41+
<td class="main-td">
42+
<table class="main-child">
43+
<tr><td></td></tr>
44+
</table>
45+
</td>
46+
</tr>
47+
<tr class="button-row button-one">
48+
<td class="main-td">
49+
<table class="main-child">
50+
<tr>
51+
<td class="empty-child-one"></td>
52+
<td class="second-child" align="center">
53+
<a href="{{@root.accountsAppURL}}/connect/registration?retUrl={{@root.connectURL}}/projects/{{projectId}}">
54+
Register
55+
</a>
56+
</td>
57+
<td class="empty-child-one"></td>
58+
</tr>
59+
</table>
60+
</td>
61+
</tr>
62+
<tr class="empty-20">
63+
<td class="main-td">
64+
<table class="main-child">
65+
<tr><td></td></tr>
66+
</table>
67+
</td>
68+
</tr>
69+
{{/if}}

emails/src/partials/project-team.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,21 @@
4545
<strong>{{userFullName}}</strong> joined the project as Manager
4646
{{/if}}
4747
{{#if [notifications.connect.project.member.removed]}}
48-
<strong>{{userFullName}}</strong> left the project
48+
{{#if [emailToAffectedUser]}}
49+
You are removed from the project
50+
{{else}}
51+
<strong>{{userFullName}}</strong> left the project
52+
{{/if}}
4953
{{/if}}
5054
{{#if [notifications.connect.project.member.left]}}
5155
<strong>{{userFullName}}</strong> left the project
5256
{{/if}}
5357
{{#if [notifications.connect.project.member.joined]}}
5458
<strong>{{userFullName}}</strong> joined the project
5559
{{/if}}
60+
{{#if [notifications.connect.project.member.invite.created]}}
61+
Hi <strong>{{userFullName}}</strong>, you are invited to join the project {{projectName}}. Please click on the button ("View project on Connect") below to join.
62+
{{/if}}
5663
</td>
5764
</tr>
5865
</table>

0 commit comments

Comments
 (0)