Skip to content

Commit 8c86aaa

Browse files
authored
Copilot workflow changes (#89)
* copilot workflow changes * rename events * fix lint
1 parent 4b09fef commit 8c86aaa

File tree

6 files changed

+84
-10
lines changed

6 files changed

+84
-10
lines changed

connect/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = {
1313
// These variables are currently being used to retrieve above role members using API V3 `/roles` endpoint.
1414
// As soon as this endpoint is replaced with more suitable one, these variables has to be removed if no need anymore.
1515
CONNECT_MANAGER_ROLE_ID: 8,
16+
CONNECT_COPILOT_MANAGER_ROLE_ID: 113,
1617
CONNECT_ACCOUNT_MANAGER_ROLE_ID: 114,
1718
CONNECT_COPILOT_ROLE_ID: 4,
1819
ADMINISTRATOR_ROLE_ID: 1,

connect/connectNotificationServer.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,34 @@ const getNotificationsForMentionedUser = (eventConfig, content) => {
101101
});
102102
};
103103

104+
/**
105+
* Get notifications for users obtained from originator
106+
*
107+
* @param {Object} eventConfig event configuration
108+
* @param {String} originator originator userId
109+
*
110+
* @return {Promise} resolves to a list of notifications
111+
*/
112+
const getNotificationsForOriginator = (eventConfig, originator) => {
113+
// if event doesn't have to be notified to originator, just ignore
114+
if (!eventConfig.originator) {
115+
return Promise.resolve([]);
116+
}
117+
118+
// if we have to send notification to the originator,
119+
// but it's not provided in the message, then throw error
120+
if (!originator) {
121+
return Promise.reject(new Error('Missing originator in the event message.'));
122+
}
123+
124+
return Promise.resolve([{
125+
userId: originator.toString(),
126+
contents: {
127+
originator: true,
128+
},
129+
}]);
130+
};
131+
104132
/**
105133
* Get project members notifications
106134
*
@@ -307,6 +335,7 @@ const handler = (topic, message, logger, callback) => {
307335
// - check that event has everything required or throw error
308336
getNotificationsForTopicStarter(eventConfig, message.topicId),
309337
getNotificationsForUserId(eventConfig, message.userId),
338+
getNotificationsForOriginator(eventConfig, message.originator),
310339
getNotificationsForMentionedUser(eventConfig, message.postContent),
311340
getProjectMembersNotifications(eventConfig, project),
312341
getTopCoderMembersNotifications(eventConfig),
@@ -321,8 +350,8 @@ const handler = (topic, message, logger, callback) => {
321350
)).then((notifications) => {
322351
allNotifications = _.filter(notifications, notification => notification.userId !== `${message.initiatorUserId}`);
323352

324-
if (eventConfig.includeUsers && message[eventConfig.includeUsers] && message[eventConfig.includeUsers].length>0){
325-
allNotifications = _.filter(allNotifications, notification => message[eventConfig.includeUsers].contains(notification.userId));
353+
if (eventConfig.includeUsers && message[eventConfig.includeUsers] && message[eventConfig.includeUsers].length > 0) {
354+
allNotifications = _.filter(allNotifications, notification => message[eventConfig.includeUsers].includes(notification.userId));
326355
}
327356

328357
// now let's retrieve some additional data

connect/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ module.exports = {
3030
ASSIGNED_AS_OWNER: 'notifications.connect.project.member.assignedAsOwner',
3131
INVITE_CREATED: 'notifications.connect.project.member.invite.created',
3232
INVITE_UPDATED: 'notifications.connect.project.member.invite.updated',
33+
INVITE_REQUESTED: 'notifications.connect.project.member.invite.requested',
34+
INVITE_APPROVED: 'notifications.connect.project.member.invite.approved',
35+
INVITE_REJECTED: 'notifications.connect.project.member.invite.rejected',
3336
},
3437
PROJECT: {
3538
ACTIVE: 'notifications.connect.project.active',

connect/events-config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ const PROJECT_ROLE_RULES = {
2323
// TopCoder roles
2424
const ROLE_CONNECT_COPILOT = 'Connect Copilot';
2525
const ROLE_CONNECT_MANAGER = 'Connect Manager';
26+
const ROLE_CONNECT_COPILOT_MANAGER = 'Connect Copilot Manager';
2627
const ROLE_CONNECT_ACCOUNT_MANAGER = 'Connect Account Manager';
2728
const ROLE_ADMINISTRATOR = 'administrator';
2829

2930
// TopCoder role rules
3031
const TOPCODER_ROLE_RULES = {
3132
[ROLE_CONNECT_COPILOT]: { id: config.CONNECT_COPILOT_ROLE_ID },
3233
[ROLE_CONNECT_MANAGER]: { id: config.CONNECT_MANAGER_ROLE_ID },
34+
[ROLE_CONNECT_COPILOT_MANAGER]: { id: config.CONNECT_COPILOT_MANAGER_ROLE_ID },
3335
[ROLE_CONNECT_ACCOUNT_MANAGER]: { id: config.CONNECT_ACCOUNT_MANAGER_ROLE_ID },
3436
[ROLE_ADMINISTRATOR]: { id: config.ADMINISTRATOR_ROLE_ID },
3537
};
@@ -112,6 +114,16 @@ const EVENTS = [
112114
type: BUS_API_EVENT.CONNECT.MEMBER.INVITE_CREATED,
113115
projectRoles: [],
114116
toUserHandle: true,
117+
}, {
118+
type: BUS_API_EVENT.CONNECT.MEMBER.INVITE_REQUESTED,
119+
topcoderRoles: [ROLE_CONNECT_COPILOT_MANAGER],
120+
}, {
121+
type: BUS_API_EVENT.CONNECT.MEMBER.INVITE_APPROVED,
122+
toUserHandle: true,
123+
originator: true
124+
}, {
125+
type: BUS_API_EVENT.CONNECT.MEMBER.INVITE_REJECTED,
126+
originator: true
115127
},
116128

117129
// Project activity
@@ -268,6 +280,9 @@ const EVENT_BUNDLES = {
268280
BUS_API_EVENT.CONNECT.MEMBER.MANAGER_JOINED,
269281
BUS_API_EVENT.CONNECT.MEMBER.REMOVED,
270282
BUS_API_EVENT.CONNECT.MEMBER.INVITE_CREATED,
283+
BUS_API_EVENT.CONNECT.MEMBER.INVITE_REQUESTED,
284+
BUS_API_EVENT.CONNECT.MEMBER.INVITE_APPROVED,
285+
BUS_API_EVENT.CONNECT.MEMBER.INVITE_REJECTED,
271286
],
272287
},
273288
PROJECT_PLAN: {

docs/tc-notification-server-api.postman_collection.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"description": "",
2424
"auth": null,
2525
"events": null,
26-
"collection": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
26+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
2727
"folder": null,
2828
"order": [
2929
"1b3b6480-ea94-4027-8898-f82f28e2bea6",
@@ -40,6 +40,7 @@
4040
"requests": [
4141
{
4242
"id": "19332a51-03e8-4f5c-8f85-4d28d6dfe6f4",
43+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
4344
"name": "getSettings",
4445
"url": "{{URL}}/settings",
4546
"description": "",
@@ -71,6 +72,7 @@
7172
},
7273
{
7374
"id": "1b3b6480-ea94-4027-8898-f82f28e2bea6",
75+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
7476
"name": "listNotifications - invalid read filter",
7577
"url": "{{URL}}/list?offset=0&limit=20&type=notifications.connect.project.updated&read=yes",
7678
"description": "",
@@ -131,6 +133,7 @@
131133
},
132134
{
133135
"id": "543cab06-2c7d-4aed-8cf3-0808463254d5",
136+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
134137
"name": "markAllRead",
135138
"url": "{{URL}}/read",
136139
"description": "",
@@ -162,6 +165,7 @@
162165
},
163166
{
164167
"id": "59fc9f2b-28c5-4cff-b21b-11ab51bf67d8",
168+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
165169
"name": "getSettings - invalid token",
166170
"url": "{{URL}}/settings",
167171
"description": "",
@@ -193,6 +197,7 @@
193197
},
194198
{
195199
"id": "76779830-a8a4-4636-8c03-1801b3d1863d",
200+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
196201
"name": "markAsRead",
197202
"url": "{{URL}}/1/read",
198203
"description": "",
@@ -226,6 +231,7 @@
226231
"id": "cb2299a5-dac7-4c40-80c4-7b1694138354",
227232
"name": "TC API - get project",
228233
"url": "https://api.topcoder-dev.com/v4/projects/1936",
234+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
229235
"description": "",
230236
"data": [],
231237
"dataMode": "raw",
@@ -339,7 +345,7 @@
339345
],
340346
"cookies": [],
341347
"request": "cb2299a5-dac7-4c40-80c4-7b1694138354",
342-
"collection": "3f30c4e3-3b7a-491b-bdb2-6629d081a452"
348+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452"
343349
}
344350
],
345351
"rawModeData": "",
@@ -351,6 +357,7 @@
351357
"name": "markAsRead - not found",
352358
"url": "{{URL}}/1111111/read",
353359
"description": "",
360+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
354361
"data": [],
355362
"dataMode": "raw",
356363
"headerData": [
@@ -380,6 +387,7 @@
380387
{
381388
"id": "d293d2c5-230d-4f34-8c97-1adc1f2f89b4",
382389
"name": "listNotifications - invalid limit",
390+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
383391
"url": "{{URL}}/list?offset=0&limit=abc&type=notifications.connect.project.updated",
384392
"description": "",
385393
"data": [],
@@ -441,6 +449,7 @@
441449
"id": "d57ba947-a5e7-410a-b978-76882f33c86e",
442450
"name": "updateSettings",
443451
"url": "{{URL}}/settings",
452+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
444453
"description": "",
445454
"data": [],
446455
"dataMode": "raw",
@@ -471,6 +480,7 @@
471480
{
472481
"id": "da23d550-55b3-4f7d-9131-735956d62f6d",
473482
"name": "markAllRead - missing token",
483+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
474484
"url": "{{URL}}/read",
475485
"description": "",
476486
"data": [],
@@ -495,6 +505,7 @@
495505
},
496506
{
497507
"id": "f2246cf7-7aae-4ea0-9d92-1d932d340302",
508+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
498509
"name": "updateSettings - invalid body",
499510
"url": "{{URL}}/settings",
500511
"description": "",
@@ -527,6 +538,7 @@
527538
{
528539
"id": "f3f3a847-46f6-4059-b167-b436078fb112",
529540
"name": "listNotifications - invalid offset",
541+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
530542
"url": "{{URL}}/list?offset=-1&limit=20&type=notifications.connect.project.updated",
531543
"description": "",
532544
"data": [],
@@ -586,6 +598,7 @@
586598
},
587599
{
588600
"id": "fce69847-5bf8-4b07-bcaf-6352db4ba923",
601+
"collectionId": "3f30c4e3-3b7a-491b-bdb2-6629d081a452",
589602
"name": "listNotifications",
590603
"url": "{{URL}}/list?offset=0&limit=20",
591604
"description": "",
@@ -645,4 +658,4 @@
645658
"pathVariables": {}
646659
}
647660
]
648-
}
661+
}

emails/src/partials/project-team.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<td class="main-td">
2222
<table class="main-child">
2323
<tr><td></td></tr>
24-
</table>
24+
</table>
2525
</td>
2626
</tr>
2727

@@ -60,12 +60,25 @@
6060
{{#if [notifications.connect.project.member.invite.created]}}
6161
Hi <strong>{{userFullName}}</strong>, you are invited to join the project {{projectName}}. Please click on the button ("View project on Connect") below to join.
6262
{{/if}}
63+
{{#if [notifications.connect.project.member.invite.requested]}}
64+
You are requested to add <strong>{{userFullName}}</strong> as a copilot
65+
{{/if}}
66+
{{#if [notifications.connect.project.member.invite.approved]}}
67+
{{#if [originator]}}
68+
Your request to add invite the member was approved
69+
{{else}}
70+
Hi <strong>{{userFullName}}</strong>, you are added as a copilot
71+
{{/if}}
72+
{{/if}}
73+
{{#if [notifications.connect.project.member.invite.rejected]}}
74+
Your request to add the member was refused
75+
{{/if}}
6376
</td>
6477
</tr>
6578
</table>
6679
</td>
6780
</tr>
68-
</table>
81+
</table>
6982
</td>
7083
</tr>
7184
{{/each}}
@@ -76,7 +89,7 @@
7689
<td class="main-td">
7790
<table class="main-child">
7891
<tr><td></td></tr>
79-
</table>
92+
</table>
8093
</td>
8194
</tr>
8295
<tr class="button-row button-one">
@@ -98,7 +111,7 @@
98111
<td class="main-td">
99112
<table class="main-child">
100113
<tr><td></td></tr>
101-
</table>
114+
</table>
102115
</td>
103116
</tr>
104-
{{/if}}
117+
{{/if}}

0 commit comments

Comments
 (0)