Skip to content

support pure v5 tasks #379

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 1 commit into from
Feb 4, 2021
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
3 changes: 2 additions & 1 deletion src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,12 @@ async function ensureProjectExist (projectId, currentUser) {
try {
const res = await axios.get(url, { headers: { Authorization: `Bearer ${token}` } })
if (currentUser.isMachine || hasAdminRole(currentUser)) {
return
return res.data
}
if (!_.find(_.get(res, 'data.members', []), m => _.toString(m.userId) === _.toString(currentUser.userId))) {
throw new errors.ForbiddenError(`You don't have access to project with ID: ${projectId}`)
}
return res.data
} catch (err) {
if (_.get(err, 'response.status') === HttpStatus.NOT_FOUND) {
throw new errors.BadRequestError(`Project with id: ${projectId} doesn't exist`)
Expand Down
22 changes: 16 additions & 6 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,10 @@ async function createChallenge (currentUser, challenge) {
if (challenge.status === constants.challengeStatuses.Active) {
throw new errors.BadRequestError('You cannot create an Active challenge. Please create a Draft challenge and then change the status to Active.')
}
await helper.ensureProjectExist(challenge.projectId, currentUser)
const { directProjectId } = await helper.ensureProjectExist(challenge.projectId, currentUser)
if (_.get(challenge, 'legacy.pureV5Task')) {
_.set(challenge, 'legacy.directProjectId', directProjectId)
}
const { track, type } = await validateChallengeData(challenge)
if (_.get(type, 'isTask')) {
_.set(challenge, 'task.isTask', true)
Expand Down Expand Up @@ -972,7 +975,8 @@ createChallenge.schema = {
screeningScorecardId: Joi.number().integer(),
reviewScorecardId: Joi.number().integer(),
isTask: Joi.boolean(),
useSchedulingAPI: Joi.boolean()
useSchedulingAPI: Joi.boolean(),
pureV5Task: Joi.boolean()
}),
task: Joi.object().keys({
isTask: Joi.boolean().default(false),
Expand Down Expand Up @@ -1199,7 +1203,7 @@ async function update (currentUser, challengeId, data, isFull) {
let billingAccountId
if (data.status) {
if (data.status === constants.challengeStatuses.Active) {
if (_.isUndefined(_.get(challenge, 'legacy.directProjectId'))) {
if (!_.get(challenge, 'legacy.pureV5Task') && _.isUndefined(_.get(challenge, 'legacy.directProjectId'))) {
throw new errors.BadRequestError('You cannot activate the challenge as it has not been created on legacy yet. Please try again later or contact support.')
}
billingAccountId = await helper.getProjectBillingAccount(_.get(challenge, 'legacy.directProjectId'))
Expand Down Expand Up @@ -1230,6 +1234,9 @@ async function update (currentUser, challengeId, data, isFull) {
if (_.get(challenge, 'legacy.useSchedulingAPI') && _.get(data, 'legacy.useSchedulingAPI') && _.get(challenge, 'legacy.useSchedulingAPI') !== _.get(data, 'legacy.useSchedulingAPI')) {
throw new errors.ForbiddenError('Cannot change legacy.useSchedulingAPI')
}
if (_.get(challenge, 'legacy.pureV5Task') && _.get(data, 'legacy.pureV5Task') && _.get(challenge, 'legacy.pureV5Task') !== _.get(data, 'legacy.pureV5Task')) {
throw new errors.ForbiddenError('Cannot change legacy.pureV5Task')
}

if (!_.isUndefined(challenge.legacy) && !_.isUndefined(data.legacy)) {
_.extend(challenge.legacy, data.legacy)
Expand Down Expand Up @@ -1672,7 +1679,8 @@ function sanitizeChallenge (challenge) {
'screeningScorecardId',
'reviewScorecardId',
'isTask',
'useSchedulingAPI'
'useSchedulingAPI',
'pureV5Task'
])
}
if (challenge.metadata) {
Expand Down Expand Up @@ -1728,7 +1736,8 @@ fullyUpdateChallenge.schema = {
screeningScorecardId: Joi.number().integer(),
reviewScorecardId: Joi.number().integer(),
isTask: Joi.boolean(),
useSchedulingAPI: Joi.boolean()
useSchedulingAPI: Joi.boolean(),
pureV5Task: Joi.boolean()
}).unknown(true),
task: Joi.object().keys({
isTask: Joi.boolean().default(false),
Expand Down Expand Up @@ -1824,7 +1833,8 @@ partiallyUpdateChallenge.schema = {
directProjectId: Joi.number(),
forumId: Joi.number().integer(),
isTask: Joi.boolean(),
useSchedulingAPI: Joi.boolean()
useSchedulingAPI: Joi.boolean(),
pureV5Task: Joi.boolean()
}).unknown(true),
task: Joi.object().keys({
isTask: Joi.boolean().default(false),
Expand Down