Skip to content

close registration, submission, checkpoint submission after cancellation #604

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
Mar 29, 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
11 changes: 11 additions & 0 deletions src/common/phase-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,17 @@ class ChallengePhaseHelper {
return updatedPhases;
}

handlePhasesAfterCancelling(phases) {
return _.map(phases, (phase) => {
if (_.includes(["Registration", "Submission", "Checkpoint Submission"], phase.name)) {
phase.isOpen = false;
if (!_.isUndefined(phase.actualStartDate)) {
phase.actualEndDate = moment().toDate().toISOString();
}
}
});
}

async validatePhases(phases) {
if (!phases || phases.length === 0) {
return;
Expand Down
23 changes: 21 additions & 2 deletions src/services/ChallengeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,7 @@ async function updateChallenge(currentUser, challengeId, data) {
/* END self-service stuffs */

let isChallengeBeingActivated = false;
let isChallengeBeingCancelled = false;
if (data.status) {
if (data.status === constants.challengeStatuses.Active) {
if (
Expand All @@ -1619,6 +1620,20 @@ async function updateChallenge(currentUser, challengeId, data) {
}
}

if (_.includes([
constants.challengeStatuses.Cancelled,
constants.challengeStatuses.CancelledRequirementsInfeasible,
constants.challengeStatuses.CancelledPaymentFailed,
constants.challengeStatuses.CancelledFailedReview,
constants.challengeStatuses.CancelledFailedScreening,
constants.challengeStatuses.CancelledZeroSubmissions,
constants.challengeStatuses.CancelledWinnerUnresponsive,
constants.challengeStatuses.CancelledClientRequest,
constants.challengeStatuses.CancelledZeroRegistrations,
], data.status)) {
isChallengeBeingCancelled = true;
}

if (
data.status === constants.challengeStatuses.CancelledRequirementsInfeasible ||
data.status === constants.challengeStatuses.CancelledPaymentFailed
Expand Down Expand Up @@ -1723,9 +1738,9 @@ async function updateChallenge(currentUser, challengeId, data) {

let phasesUpdated = false;
if (
(data.phases && data.phases.length > 0) ||
((data.phases && data.phases.length > 0) ||
isChallengeBeingActivated ||
timelineTemplateChanged
timelineTemplateChanged) && !isChallengeBeingCancelled
) {
if (
challenge.status === constants.challengeStatuses.Completed ||
Expand Down Expand Up @@ -1754,6 +1769,10 @@ async function updateChallenge(currentUser, challengeId, data) {
phasesUpdated = true;
data.phases = newPhases;
}
if (isChallengeBeingCancelled) {
data.phases = await phaseHelper.handlePhasesAfterCancelling(challenge.phases);
phasesUpdated = true;
}
if (phasesUpdated || data.startDate) {
data.startDate = convertToISOString(_.min(_.map(data.phases, "scheduledStartDate")));
}
Expand Down