@@ -17,10 +17,15 @@ const template = require(config.TEMPLATES.TEMPLATE_FILE_PATH)
17
17
* @returns {undefined }
18
18
*/
19
19
async function manageVanillaUser ( data ) {
20
- const { challengeId, action, handle : username } = data
20
+ const { challengeId, action, handle : username , role : projectRole } = data
21
21
logger . info ( `Managing users for challengeID=${ challengeId } ...` )
22
22
const { body : groups } = await vanillaClient . searchGroups ( challengeId )
23
23
const group = groups . length > 0 ? groups [ 0 ] : null
24
+
25
+ // Only members and copilots will receive notifications
26
+ const watch = ( ! projectRole || projectRole === constants . TOPCODER . PROJECT_ROLES . COPILOT ) ? 1 : 0
27
+ const follow = 1
28
+
24
29
if ( ! group ) {
25
30
throw new Error ( 'The group wasn\'t not found by challengeID' )
26
31
}
@@ -87,21 +92,13 @@ async function manageVanillaUser (data) {
87
92
await vanillaClient . updateUser ( vanillaUser . userID , userData )
88
93
}
89
94
90
- let categories = [ ]
91
- const { body : nestedCategories } = await vanillaClient . getCategoriesByParentUrlCode ( challengeId )
92
- categories = nestedCategories
93
-
94
- // Some group might not have nested categories
95
- if ( categories . length === 0 ) {
96
- const { body : parentCategory } = await vanillaClient . getCategoryByUrlcode ( challengeId )
97
- categories . push ( parentCategory )
98
- }
99
-
100
95
// Choose action to perform
101
96
switch ( action ) {
102
97
case constants . USER_ACTIONS . INVITE : {
103
98
await vanillaClient . addUserToGroup ( group . groupID , {
104
- userID : vanillaUser . userID
99
+ userID : vanillaUser . userID ,
100
+ watch : watch ,
101
+ follow : follow
105
102
} )
106
103
logger . info ( `The user '${ vanillaUser . name } ' was added to the group '${ group . name } '` )
107
104
break
@@ -259,7 +256,7 @@ async function createVanillaGroup (challenge) {
259
256
}
260
257
261
258
for ( const member of members ) {
262
- await manageVanillaUser ( { challengeId : challenge . id , action : constants . USER_ACTIONS . INVITE , handle : member . handle } )
259
+ await manageVanillaUser ( { challengeId : challenge . id , action : constants . USER_ACTIONS . INVITE , handle : member . handle , role : member . role } )
263
260
}
264
261
265
262
challengeDetailsDiscussion . url = `${ challengeCategory . url } `
0 commit comments