From f6c278bb6f1cb10084725debe372f7093013f0a7 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Thu, 17 Mar 2022 23:22:07 +0800 Subject: [PATCH 1/9] reviewer resource check --- config/default.js | 2 ++ src/services/ResourceService.js | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/config/default.js b/config/default.js index 8accfed..9a61b51 100644 --- a/config/default.js +++ b/config/default.js @@ -14,6 +14,7 @@ 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', 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 +28,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..81c432c 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -243,6 +243,13 @@ 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 + const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100 }) + const submissions = submissionsRes.body + if ((_.find(submissions, s => s.memberId === memberId) && resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID)) { + throw new errors.ConflictError(`The member has already submitted to the challenge and cannot have a Reviewer role`) + } + // ensure resource role existed const resourceRole = await getResourceRole(resource.roleId, isCreated) From aec5010350d55a22183ba2cf33abf7c5b4daa981 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Thu, 17 Mar 2022 23:22:40 +0800 Subject: [PATCH 2/9] ci:deploying --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c86be2c..a6c6f94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,7 @@ workflows: branches: only: - develop - - dev-circleci + - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch. From dae9ed79789b88b501991aba7b58b9fab63336fd Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Mon, 21 Mar 2022 20:30:28 +0800 Subject: [PATCH 3/9] restrict iterative reviewer role --- config/default.js | 1 + src/services/ResourceService.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/default.js b/config/default.js index 9a61b51..503eedf 100644 --- a/config/default.js +++ b/config/default.js @@ -15,6 +15,7 @@ module.exports = { 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/', diff --git a/src/services/ResourceService.js b/src/services/ResourceService.js index 81c432c..9031bf3 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -246,8 +246,8 @@ async function init (currentUser, challengeId, resource, isCreated) { // check if the resource is reviewer role and has already made a submission in the challenge const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100 }) const submissions = submissionsRes.body - if ((_.find(submissions, s => s.memberId === memberId) && resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID)) { - throw new errors.ConflictError(`The member has already submitted to the challenge and cannot have a Reviewer role`) + if ((_.find(submissions, s => s.memberId === memberId) && (resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID || resource.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID))) { + 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 From 9490e2cf8e84c2986f054643259fbb1888edda57 Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Mon, 21 Mar 2022 22:27:45 +0800 Subject: [PATCH 4/9] ci:reset --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6c6f94..fbc92f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,6 @@ workflows: branches: only: - develop - - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch. From cd068b780193452b3e9b02aff6788fade82745cc Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Tue, 22 Mar 2022 20:15:47 +0800 Subject: [PATCH 5/9] using member filter --- .circleci/config.yml | 1 + src/services/ResourceService.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fbc92f8..a6c6f94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,6 +122,7 @@ workflows: branches: only: - develop + - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch. diff --git a/src/services/ResourceService.js b/src/services/ResourceService.js index 9031bf3..8ea2afc 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -244,9 +244,9 @@ async function init (currentUser, challengeId, resource, isCreated) { const memberId = await helper.getMemberIdByHandle(resource.memberHandle) // check if the resource is reviewer role and has already made a submission in the challenge - const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100 }) + const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100, memberId: memberId }) const submissions = submissionsRes.body - if ((_.find(submissions, s => s.memberId === memberId) && (resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID || resource.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID))) { + if (submissions.length !== 0 && (resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID || resource.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID)) { throw new errors.ConflictError(`The member has already submitted to the challenge and cannot have a Reviewer or Iterative Reviewer role`) } From bc719d1fd9c51940ea8c4e12ee81c87f91ed2e2f Mon Sep 17 00:00:00 2001 From: LieutenantRoger Date: Tue, 22 Mar 2022 20:43:07 +0800 Subject: [PATCH 6/9] reset ci --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6c6f94..fbc92f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,6 @@ workflows: branches: only: - develop - - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch. From 08de9224e8f0eeed0f3afa4acb5b1ae0b8664f4e Mon Sep 17 00:00:00 2001 From: roger Date: Wed, 23 Mar 2022 18:24:39 +0800 Subject: [PATCH 7/9] avoid unnecessary call --- src/services/ResourceService.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/services/ResourceService.js b/src/services/ResourceService.js index 8ea2afc..4016d99 100644 --- a/src/services/ResourceService.js +++ b/src/services/ResourceService.js @@ -244,10 +244,12 @@ async function init (currentUser, challengeId, resource, isCreated) { const memberId = await helper.getMemberIdByHandle(resource.memberHandle) // check if the resource is reviewer role and has already made a submission in the challenge - const submissionsRes = await helper.getRequest(`${config.SUBMISSIONS_API_URL}`, { challengeId: challengeId, perPage: 100, memberId: memberId }) - const submissions = submissionsRes.body - if (submissions.length !== 0 && (resource.roleId === config.REVIEWER_RESOURCE_ROLE_ID || resource.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID)) { - throw new errors.ConflictError(`The member has already submitted to the challenge and cannot have a Reviewer or Iterative Reviewer role`) + 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 From dc7cc07d41c7fcc2710a6ff35228fb23b6b995fb Mon Sep 17 00:00:00 2001 From: roger Date: Wed, 23 Mar 2022 18:26:37 +0800 Subject: [PATCH 8/9] deploying --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index fbc92f8..a6c6f94 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,6 +122,7 @@ workflows: branches: only: - develop + - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch. From d34b61ec0b5dc6a5dc70dcdcfa62e827d6744a5f Mon Sep 17 00:00:00 2001 From: roger Date: Wed, 23 Mar 2022 18:54:27 +0800 Subject: [PATCH 9/9] revert ci --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a6c6f94..fbc92f8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -122,7 +122,6 @@ workflows: branches: only: - develop - - issue_reviewer_role # Production builds are exectuted only on tagged commits to the testing # master branch.