Skip to content

HOTFIX - do not store legacy challenge id if there isnt one #254

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 1 commit into from
Oct 29, 2021
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
2 changes: 2 additions & 0 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,8 @@ function adjustSubmissionChallengeId (submission) {
if (submission.challengeId && submission.legacyChallengeId) {
submission.v5ChallengeId = submission.challengeId
submission.challengeId = submission.legacyChallengeId
} else if (submission.challengeId && !submission.legacyChallengeId) {
submission.v5ChallengeId = submission.challengeId
}
}

Expand Down
21 changes: 18 additions & 3 deletions src/services/SubmissionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,17 @@ function * createSubmission (authUser, files, entity) {
url: url,
memberId: entity.memberId,
challengeId,
legacyChallengeId,
created: currDate,
updated: currDate,
createdBy: authUser.handle || authUser.sub,
updatedBy: authUser.handle || authUser.sub
}

// Pure v5 challenges won't have a legacy challenge id
if (legacyChallengeId) {
item.legacyChallengeId = legacyChallengeId
}

if (entity.legacySubmissionId) {
item.legacySubmissionId = entity.legacySubmissionId
}
Expand Down Expand Up @@ -405,20 +409,26 @@ function * _updateSubmission (authUser, submissionId, entity) {
challengeId = yield helper.getV5ChallengeId(entity.challengeId)
legacyChallengeId = yield helper.getLegacyChallengeId(entity.challengeId)
}
if (exist.legacyChallengeId && !legacyChallengeId) {
// Original submission contains a legacy challenge id
// But with this update, it does not
// Prevent updates to current submission
// else we will be left with a submission with wrong legacy challenge id
throw new errors.HttpStatusError(400, `Cannot update submission with v5 challenge id since it already has a legacy challenge id associated with it`)
}
// Record used for updating in Database
const record = {
TableName: table,
Key: {
id: submissionId
},
UpdateExpression: `set #type = :t, #url = :u, memberId = :m, challengeId = :c,
legacyChallengeId = :lc, updated = :ua, updatedBy = :ub, submittedDate = :sb`,
updated = :ua, updatedBy = :ub, submittedDate = :sb`,
ExpressionAttributeValues: {
':t': entity.type || exist.type,
':u': entity.url || exist.url,
':m': entity.memberId || exist.memberId,
':c': challengeId,
':lc': legacyChallengeId,
':ua': currDate,
':ub': authUser.handle || authUser.sub,
':sb': entity.submittedDate || exist.submittedDate || exist.created
Expand All @@ -429,6 +439,11 @@ function * _updateSubmission (authUser, submissionId, entity) {
}
}

if (legacyChallengeId) {
record.UpdateExpression = record.UpdateExpression + ', legacyChallengeId = :lc'
record.ExpressionAttributeValues[':lc'] = legacyChallengeId
}

// If legacy submission ID exists, add it to the update expression
if (entity.legacySubmissionId || exist.legacySubmissionId) {
record.UpdateExpression = record.UpdateExpression + ', legacySubmissionId = :ls'
Expand Down