Skip to content

v1.9 #73

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 16 commits into from
Feb 2, 2022
Merged

v1.9 #73

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
43 changes: 39 additions & 4 deletions config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -39,6 +41,7 @@
},
{
"name": "Code Questions",
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -48,6 +51,13 @@
"closed": 0
}
]
},
{
"name": "General Questions",
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
]
}
]
},
Expand All @@ -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": [
{
Expand All @@ -82,6 +94,7 @@
},
{
"name": "Code Questions",
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -91,6 +104,13 @@
"closed": 0
}
]
},
{
"name": "General Questions",
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
]
}
]
}
Expand All @@ -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"
},
Expand All @@ -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
}
]
}
Expand All @@ -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": [
{
Expand All @@ -174,6 +201,7 @@
},
{
"name": "Code Questions",
"selfService": false,
"urlcode": "${ challenge.id }-questions",
"discussions": [
{
Expand All @@ -183,6 +211,13 @@
"closed": 0
}
]
},
{
"name": "General Questions",
"selfService": true,
"urlcode": "${ challenge.id }-questions",
"discussions": [
]
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports = {
CHALLENGE_ROLES: {
COPILOT: 'Copilot',
MANAGER: 'Manager',
SUBMITTER: 'Submitter'
SUBMITTER: 'Submitter',
CLIENT_MANAGER: 'Client Manager'
},
CHALLENGE_STATUSES: {
NEW: 'New',
Expand Down
37 changes: 29 additions & 8 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 @@ -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,
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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)}`)
Expand Down Expand Up @@ -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)))
)
}

Expand Down