Skip to content

Commit a66bac4

Browse files
committed
Issues-668: create forums for sel-service if status=Active
1 parent 09e8ce8 commit a66bac4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/services/vanilla.js

Lines changed: 16 additions & 4 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 => {
@@ -199,7 +205,6 @@ async function createVanillaGroup (challenge) {
199205

200206
logger.info(`Creating Vanilla entities for the '${challengeDetailsDiscussion.name}' discussion ....`)
201207

202-
const isSelfService = challenge.legacy.selfService && challenge.legacy.selfService === true ? true: false
203208
const groupNameTemplate = _.template(groupTemplate.group.name)
204209
const groupDescriptionTemplate = challenge.legacy.selfService ? _.template(groupTemplate.group.selfServiceDescription)
205210
: _.template(groupTemplate.group.description)
@@ -286,11 +291,18 @@ async function createVanillaGroup (challenge) {
286291
* @param {Object} challenge the challenge data
287292
*/
288293
async function updateVanillaGroup (challenge) {
289-
logger.info(`The challenge with challengeID=${challenge.id}:`)
294+
logger.info(`Update: challengeID=${challenge.id}, status=${challenge.status}, selService=${challenge.legacy.selfService}:`)
290295

291296
const { body: groups } = await vanillaClient.searchGroups(challenge.id)
292297
if (groups.length === 0) {
293-
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+
}
294306
}
295307

296308
if (groups.length > 1) {

0 commit comments

Comments
 (0)