Skip to content
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

Conversation

cmadjar
Copy link
Collaborator

@cmadjar cmadjar commented Jul 16, 2018

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.

@cmadjar cmadjar added Category: Bug PR or issue that aims to report or fix a bug [branch] major labels Jul 16, 2018
@cmadjar cmadjar added this to the 20.0.0 milestone Jul 16, 2018
@cmadjar cmadjar requested a review from ZainVirani July 16, 2018 17:23
@johnsaigle
Copy link
Contributor

@cmadjar This requires phpcs

))
) {
print_r('other situation');
print_r($ex_radiologist);
Copy link
Contributor

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that for debuging?

Copy link
Collaborator Author

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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that for debuging?

@cmadjar
Copy link
Collaborator Author

cmadjar commented Jul 16, 2018

@xlecours removed the print_r statements.
@johnsaigle fixed the travis issues hopefully.

'userID' => $uid,
'full_name' => $values['Real_name'],
'radiologist' => $ex_radiologist,
'userID' => $uid,
)
);
$examinerID = $examinerID = $DB->pselectOne(
Copy link
Contributor

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(...)

@jesscall
Copy link
Contributor

jesscall commented Jul 16, 2018

Created a user under User Accounts with no Examiner affiliations both before and after checking your branch out and it works as intended!

@jesscall jesscall added the Passed manual tests PR has been successfully tested by at least one peer label Jul 16, 2018
um4r12
um4r12 previously approved these changes Jul 16, 2018
Copy link
Contributor

@ZainVirani ZainVirani left a 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,
Copy link
Contributor

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,"

Copy link
Collaborator Author

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)
Copy link
Contributor

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

Copy link
Collaborator Author

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)
Copy link
Contributor

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

Copy link
Collaborator Author

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(
Copy link
Contributor

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.

Copy link
Collaborator Author

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(
Copy link
Contributor

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.

Copy link
Collaborator Author

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(
Copy link
Contributor

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.

Copy link
Contributor

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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Collaborator Author

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.

@ZainVirani ZainVirani removed the Passed manual tests PR has been successfully tested by at least one peer label Jul 16, 2018
Copy link
Collaborator Author

@cmadjar cmadjar left a 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,
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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)
Copy link
Collaborator Author

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(
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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.

@xlecours xlecours dismissed their stale review July 17, 2018 13:52

change made

@ZainVirani ZainVirani dismissed um4r12’s stale review July 17, 2018 14:12

Accidental approval

Copy link
Contributor

@ZainVirani ZainVirani left a 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']);
}
}
Copy link
Contributor

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.

Copy link
Collaborator Author

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(
Copy link
Contributor

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 👍

@cmadjar
Copy link
Collaborator Author

cmadjar commented Jul 17, 2018

@ZainVirani Good catch! I corrected the misplaced closing curly bracket. Please re-review at your convenience. Thanks a lot!

@zaliqarosli zaliqarosli added the Passed manual tests PR has been successfully tested by at least one peer label Jul 24, 2018
@ridz1208 ridz1208 self-assigned this Jul 26, 2018
@ridz1208
Copy link
Collaborator

@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)

Copy link
Contributor

@zaliqarosli zaliqarosli left a 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!

Copy link
Collaborator

@ridz1208 ridz1208 left a 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)))
) {
Copy link
Collaborator

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

Copy link
Collaborator Author

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!

Copy link
Collaborator

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.

@ridz1208
Copy link
Collaborator

@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

@ridz1208 ridz1208 added State: Needs work PR awaiting additional work by the author to proceed and removed Passed manual tests PR has been successfully tested by at least one peer labels Jul 27, 2018
@cmadjar cmadjar removed the State: Needs work PR awaiting additional work by the author to proceed label Jul 30, 2018
um4r12
um4r12 previously requested changes Jul 30, 2018
&& ((!empty($ex_radiologist)
&& !empty($ex_pending)
&& !empty($ex_curr_sites))
|| empty($ex_curr_sites))
Copy link
Contributor

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
		  }

Copy link
Collaborator Author

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)

Copy link
Collaborator

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.

@cmadjar
Copy link
Collaborator Author

cmadjar commented Aug 1, 2018

@ridz1208 @um4r12 Please re-review. Thanks!

@ridz1208 ridz1208 dismissed stale reviews from um4r12 and themself August 2, 2018 01:54

stale

@ridz1208 ridz1208 added the Critical to release PR or issue is key for the release to which it has been assigned label Aug 3, 2018
array('fullName' => $values['Real_name'])
);
} else {

// } elseif (!empty($examinerID)
Copy link
Collaborator

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

@ridz1208
Copy link
Collaborator

ridz1208 commented Aug 4, 2018

@cmadjar I hope you dont mind, I pushed directly to your branch to fix phpcs

@ridz1208 ridz1208 added the Passed manual tests PR has been successfully tested by at least one peer label Aug 4, 2018
@ridz1208 ridz1208 merged commit 9a41406 into aces:20.0-release Aug 6, 2018
@cmadjar cmadjar deleted the Fixing_examiners_being_always_inserted_into_Examiner_table branch September 24, 2021 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug PR or issue that aims to report or fix a bug Critical to release PR or issue is key for the release to which it has been assigned Passed manual tests PR has been successfully tested by at least one peer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants