-
Notifications
You must be signed in to change notification settings - Fork 179
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
[user accounts] Fixing users being always inserted into examiner table upon save #3829
[user accounts] Fixing users being always inserted into examiner table upon save #3829
Conversation
@cmadjar This requires phpcs |
)) | ||
) { | ||
print_r('other situation'); | ||
print_r($ex_radiologist); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that for debuging?
&& empty($ex_curr_sites) | ||
)) | ||
) { | ||
print_r('other situation'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that for debuging?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops. Yes. I will remove it. Sorry :S
&& !empty($ex_curr_sites) | ||
&& empty($examinerID) | ||
) { | ||
print_r("radio, pending, curr site not empty + examiner empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that for debuging?
@xlecours removed the print_r statements. |
'userID' => $uid, | ||
'full_name' => $values['Real_name'], | ||
'radiologist' => $ex_radiologist, | ||
'userID' => $uid, | ||
) | ||
); | ||
$examinerID = $examinerID = $DB->pselectOne( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to be just $examinerID = $DB->pselectOne(...)
, instead of $examinerID = $examinerID = $DB->pselectOne(...)
Created a user under User Accounts with no Examiner affiliations both before and after checking your branch out and it works as intended! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reviewed code and tested to verify my comments, but I really think I would like another set of eyes on this.
@@ -293,9 +290,16 @@ class Edit_User extends \NDB_Form | |||
// START EXAMINER UPDATE | |||
// If examiner not in table add him, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unrelated but can we change this to "If examiner not in the table add them,"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
$values = \Utility::nullifyEmpty($values, 'examiner_radiologist'); | ||
if (empty($examinerID)) { | ||
|
||
if (!empty($ex_radiologist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining the condition here is a good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
array('fullName' => $values['Real_name']) | ||
); | ||
} else { | ||
|
||
} elseif (!empty($examinerID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A comment explaining the condition logic here would be good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
&& empty($examinerID) | ||
) { | ||
$ex_radiologist = $ex_radiologist === 'Y' ? 1 : 0; | ||
$values = \Utility::nullifyEmpty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function call is useless here, we assigned $values[examiner_radiologist]
to $ex_radiologist
earlier and then checked for !empty($ex_radiologist)
. The call should be made outside of this if
statement.
I also don't see the point of making this call at all, the value is not used again and it's unset after this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. Now that I think of it, this is probably not useful. Will remove it.
&& empty($ex_curr_sites))) | ||
) { | ||
$ex_radiologist = $ex_radiologist === 'Y' ? 1 : 0; | ||
$values = \Utility::nullifyEmpty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on line 299.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -304,14 +308,25 @@ class Edit_User extends \NDB_Form | |||
'userID' => $uid, | |||
) | |||
); | |||
$examinerID = $examinerID = $DB->pselectOne( | |||
$examinerID = $DB->pselectOne( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why we need to extract the new examinerID here, it doesn't seem to be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmadjar I was wrong about this, it is used 👍
"cid" => $v, | ||
) | ||
); | ||
foreach ($ex_curr_sites as $k => $v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're missing a }
before this line (and subsequently have an extra at the end), otherwise new examiners won't have any site affiliation. Previously this code was run regardless of the empty status of $examinerID, and now it is only run when it is set. Setting the examiner status of an existing user for the first time breaks the page as a result.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is the one that sketches me out the most. I know that it does break when this condition is hit, but I didn't check if moving the }
would fix it. Give it a shot and lmk @cmadjar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!! Your suggestion worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ZainVirani Thanks for the comments! They should all have been taken care of in the last commit. Please re-review at your convenience.
Thanks again!
@@ -293,9 +290,16 @@ class Edit_User extends \NDB_Form | |||
// START EXAMINER UPDATE | |||
// If examiner not in table add him, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
$values = \Utility::nullifyEmpty($values, 'examiner_radiologist'); | ||
if (empty($examinerID)) { | ||
|
||
if (!empty($ex_radiologist) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
&& empty($examinerID) | ||
) { | ||
$ex_radiologist = $ex_radiologist === 'Y' ? 1 : 0; | ||
$values = \Utility::nullifyEmpty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point. Now that I think of it, this is probably not useful. Will remove it.
array('fullName' => $values['Real_name']) | ||
); | ||
} else { | ||
|
||
} elseif (!empty($examinerID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
&& empty($ex_curr_sites))) | ||
) { | ||
$ex_radiologist = $ex_radiologist === 'Y' ? 1 : 0; | ||
$values = \Utility::nullifyEmpty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"cid" => $v, | ||
) | ||
); | ||
foreach ($ex_curr_sites as $k => $v) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!! Your suggestion worked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small change still required.
foreach ($prev_sites as $row => $center) { | ||
array_push($ex_prev_sites, $center['centerID']); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I think this should be on line 350 instead of here. The original file had the next foreach loop inside of the else statement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -304,14 +308,25 @@ class Edit_User extends \NDB_Form | |||
'userID' => $uid, | |||
) | |||
); | |||
$examinerID = $examinerID = $DB->pselectOne( | |||
$examinerID = $DB->pselectOne( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmadjar I was wrong about this, it is used 👍
@ZainVirani Good catch! I corrected the misplaced closing curly bracket. Please re-review at your convenience. Thanks a lot! |
@ZainVirani please re-review @jesscall please re-test on ccna DB (make sure that when examiner sites are checked the examiner entry in the table contains the userID reference, make sure the removal of examiners also works) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it kinda bothers me that an if/elseif statement isn't followed by an else :p but other than that, it looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fault in logic
|| (empty($ex_radiologist) | ||
&& empty($ex_pending) | ||
&& empty($ex_curr_sites))) | ||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fault in logic above, if examiner ID exists, there is no way the examiner pending and approval can be reset to null (the columns in SQL are not nullable, examiners can not be deleted and there is no code below to handle that case) thus the last segment of this statemnt should be removed.
|| (empty($ex_radiologist)
&& empty($ex_pending)
&& empty($ex_curr_sites))
The possible cases are:
!empty($examinerID) && !empty($ex_pending) && !empty($ex_radiologist)) &&
empty($ex_curr_sites)
-> examiner existed but we just removed all its sites||
!empty($ex_curr_sites)
-> examiner existed and we changed its sites
empty($examinerID) && !empty($ex_pending) && !empty($ex_radiologist)) &&
!empty($ex_curr_sites)
-> examiner is new and we added its sites
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ridz1208 I changed the logic as you suggested. FYI, the following case is impossible: !empty($examinerID) && !empty($ex_pending) && !empty($ex_radiologist) && empty($ex_curr_sites)
due to data entry checks. If there are no sites for the examiner, then Radiologist and Pending fields must be emptied out in order for the form to save. That is why I originally added the second "or" with all empty fields.
|| ((empty($ex_radiologist)
&& empty($ex_pending)
&& empty($ex_curr_sites)))
But indeed, in case the requirements for data entry change in the form, probably best to simplify the 'or' part of the logic to || empty($ex_curr_sites)
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are correct but that means that there is a bigger fautl in logic in the field validation in the front end. Thats def not within the scope of this PR since its not a bugfix but rather a minor revamp.
This should do for the moment. I will try to test as soon as I can.
@ZainVirani @zaliqarosli wouldn't mind a double check on the logic, look at what the code is handling below to know what the if statement has to check for |
&& ((!empty($ex_radiologist) | ||
&& !empty($ex_pending) | ||
&& !empty($ex_curr_sites)) | ||
|| empty($ex_curr_sites)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmadjar, addressing your most recent change, shouldn't the else if statement be:
else if (!empty($examinerID)
&& !empty($ex_pending)
&& !empty($ex_radiologist))
&& (empty($ex_curr_sites) || !empty($ex_curr_sites))
) {
// The case where the examiner already exists
// and has either all sites being deleted or the sites are being changed
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @um4r12 ,
Thanks for the sugesstion. Actually, I tried that and it does not work as it is impossible to be in the following condition !empty($examinerID) && !empty($ex_pending) && !empty($ex_radiologist)) && empty($ex_curr_sites)
in the frontend. To remove all the sites from an examiner, you have to unselect radiologist and ex_pending. Currently, only lets you be in either of the following conditions:
!empty($examinerID) && !empty($ex_pending) && !empty($ex_radiologist)) && !empty($ex_curr_sites)
!empty($examinerID) && empty($ex_pending) && empty($ex_radiologist)) && empty($ex_curr_sites)
which I simplified in my last commit by!empty($examinerID) && empty($ex_curr_sites)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cmadjar is correct, its not ideal but is acceptable in the scope of this bugfix. a revap of the logic is def needed to prevent unsetting of all fields and to sync the validation checks to the processing.
array('fullName' => $values['Real_name']) | ||
); | ||
} else { | ||
|
||
// } elseif (!empty($examinerID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commented code should not be submitted
@cmadjar I hope you dont mind, I pushed directly to your branch to fix phpcs |
This PR fixes the issue that whenever a user has the examiner_multisite permission and creates a new user, the new user will always be added to the examiner table even if no examiner options were set.
This bug was found by @ZainVirani so assigning him to be a reviewer to this new PR.