Skip to content
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
6 changes: 3 additions & 3 deletions config/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
LOG_LEVEL: 'info',
WEB_SERVER_PORT: 3010,
AUTH_SECRET: 'mysecret',
VALID_ISSUERS: '["https://api.topcoder.com"]',
VALID_ISSUERS: process.env.VALID_ISSUERS ? process.env.VALID_ISSUERS.replace(/\\"/g, '') : '["https://api.topcoder.com","https://topcoder-dev.auth0.com/"]',
API_VERSION: process.env.API_VERSION || '/api/v5',
aws: {
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used by the application
Expand All @@ -16,14 +16,14 @@ module.exports = {
S3_BUCKET: process.env.S3_BUCKET_TEST || 'tc-testing-submissions' // S3 Bucket to which submissions need to be uploaded
},
BUSAPI_EVENTS_URL: 'https://api.topcoder-dev.com/v5/bus/events',
BUSAPI_URL: 'https://api.topcoder-dev.com/v5',
CHALLENGEAPI_V5_URL: 'https://api.topcoder-dev.com/v5/challenges',
esConfig: {
ES_INDEX: process.env.ES_INDEX_TEST || 'submission-test',
ES_TYPE: process.env.ES_TYPE_TEST || '_doc' // ES 6.x accepts only 1 Type per index and it's mandatory to define it
},
AUTH0_URL: process.env.AUTH0_URL, // Auth0 credentials for Submission Service
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://www.topcoder.com',
TOKEN_CACHE_TIME: process.env.TOKEN_CACHE_TIME,
AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE,
AUTH0_CLIENT_ID: process.env.AUTH0_CLIENT_ID,
AUTH0_CLIENT_SECRET: process.env.AUTH0_CLIENT_SECRET,
USER_TOKEN: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJyb2xlcyI6WyJUb3Bjb2RlciBVc2VyIl0sImlzcyI6Imh0dHBzOi8vYXBpLnRvcGNvZGVyLmNvbSIsImhhbmRsZSI6IlNoYXJhdGhrdW1hcjkyIiwiZXhwIjo1NTUzMDE5OTI1OSwidXNlcklkIjoiNDA0OTMwNTAiLCJpYXQiOjE1MzAxOTg2NTksImVtYWlsIjoiU2hhcmF0aGt1bWFyOTJAdG9wY29kZXIuY29tIiwianRpIjoiYzNhYzYwOGEtNTZiZS00NWQwLThmNmEtMzFmZTk0Yjk1NjFjIn0.2gtNJwhcv7MYc-muX3Nv-B0RdWbhMRl7-xrwFUsLazM',
Expand Down
54 changes: 23 additions & 31 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function autoWrapExpress (obj) {
return obj
}
_.each(obj, (value, key) => {
obj[key] = autoWrapExpress(value); //eslint-disable-line
obj[key] = autoWrapExpress(value); //eslint-disable-line
})
return obj
}
Expand Down Expand Up @@ -676,39 +676,31 @@ function * getRoleIdToRoleNameMap () {
* @param {Object} challengeDetails the challenge details
* @returns {('Scheduled' | 'Open' | 'Closed' | 'Invalid')} status of the phase
*/
function * getPhaseStatus (phaseName, challengeDetails) {
const phases = challengeDetails.phases
if (challengeDetails.status === 'Completed') {
return 'Closed'
} else if (challengeDetails.status === 'Active') {
const queriedPhaseIndex = _.findIndex(phases, phase => {
return phase.name === phaseName
})
// Requested phase name could not be found in phases hence 'Invalid'
if (queriedPhaseIndex === -1) {
return 'Invalid'
}
// If requested phase name is open return 'Open'
if (phases[queriedPhaseIndex].isOpen) {
return 'Open'
}

// Search for phase where isOpen == true from list of phases
// Phases are already in sorted order as per challenge-api repository
const currentOpenPhaseIndex = _.findLastIndex(phases, phase => {
return phase.isOpen === true
})

// if queried phase occurs before current open phase it is 'Closed'
// else it is 'Scheduled'
if (currentOpenPhaseIndex !== -1) {
return currentOpenPhaseIndex > queriedPhaseIndex ? 'Closed' : 'Scheduled'
function getPhaseStatus (phaseName, challengeDetails) {
const { phases } = challengeDetails
const queriedPhaseIndex = _.findIndex(phases, phase => {
return phase.name === phaseName
})
// Requested phase name could not be found in phases hence 'Invalid'
if (queriedPhaseIndex === -1) {
return 'Invalid'
}
// If requested phase name is open return 'Open'
if (phases[queriedPhaseIndex].isOpen) {
return 'Open'
} else {
const { actualEndDate } = phases[queriedPhaseIndex]
if (!_.isEmpty(actualEndDate)) {
const present = new Date().getTime()
const actualDate = new Date(actualEndDate).getTime()
if (present > actualDate) {
return 'Closed'
} else {
return 'Scheduled'
}
} else {
// if no phase is open but the challenge is Active return Scheduled
return 'Scheduled'
}
} else { // if challenge is not in Active or Completed state return Scheduled
return 'Scheduled'
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/services/SubmissionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const listSubmissionsQuerySchema = {
type: joi.string(),
url: joi.string().uri().trim(),
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()),
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
challengeId: joi.string().uuid(),
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
submissionPhaseId: joi.id(),
Expand Down Expand Up @@ -356,7 +356,7 @@ createSubmission.schema = {
fileType: joi.string(),
url: joi.string().uri().trim(),
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
challengeId: joi.string().uuid().required(),
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
submissionPhaseId: joi.id(),
Expand Down Expand Up @@ -480,7 +480,7 @@ updateSubmission.schema = {
type: joi.string(),
url: joi.string().uri().trim().required(),
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()).required(),
challengeId: joi.string().uuid().required(),
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
submissionPhaseId: joi.id(),
Expand All @@ -506,7 +506,7 @@ patchSubmission.schema = {
type: joi.string(),
url: joi.string().uri().trim(),
memberId: joi.alternatives().try(joi.id(), joi.string().uuid()),
challengeId: joi.alternatives().try(joi.id(), joi.string().uuid()),
challengeId: joi.string().uuid(),
legacySubmissionId: joi.alternatives().try(joi.id(), joi.string().uuid()),
legacyUploadId: joi.alternatives().try(joi.id(), joi.string().uuid()),
submissionPhaseId: joi.id(),
Expand Down
Loading