@@ -379,12 +379,15 @@ function * getSubmissionPhaseId (challengeId) {
379379 const checkPoint = _ . filter ( phases , { name : 'Checkpoint Submission' , isOpen : true } )
380380 const submissionPh = _ . filter ( phases , { name : 'Submission' , isOpen : true } )
381381 const finalFixPh = _ . filter ( phases , { name : 'Final Fix' , isOpen : true } )
382+ const approvalPh = _ . filter ( phases , { name : 'Approval' , isOpen : true } )
382383 if ( checkPoint . length !== 0 ) {
383384 phaseId = checkPoint [ 0 ] . phaseId
384385 } else if ( submissionPh . length !== 0 ) {
385386 phaseId = submissionPh [ 0 ] . phaseId
386387 } else if ( finalFixPh . length !== 0 ) {
387388 phaseId = finalFixPh [ 0 ] . phaseId
389+ } else if ( approvalPh . length !== 0 ) {
390+ phaseId = approvalPh [ 0 ] . phaseId
388391 }
389392 }
390393 return phaseId
@@ -449,7 +452,6 @@ function * checkCreateAccess (authUser, subEntity) {
449452
450453 // Get phases and winner detail from challengeDetails
451454 const phases = challengeDetails . body . phases
452- const winner = challengeDetails . body . winners
453455
454456 // Check if the User is registered for the contest
455457 const submitters = _ . filter ( currUserRoles , { role : 'Submitter' } )
@@ -460,14 +462,22 @@ function * checkCreateAccess (authUser, subEntity) {
460462 const submissionPhaseId = yield getSubmissionPhaseId ( subEntity . challengeId )
461463
462464 if ( submissionPhaseId == null ) {
463- throw new errors . HttpStatusError ( 403 , 'You are not allowed to submit when submission phase is not open ' )
465+ throw new errors . HttpStatusError ( 403 , 'You cannot create a submission in the current phase ' )
464466 }
465467
466468 const currPhase = _ . filter ( phases , { phaseId : submissionPhaseId } )
467469
468- if ( currPhase [ 0 ] . name === 'Final Fix' ) {
469- if ( ! authUser . handle . equals ( winner [ 0 ] . handle ) ) {
470- throw new errors . HttpStatusError ( 403 , 'Only winner is allowed to submit during Final Fix phase' )
470+ if ( currPhase [ 0 ] . name === 'Final Fix' || currPhase [ 0 ] . name === 'Approval' ) {
471+ // Check if the user created a submission in the Submission phase - only such users
472+ // will be allowed to submit during final phase
473+ const userSubmission = yield fetchFromES ( {
474+ challengeId,
475+ memberId : authUser . userId
476+ } , camelize ( 'Submission' ) )
477+
478+ // User requesting submission haven't made any submission - prevent them for creating one
479+ if ( userSubmission . total === 0 ) {
480+ throw new errors . HttpStatusError ( 403 , 'You are not expected to create a submission in the current phase' )
471481 }
472482 }
473483 } else {
0 commit comments