diff --git a/config/template.json b/config/template.json index cd732ef..6a1ed6f 100644 --- a/config/template.json +++ b/config/template.json @@ -15,13 +15,14 @@ "group": { "name": "${ challenge.name }", "description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.", + "selfServiceDescription": "Welcome to ${ challenge.name } Forum.", "privacy": "secret", "type": "challenge" }, "categories": [ { "name": "Code Documents", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -40,7 +41,7 @@ }, { "name": "Code Questions", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -53,7 +54,7 @@ }, { "name": "General Questions", - "selfservice": true, + "selfService": true, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -73,13 +74,14 @@ "group": { "name": "${ challenge.name }", "description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.", + "selfServiceDescription": "Welcome to ${ challenge.name } Forum.", "privacy": "secret", "type": "challenge" }, "categories": [ { "name": "Code Documents", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -98,7 +100,7 @@ }, { "name": "Code Questions", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -111,7 +113,7 @@ }, { "name": "General Questions", - "selfservice": true, + "selfService": true, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -136,7 +138,8 @@ "urlcode": "$ { challenge.id }", "group": { "name": "${ challenge.name }", - "description": "Welcome to the challenge forum.", + "description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.", + "selfServiceDescription": "Welcome to ${ challenge.name } Forum.", "privacy": "secret", "type": "challenge" }, @@ -146,35 +149,35 @@ "body": "Spec Review Discussion", "announce": 0, "closed": 0, - "selfservice": false + "selfService": false }, { "title": "Please give us feedback on this challenge!", "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 %>", "announce": 0, "closed": 0, - "selfservice": false + "selfService": false }, { "title": "Welcome!", "body": "Please read the requirements carefully. If you have questions, please let me know, I'll be glad to help you.", "announce": 0, "closed": 0, - "selfservice": false + "selfService": false }, { "title": "Challenge Overview", "body": "[Back to Challenge Details page](<%- challenge.url %>)\n<% _.forEach(challenge.prizeSets, function(prizeSet) { %>* <%- prizeSet.type %>: <% _.forEach(prizeSet.prizes, function(prize) { %><%- prize.value %>$ <% }) %>\n<% }); %>", "announce": 1, "closed": 1, - "selfservice": false + "selfService": false }, { "title": "Welcome!", "body": "Please read the requirements carefully. If you have questions, please let me know, I'll be glad to help you.", "announce": 0, "closed": 0, - "selfservice": true + "selfService": true } ] } @@ -191,13 +194,14 @@ "group": { "name": "${ challenge.name }", "description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.", + "selfServiceDescription": "Welcome to ${ challenge.name } Forum.", "privacy": "secret", "type": "challenge" }, "categories": [ { "name": "Code Documents", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -216,7 +220,7 @@ }, { "name": "Code Questions", - "selfservice": false, + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -229,7 +233,7 @@ }, { "name": "General Questions", - "selfservice": true, + "selfService": true, "urlcode": "${ challenge.id }-questions", "discussions": [ { diff --git a/src/services/vanilla.js b/src/services/vanilla.js index 0d34b55..feef34b 100644 --- a/src/services/vanilla.js +++ b/src/services/vanilla.js @@ -140,7 +140,7 @@ async function addTopcoderRoles (allVanillaRoles, topcoderRoleNames) { * @param {Object} challenge the challenge data */ async function createVanillaGroup (challenge) { - logger.info(`The challenge with challengeID=${challenge.id}:`) + logger.info(`Create: challengeID=${challenge.id}, status=${challenge.status}, selfService=${challenge.legacy.selfService}:`) const { text: challengeDetailsData, status: responseStatus } = await topcoderApi.getChallenge(challenge.id) const challengeDetails = JSON.parse(challengeDetailsData) @@ -163,6 +163,12 @@ async function createVanillaGroup (challenge) { throw new Error('Multiple discussions with type=\'challenge\' and provider=\'vanilla\' are not supported.') } + const isSelfService = challenge.legacy.selfService && challenge.legacy.selfService === true ? true: false + if(isSelfService && challenge.status !== constants.TOPCODER.CHALLENGE_STATUSES.ACTIVE) { + logger.info(`The forums are created only for self-service challenges with the Active status.`) + return + } + const { body: project } = await topcoderApi.getProject(challenge.projectId) const allProjectRoles = _.values(constants.TOPCODER.PROJECT_ROLES) const members = _.filter(project.members, member => { @@ -200,7 +206,9 @@ async function createVanillaGroup (challenge) { logger.info(`Creating Vanilla entities for the '${challengeDetailsDiscussion.name}' discussion ....`) const groupNameTemplate = _.template(groupTemplate.group.name) - const groupDescriptionTemplate = _.template(groupTemplate.group.description) + const groupDescriptionTemplate = challenge.legacy.selfService ? _.template(groupTemplate.group.selfServiceDescription) + : _.template(groupTemplate.group.description) + const { body: group } = await vanillaClient.createGroup({ name: groupNameTemplate({ challenge }), privacy: groupTemplate.group.privacy, @@ -239,9 +247,8 @@ async function createVanillaGroup (challenge) { logger.info(`The '${challengeCategory.name}' category was created.`) - const isSelfService = challenge.legacy.selfService; if (groupTemplate.categories) { - const categories = _.filter(groupTemplate.categories, ['selfservice', isSelfService] ) + const categories = _.filter(groupTemplate.categories, ['selfService', isSelfService]) for (const item of categories) { const urlCodeTemplate = _.template(item.urlcode) const { body: childCategory } = await vanillaClient.createCategory({ @@ -257,7 +264,7 @@ async function createVanillaGroup (challenge) { } if (groupTemplate.discussions) { - const groupDiscussions = _.filter(groupTemplate.discussions, ['selfservice', isSelfService] ) + const groupDiscussions = _.filter(groupTemplate.discussions, ['selfService', isSelfService]) await createDiscussions(group, challenge, groupDiscussions, challengeCategory) } @@ -284,11 +291,18 @@ async function createVanillaGroup (challenge) { * @param {Object} challenge the challenge data */ async function updateVanillaGroup (challenge) { - logger.info(`The challenge with challengeID=${challenge.id}:`) + logger.info(`Update: challengeID=${challenge.id}, status=${challenge.status}, selService=${challenge.legacy.selfService}:`) const { body: groups } = await vanillaClient.searchGroups(challenge.id) if (groups.length === 0) { - throw new Error('The group wasn\'t found for this challenge') + const isSelfService = challenge.legacy.selfService && challenge.legacy.selfService === true ? true: false + // Create the forums for self-service challenges with the Active status + if(isSelfService && challenge.status === constants.TOPCODER.CHALLENGE_STATUSES.ACTIVE) { + await createVanillaGroup(challenge) + return + } else { + throw new Error('The group wasn\'t found for this challenge') + } } if (groups.length > 1) {