Skip to content

Commit 82f9e57

Browse files
Merge branch 'master' into develop
2 parents 3c4513e + 252d8c6 commit 82f9e57

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,3 +315,5 @@ npm run update-to-v5-challengeId
315315
2. There are 3 tokens provided in the environment collection representing each role - Topcoder User, Copilot, Administrator
316316

317317
3. DynamoDB performance seems to be slower in my testing
318+
319+
Token Commit.

src/common/helper.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@ function * checkCreateAccess (authUser, subEntity) {
465465
throw new errors.HttpStatusError(400, `You cannot create a submission for a challenge while you are an iterative reviewer`)
466466
}
467467

468+
// Check if the User is assigned as the reviewer for the contest
469+
const reviewers = _.filter(currUserRoles, { role: 'Reviewer' })
470+
if (reviewers.length !== 0) {
471+
throw new errors.HttpStatusError(400, `You cannot create a submission for a challenge while you are a reviewer`)
472+
}
473+
474+
// Check if the User is assigned as the iterative reviewer for the contest
475+
const iterativeReviewers = _.filter(currUserRoles, { role: 'Iterative Reviewer' })
476+
if (iterativeReviewers.length !== 0) {
477+
throw new errors.HttpStatusError(400, `You cannot create a submission for a challenge while you are an iterative reviewer`)
478+
}
479+
468480
// Check if the User is registered for the contest
469481
const submitters = _.filter(currUserRoles, { role: 'Submitter' })
470482
if (submitters.length === 0) {
@@ -837,6 +849,8 @@ function adjustSubmissionChallengeId (submission) {
837849
if (submission.challengeId && submission.legacyChallengeId) {
838850
submission.v5ChallengeId = submission.challengeId
839851
submission.challengeId = submission.legacyChallengeId
852+
} else if (submission.challengeId && !submission.legacyChallengeId) {
853+
submission.v5ChallengeId = submission.challengeId
840854
}
841855
}
842856

src/services/SubmissionService.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ function * createSubmission (authUser, files, entity) {
298298
updatedBy: authUser.handle || authUser.sub
299299
}
300300

301+
// Pure v5 challenges won't have a legacy challenge id
301302
if (legacyChallengeId) {
302303
item.legacyChallengeId = legacyChallengeId
303304
}
@@ -343,6 +344,7 @@ function * createSubmission (authUser, files, entity) {
343344
}
344345

345346
logger.info('Prepared submission item to insert into Dynamodb. Inserting...')
347+
logger.info(JSON.stringify(record, null, 2))
346348
yield dbhelper.insertRecord(record)
347349

348350
// After save to db, adjust challengeId to busApi and response
@@ -417,6 +419,13 @@ function * _updateSubmission (authUser, submissionId, entity) {
417419
challengeId = yield helper.getV5ChallengeId(entity.challengeId)
418420
legacyChallengeId = yield helper.getLegacyChallengeId(entity.challengeId)
419421
}
422+
if (exist.legacyChallengeId && !legacyChallengeId) {
423+
// Original submission contains a legacy challenge id
424+
// But with this update, it does not
425+
// Prevent updates to current submission
426+
// else we will be left with a submission with wrong legacy challenge id
427+
throw new errors.HttpStatusError(400, `Cannot update submission with v5 challenge id since it already has a legacy challenge id associated with it`)
428+
}
420429
// Record used for updating in Database
421430
const record = {
422431
TableName: table,
@@ -443,6 +452,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
443452
}
444453
}
445454

455+
if (legacyChallengeId) {
456+
record.UpdateExpression = record.UpdateExpression + ', legacyChallengeId = :lc'
457+
record.ExpressionAttributeValues[':lc'] = legacyChallengeId
458+
}
459+
446460
// If legacy submission ID exists, add it to the update expression
447461
if (entity.legacySubmissionId || exist.legacySubmissionId) {
448462
record.UpdateExpression = record.UpdateExpression + ', legacySubmissionId = :ls'

0 commit comments

Comments
 (0)