diff --git a/.circleci/config.yml b/.circleci/config.yml index c86be2c..fbc92f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,6 @@ workflows: branches: only: - develop - - dev-circleci # Production builds are exectuted only on tagged commits to the testing # master branch. diff --git a/config/default.js b/config/default.js index 8accfed..503eedf 100644 --- a/config/default.js +++ b/config/default.js @@ -14,6 +14,8 @@ module.exports = { VALID_ISSUERS: process.env.VALID_ISSUERS || '["https://api.topcoder-dev.com", "https://api.topcoder.com", "https://topcoder-dev.auth0.com/"]', SUBMITTER_RESOURCE_ROLE_ID: process.env.SUBMITTER_RESOURCE_ROLE_ID || '732339e7-8e30-49d7-9198-cccf9451e221', + REVIEWER_RESOURCE_ROLE_ID: process.env.REVIEWER_RESOURCE_ROLE_ID || '318b9c07-079a-42d9-a81f-b96be1dc1099', + ITERATIVE_REVIEWER_RESOURCE_ROLE_ID: process.env.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID || 'f6df7212-b9d6-4193-bfb1-b383586fce63', AUTH0_URL: process.env.AUTH0_URL || 'https://topcoder-dev.auth0.com/oauth/token', AUTH0_AUDIENCE: process.env.AUTH0_AUDIENCE || 'https://m2m.topcoder-dev.com/', @@ -27,6 +29,7 @@ module.exports = { USER_API_URL: process.env.USER_API_URL || 'https://api.topcoder-dev.com/v3/users', CHALLENGE_API_URL: process.env.CHALLENGE_API_URL || 'http://localhost:4000/v5/challenges', CHALLENGE_PHASES_API_URL: process.env.CHALLENGE_PHASES_API_URL || 'https://api.topcoder-dev.com/v5/challenge-phases', + SUBMISSIONS_API_URL: process.env.SUBMISSIONS_API_URL || 'https://api.topcoder-dev.com/v5/submissions', DYNAMODB: { AWS_ACCESS_KEY_ID: process.env.AWS_ACCESS_KEY_ID, diff --git a/src/services/ResourceService.js b/src/services/ResourceService.js index 7054975..4016d99 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -243,6 +243,15 @@ async function init (currentUser, challengeId, resource, isCreated) { const handle = resource.memberHandle const memberId = await helper.getMemberIdByHandle(resource.memberHandle) + // check if the resource is reviewer role and has already made a submission in the challenge + if (resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID || resource.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID) { + const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100, memberId: memberId }) + const submissions = submissionsRes.body + if (submissions.length !== 0) { + throw new errors.ConflictError(`The member has already submitted to the challenge and cannot have a Reviewer or Iterative Reviewer role`) + } + } + // ensure resource role existed const resourceRole = await getResourceRole(resource.roleId, isCreated)