Skip to content

Commit 6ccfe66

Browse files
authored
Merge pull request #73 from topcoder-platform/develop
v1.9
2 parents ad017be + d6efcd9 commit 6ccfe66

File tree

3 files changed

+70
-13
lines changed

3 files changed

+70
-13
lines changed

config/template.json

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
"group": {
1616
"name": "${ challenge.name }",
1717
"description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.",
18+
"selfServiceDescription": "Welcome to ${ challenge.name } Forum.",
1819
"privacy": "secret",
1920
"type": "challenge"
2021
},
2122
"categories": [
2223
{
2324
"name": "Code Documents",
25+
"selfService": false,
2426
"urlcode": "${ challenge.id }-documents",
2527
"discussions": [
2628
{
@@ -39,6 +41,7 @@
3941
},
4042
{
4143
"name": "Code Questions",
44+
"selfService": false,
4245
"urlcode": "${ challenge.id }-questions",
4346
"discussions": [
4447
{
@@ -48,6 +51,13 @@
4851
"closed": 0
4952
}
5053
]
54+
},
55+
{
56+
"name": "General Questions",
57+
"selfService": true,
58+
"urlcode": "${ challenge.id }-questions",
59+
"discussions": [
60+
]
5161
}
5262
]
5363
},
@@ -58,12 +68,14 @@
5868
"group": {
5969
"name": "${ challenge.name }",
6070
"description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.",
71+
"selfServiceDescription": "Welcome to ${ challenge.name } Forum.",
6172
"privacy": "secret",
6273
"type": "challenge"
6374
},
6475
"categories": [
6576
{
6677
"name": "Code Documents",
78+
"selfService": false,
6779
"urlcode": "${ challenge.id }-documents",
6880
"discussions": [
6981
{
@@ -82,6 +94,7 @@
8294
},
8395
{
8496
"name": "Code Questions",
97+
"selfService": false,
8598
"urlcode": "${ challenge.id }-questions",
8699
"discussions": [
87100
{
@@ -91,6 +104,13 @@
91104
"closed": 0
92105
}
93106
]
107+
},
108+
{
109+
"name": "General Questions",
110+
"selfService": true,
111+
"urlcode": "${ challenge.id }-questions",
112+
"discussions": [
113+
]
94114
}
95115
]
96116
}
@@ -107,6 +127,7 @@
107127
"group": {
108128
"name": "${ challenge.name }",
109129
"description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.",
130+
"selfServiceDescription": "Welcome to ${ challenge.name } Forum.",
110131
"privacy": "secret",
111132
"type": "challenge"
112133
},
@@ -115,25 +136,29 @@
115136
"title": "Spec Review Discussion",
116137
"body": "Spec Review Discussion",
117138
"announce": 0,
118-
"closed": 0
139+
"closed": 0,
140+
"selfService": false
119141
},
120142
{
121143
"title": "Please give us feedback on this challenge!",
122144
"body": "Hi Competitors,\n\nAt topcoder, we are always trying to continuously improve how we are running competitions and tasks for our competitors. Part of this involves getting feedback from you on how well our tasks and challenges are being managed.\n\nPlease take 2-3 minutes to fill out this survey. The results will be used to identify areas of improvement, follow on training, procedural changes, etc. \n\n https://www.surveymonkey.com/r/3SYYTHP?Challenge_ID=<%- challenge.id %>",
123145
"announce": 0,
124-
"closed": 0
146+
"closed": 0,
147+
"selfService": false
125148
},
126149
{
127150
"title": "Welcome!",
128151
"body": "Please read the requirements carefully. If you have questions, please let me know, I'll be glad to help you.",
129152
"announce": 0,
130-
"closed": 0
153+
"closed": 0,
154+
"selfService": false
131155
},
132156
{
133157
"title": "Challenge Overview",
134158
"body": "[Back to Challenge Details page](<%- challenge.url %>)\n<% _.forEach(challenge.prizeSets, function(prizeSet) { %>* <%- prizeSet.type %>: <% _.forEach(prizeSet.prizes, function(prize) { %><%- prize.value %>$ <% }) %>\n<% }); %>",
135159
"announce": 1,
136-
"closed": 1
160+
"closed": 1,
161+
"selfService": false
137162
}
138163
]
139164
}
@@ -150,12 +175,14 @@
150175
"group": {
151176
"name": "${ challenge.name }",
152177
"description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.",
178+
"selfServiceDescription": "Welcome to ${ challenge.name } Forum.",
153179
"privacy": "secret",
154180
"type": "challenge"
155181
},
156182
"categories": [
157183
{
158184
"name": "Code Documents",
185+
"selfService": false,
159186
"urlcode": "${ challenge.id }-documents",
160187
"discussions": [
161188
{
@@ -174,6 +201,7 @@
174201
},
175202
{
176203
"name": "Code Questions",
204+
"selfService": false,
177205
"urlcode": "${ challenge.id }-questions",
178206
"discussions": [
179207
{
@@ -183,6 +211,13 @@
183211
"closed": 0
184212
}
185213
]
214+
},
215+
{
216+
"name": "General Questions",
217+
"selfService": true,
218+
"urlcode": "${ challenge.id }-questions",
219+
"discussions": [
220+
]
186221
}
187222
]
188223
}

src/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ module.exports = {
4141
CHALLENGE_ROLES: {
4242
COPILOT: 'Copilot',
4343
MANAGER: 'Manager',
44-
SUBMITTER: 'Submitter'
44+
SUBMITTER: 'Submitter',
45+
CLIENT_MANAGER: 'Client Manager'
4546
},
4647
CHALLENGE_STATUSES: {
4748
NEW: 'New',

src/services/vanilla.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async function addTopcoderRoles (allVanillaRoles, topcoderRoleNames) {
140140
* @param {Object} challenge the challenge data
141141
*/
142142
async function createVanillaGroup (challenge) {
143-
logger.info(`The challenge with challengeID=${challenge.id}:`)
143+
logger.info(`Create: challengeID=${challenge.id}, status=${challenge.status}, selfService=${challenge.legacy.selfService}:`)
144144
const { text: challengeDetailsData, status: responseStatus } = await topcoderApi.getChallenge(challenge.id)
145145
const challengeDetails = JSON.parse(challengeDetailsData)
146146

@@ -163,6 +163,12 @@ async function createVanillaGroup (challenge) {
163163
throw new Error('Multiple discussions with type=\'challenge\' and provider=\'vanilla\' are not supported.')
164164
}
165165

166+
const isSelfService = challenge.legacy.selfService && challenge.legacy.selfService === true ? true: false
167+
if(isSelfService && challenge.status !== constants.TOPCODER.CHALLENGE_STATUSES.ACTIVE) {
168+
logger.info(`The forums are created only for self-service challenges with the Active status.`)
169+
return
170+
}
171+
166172
const { body: project } = await topcoderApi.getProject(challenge.projectId)
167173
const allProjectRoles = _.values(constants.TOPCODER.PROJECT_ROLES)
168174
const members = _.filter(project.members, member => {
@@ -200,7 +206,9 @@ async function createVanillaGroup (challenge) {
200206
logger.info(`Creating Vanilla entities for the '${challengeDetailsDiscussion.name}' discussion ....`)
201207

202208
const groupNameTemplate = _.template(groupTemplate.group.name)
203-
const groupDescriptionTemplate = _.template(groupTemplate.group.description)
209+
const groupDescriptionTemplate = challenge.legacy.selfService ? _.template(groupTemplate.group.selfServiceDescription)
210+
: _.template(groupTemplate.group.description)
211+
204212
const { body: group } = await vanillaClient.createGroup({
205213
name: groupNameTemplate({ challenge }),
206214
privacy: groupTemplate.group.privacy,
@@ -237,10 +245,11 @@ async function createVanillaGroup (challenge) {
237245
archived: true
238246
})
239247

240-
logger.info(`The '${challengeCategory.name}' category was created`)
248+
logger.info(`The '${challengeCategory.name}' category was created.`)
241249

242250
if (groupTemplate.categories) {
243-
for (const item of groupTemplate.categories) {
251+
const categories = _.filter(groupTemplate.categories, ['selfService', isSelfService])
252+
for (const item of categories) {
244253
const urlCodeTemplate = _.template(item.urlcode)
245254
const { body: childCategory } = await vanillaClient.createCategory({
246255
name: item.name,
@@ -255,7 +264,8 @@ async function createVanillaGroup (challenge) {
255264
}
256265

257266
if (groupTemplate.discussions) {
258-
await createDiscussions(group, challenge, groupTemplate.discussions, challengeCategory)
267+
const groupDiscussions = _.filter(groupTemplate.discussions, ['selfService', isSelfService])
268+
await createDiscussions(group, challenge, groupDiscussions, challengeCategory)
259269
}
260270

261271
for (const member of members) {
@@ -281,11 +291,18 @@ async function createVanillaGroup (challenge) {
281291
* @param {Object} challenge the challenge data
282292
*/
283293
async function updateVanillaGroup (challenge) {
284-
logger.info(`The challenge with challengeID=${challenge.id}:`)
294+
logger.info(`Update: challengeID=${challenge.id}, status=${challenge.status}, selService=${challenge.legacy.selfService}:`)
285295

286296
const { body: groups } = await vanillaClient.searchGroups(challenge.id)
287297
if (groups.length === 0) {
288-
throw new Error('The group wasn\'t found for this challenge')
298+
const isSelfService = challenge.legacy.selfService && challenge.legacy.selfService === true ? true: false
299+
// Create the forums for self-service challenges with the Active status
300+
if(isSelfService && challenge.status === constants.TOPCODER.CHALLENGE_STATUSES.ACTIVE) {
301+
await createVanillaGroup(challenge)
302+
return
303+
} else {
304+
throw new Error('The group wasn\'t found for this challenge')
305+
}
289306
}
290307

291308
if (groups.length > 1) {
@@ -321,7 +338,10 @@ async function updateVanillaGroup (challenge) {
321338
if (!groupCategoryForEdit) {
322339
throw new Error('Group category wasn\'t found for this challenge')
323340
}
341+
// Update group's name
324342
groupCategoryForEdit.name = challenge.name
343+
// Delete a category's parent so as not to rebuild the category tree again
344+
delete groupCategoryForEdit.parentCategoryID
325345

326346
const { body: updatedGroupCategory } = await vanillaClient.updateCategory(groupCategoryForEdit.categoryID, groupCategoryForEdit)
327347
logger.info(`The group category was updated: ${JSON.stringify(updatedGroupCategory)}`)
@@ -359,7 +379,8 @@ function shouldWatchCategories (projectRole, challengeRoles) {
359379
// Project Copilots / Challenge Copilots and Submitters
360380
return (projectRole === constants.TOPCODER.PROJECT_ROLES.COPILOT ||
361381
(_.isArray(challengeRoles) && (_.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.COPILOT) ||
362-
_.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.SUBMITTER)))
382+
_.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.SUBMITTER) ||
383+
_.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.CLIENT_MANAGER)))
363384
)
364385
}
365386

0 commit comments

Comments
 (0)