diff --git a/config/template.json b/config/template.json index eb06fb5..66aefb3 100644 --- a/config/template.json +++ b/config/template.json @@ -15,12 +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, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -39,6 +41,7 @@ }, { "name": "Code Questions", + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -48,6 +51,13 @@ "closed": 0 } ] + }, + { + "name": "General Questions", + "selfService": true, + "urlcode": "${ challenge.id }-questions", + "discussions": [ + ] } ] }, @@ -58,12 +68,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, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -82,6 +94,7 @@ }, { "name": "Code Questions", + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -91,6 +104,13 @@ "closed": 0 } ] + }, + { + "name": "General Questions", + "selfService": true, + "urlcode": "${ challenge.id }-questions", + "discussions": [ + ] } ] } @@ -107,6 +127,7 @@ "group": { "name": "${ challenge.name }", "description": "Welcome to [${ challenge.name }](<%- challenge.url %>) Forum.", + "selfServiceDescription": "Welcome to ${ challenge.name } Forum.", "privacy": "secret", "type": "challenge" }, @@ -115,25 +136,29 @@ "title": "Spec Review Discussion", "body": "Spec Review Discussion", "announce": 0, - "closed": 0 + "closed": 0, + "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 + "closed": 0, + "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 + "closed": 0, + "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 + "closed": 1, + "selfService": false } ] } @@ -150,12 +175,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, "urlcode": "${ challenge.id }-documents", "discussions": [ { @@ -174,6 +201,7 @@ }, { "name": "Code Questions", + "selfService": false, "urlcode": "${ challenge.id }-questions", "discussions": [ { @@ -183,6 +211,13 @@ "closed": 0 } ] + }, + { + "name": "General Questions", + "selfService": true, + "urlcode": "${ challenge.id }-questions", + "discussions": [ + ] } ] } diff --git a/src/constants.js b/src/constants.js index 91537ea..b47d9ac 100644 --- a/src/constants.js +++ b/src/constants.js @@ -41,7 +41,8 @@ module.exports = { CHALLENGE_ROLES: { COPILOT: 'Copilot', MANAGER: 'Manager', - SUBMITTER: 'Submitter' + SUBMITTER: 'Submitter', + CLIENT_MANAGER: 'Client Manager' }, CHALLENGE_STATUSES: { NEW: 'New', diff --git a/src/services/vanilla.js b/src/services/vanilla.js index 9993001..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, @@ -237,10 +245,11 @@ async function createVanillaGroup (challenge) { archived: true }) - logger.info(`The '${challengeCategory.name}' category was created`) + logger.info(`The '${challengeCategory.name}' category was created.`) if (groupTemplate.categories) { - for (const item of groupTemplate.categories) { + const categories = _.filter(groupTemplate.categories, ['selfService', isSelfService]) + for (const item of categories) { const urlCodeTemplate = _.template(item.urlcode) const { body: childCategory } = await vanillaClient.createCategory({ name: item.name, @@ -255,7 +264,8 @@ async function createVanillaGroup (challenge) { } if (groupTemplate.discussions) { - await createDiscussions(group, challenge, groupTemplate.discussions, challengeCategory) + const groupDiscussions = _.filter(groupTemplate.discussions, ['selfService', isSelfService]) + await createDiscussions(group, challenge, groupDiscussions, challengeCategory) } for (const member of members) { @@ -281,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) { @@ -321,7 +338,10 @@ async function updateVanillaGroup (challenge) { if (!groupCategoryForEdit) { throw new Error('Group category wasn\'t found for this challenge') } + // Update group's name groupCategoryForEdit.name = challenge.name + // Delete a category's parent so as not to rebuild the category tree again + delete groupCategoryForEdit.parentCategoryID const { body: updatedGroupCategory } = await vanillaClient.updateCategory(groupCategoryForEdit.categoryID, groupCategoryForEdit) logger.info(`The group category was updated: ${JSON.stringify(updatedGroupCategory)}`) @@ -359,7 +379,8 @@ function shouldWatchCategories (projectRole, challengeRoles) { // Project Copilots / Challenge Copilots and Submitters return (projectRole === constants.TOPCODER.PROJECT_ROLES.COPILOT || (_.isArray(challengeRoles) && (_.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.COPILOT) || - _.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.SUBMITTER))) + _.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.SUBMITTER) || + _.includes(challengeRoles, constants.TOPCODER.CHALLENGE_ROLES.CLIENT_MANAGER))) ) }