diff --git a/app-constants.js b/app-constants.js index 3db24e1..ce3e323 100644 --- a/app-constants.js +++ b/app-constants.js @@ -10,7 +10,8 @@ const UserRoles = { } const ChallengeStatuses = { - Completed: 'Completed' + Completed: 'Completed', + Active: 'Active', } module.exports = { diff --git a/src/services/ResourceService.js b/src/services/ResourceService.js index 199fde7..42de677 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -231,6 +231,10 @@ async function init (currentUser, challengeId, resource, isCreated) { throw new errors.BadRequestError('Cannot delete resources of a completed challenge!') } + if (_.get(challenge, 'status') !== constants.ChallengeStatuses.Active && isCreated && resource.roleId === config.SUBMITTER_RESOURCE_ROLE_ID) { + throw new errors.BadRequestError(`Cannot create submitter resource on challenge with status ${_.get(challenge, 'status')}`) + } + // Prevent from creating more than 1 submitter resources on tasks if (_.get(challenge, 'task.isTask', false) && isCreated && resource.roleId === config.SUBMITTER_RESOURCE_ROLE_ID) { const existing = await getResources(currentUser, challengeId, config.SUBMITTER_RESOURCE_ROLE_ID, null, null, 1, 1)