Skip to content

Restrictions for registering #144

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 3 commits into from
Oct 5, 2023
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: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ workflows:
branches:
only:
- develop
- PLAT-3383
- PLAT-3501

# Production builds are exectuted only on tagged commits to the testing
# master branch.
Expand Down
15 changes: 10 additions & 5 deletions src/services/ResourceService.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ async function getResources (currentUser, challengeId, roleId, memberId, memberH
}
if (challengeId) {
try {
// Verify that the challenge exists
await helper.getRequest(`${config.CHALLENGE_API_URL}/${challengeId}`)
// Verify that the challenge exists
await helper.getRequest(`${config.CHALLENGE_API_URL}/${challengeId}`, { checkIfExists: 'true' })
} catch (e) {
throw new errors.NotFoundError(`Challenge ID ${challengeId} not found`)
}
Expand Down Expand Up @@ -240,6 +240,7 @@ async function init (currentUser, challengeId, resource, isCreated) {
const registrationPhase = challenge.phases.find((phase) => phase.name === 'Registration')
const currentSubmitters = _.filter(allResources, (r) => r.roleId === config.SUBMITTER_RESOURCE_ROLE_ID)
const handle = resource.memberHandle
const userResources = allResources.filter((r) => _.toLower(r.memberHandle) === _.toLower(handle))
// Retrieve the constraint - Allowed Registrants
if (isCreated && resource.roleId === config.SUBMITTER_RESOURCE_ROLE_ID) {
const allowedRegistrants = _.get(challenge, 'constraints.allowedRegistrants')
Expand All @@ -256,6 +257,12 @@ async function init (currentUser, challengeId, resource, isCreated) {
`User ${resource.memberHandle} is not allowed to register.`
)
}
if (!_.get(challenge, 'task.isTask', false) && (_.toLower(challenge.createdBy) === _.toLower(handle) ||
_.some(userResources, r => r.roleId === config.REVIEWER_RESOURCE_ROLE_ID || r.roleId === config.ITERATIVE_REVIEWER_RESOURCE_ROLE_ID))) {
throw new errors.BadRequestError(
`User ${resource.memberHandle} is not allowed to register.`
)
}
}

// Prevent from creating more than 1 submitter resources on tasks
Expand All @@ -265,9 +272,6 @@ async function init (currentUser, challengeId, resource, isCreated) {
}
}

// get member information using v3 API
const { memberId, email } = await helper.getMemberDetailsByHandle(handle)
const userResources = allResources.filter((r) => _.toString(r.memberId) === _.toString(memberId))
const currentUserResources = allResources.filter((r) => _.toString(r.memberId) === _.toString(currentUser.userId))
const isResourceExist = !_.isUndefined(_.find(userResources, r => r.roleId === resource.roleId))
if (isCreated && isResourceExist) {
Expand All @@ -278,6 +282,7 @@ async function init (currentUser, challengeId, resource, isCreated) {
throw new errors.NotFoundError(`User ${handle} doesn't have resource with roleId: ${resource.roleId} in challenge ${challengeId}`)
}

const { memberId, email } = await helper.getMemberDetailsByHandle(handle)
// check if the resource is reviewer role and has already made a submission in the challenge
if (isCreated && (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 })
Expand Down