Skip to content

Issues-663: add self-service description #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -40,7 +41,7 @@
},
{
"name": "Code Questions",
"selfservice": false,
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -53,7 +54,7 @@
},
{
"name": "General Questions",
"selfservice": true,
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -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": [
{
Expand All @@ -98,7 +100,7 @@
},
{
"name": "Code Questions",
"selfservice": false,
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -111,7 +113,7 @@
},
{
"name": "General Questions",
"selfservice": true,
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -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"
},
Expand All @@ -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
}
]
}
Expand All @@ -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": [
{
Expand All @@ -216,7 +220,7 @@
},
{
"name": "Code Questions",
"selfservice": false,
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -229,7 +233,7 @@
},
{
"name": "General Questions",
"selfservice": true,
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand Down
28 changes: 21 additions & 7 deletions src/services/vanilla.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand All @@ -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)
}

Expand All @@ -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) {
Expand Down