Skip to content

Commit d64a45d

Browse files
Merge pull request #114 from topcoder-platform/Fix/create-reasource-method
Fix issue that user was able to register on a cancelled challenge
2 parents 2f5331b + a1f7cd2 commit d64a45d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

app-constants.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const UserRoles = {
1010
}
1111

1212
const ChallengeStatuses = {
13-
Completed: 'Completed'
13+
Completed: 'Completed',
14+
Active: 'Active',
1415
}
1516

1617
module.exports = {

src/services/ResourceService.js

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ async function init (currentUser, challengeId, resource, isCreated) {
231231
throw new errors.BadRequestError('Cannot delete resources of a completed challenge!')
232232
}
233233

234+
if (_.get(challenge, 'status') !== constants.ChallengeStatuses.Active && isCreated && resource.roleId === config.SUBMITTER_RESOURCE_ROLE_ID) {
235+
throw new errors.BadRequestError(`Cannot create submitter resource on challenge with status ${_.get(challenge, 'status')}`)
236+
}
237+
234238
// Prevent from creating more than 1 submitter resources on tasks
235239
if (_.get(challenge, 'task.isTask', false) && isCreated && resource.roleId === config.SUBMITTER_RESOURCE_ROLE_ID) {
236240
const existing = await getResources(currentUser, challengeId, config.SUBMITTER_RESOURCE_ROLE_ID, null, null, 1, 1)

0 commit comments

Comments
 (0)