Skip to content

Commit

Permalink
[candidate_parameter] Consent Status data validation bugfix (#5000)
Browse files Browse the repository at this point in the history
This fixes the logic for data validation on consent status tab. As it stands, if no status stays no or record existed as NULL the validation checks that :

- consent date is not empty
- withdrawal date is empty

However, if Consent Status at one point changes from 'YES' to 'NO' ==> user must fill in date of withdrawal. Therefore, consents that = 'NO' and have non-empty dates of withdrawal are considered non-valid (Displays error message).
  • Loading branch information
jesscall authored and driusan committed Aug 29, 2019
1 parent 0ab86b8 commit 9e30cf0
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions modules/candidate_parameters/ajax/formHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,9 +450,10 @@ function editConsentStatusFields($db, $user)
];

// Validate data
$recordExists = array_key_exists($consentID, $candidateConsent);
$oldStatus = $candidateConsent[$consentID]['Status'] ?? null;
$validated = false;
$recordExists = array_key_exists($consentID, $candidateConsent);
$oldStatus = $candidateConsent[$consentID]['Status'] ?? null;
$oldWithdrawal = $candidateConsent[$consentID]['DateWithdrawn'] ?? null;
$validated = false;

switch ($status) {
case 'yes':
Expand All @@ -477,10 +478,11 @@ function editConsentStatusFields($db, $user)
requires only the date of consent.');
return;
}
} else { // If no status stays no or record existed as NULL,
// consent date and empty withdrawal date still required
} else { // If no status stays no or record existed as NULL
// consent date required and withdrawal date unchanged
if (($oldStatus === null || $oldStatus === 'no') && !empty($date)
&& empty($withdrawal)
&& ((empty($oldWithdrawal) && empty($withdrawal))
|| (!empty($oldWithdrawal) && !empty($withdrawal)))
) {
$validated = true;
} else if ($oldStatus === 'yes' && !empty($date)
Expand Down

0 comments on commit 9e30cf0

Please sign in to comment.