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

Fetch group info for users from DB when oktaMigrationEnabled is true #8105

Merged
merged 4 commits into from
Sep 19, 2024

Conversation

emyl3
Copy link
Collaborator

@emyl3 emyl3 commented Sep 6, 2024

BACKEND PULL REQUEST

Related Issue

Changes Proposed

  • Regardless of oktaMigrationEnabled flag status, continue to update groups and roles in Okta
  • When the oktaMigrationEnabled flag is set to true, read groups and roles from DB
  • When the oktaMigrationEnabled flag is set to false, read groups and roles from Okta

Affected flows:

  • adding org to queue (checking if the org is a duplicate)
  • reprovisioning user
  • updating user roles and privileges
  • users graphql query (I don't think we are calling this on the frontend 🤔)
  • verifying a pending organization
  • getting org admin users
  • confirmation modal when deleting a facility via site admin "Manage facility" tool (it displays how many users and patients are associated with only that facility)
Screenshot 2024-09-10 at 16 23 29

Additional Information

  • Separate tickets to address loading users with their status for the "Manage users" page

Testing

dev2 - oktaMigrationEnabled - true

dev3 - oktaMigrationEnabled - false

@emyl3 emyl3 force-pushed the elisa/7598-refactor-groupapi-calls branch 6 times, most recently from acf4def to 754ae1f Compare September 9, 2024 20:09
@emyl3 emyl3 force-pushed the elisa/7598-refactor-groupapi-calls branch from 754ae1f to b7956bc Compare September 10, 2024 14:37
}

// To be addressed in #8108
@AuthorizationConfiguration.RequirePermissionManageUsers
public List<ApiUserWithStatus> getUsersAndStatusInCurrentOrg() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ holding off on updating this until this is addressed #8103

Then, this will be updated in #8108

String orgAdminEmail = orgAdmin.get().getLoginEmail();
return oktaRepository.activateUser(orgAdminEmail);
} else {
throw new IllegalStateException("Organization does not have any org admins.");
Copy link
Collaborator Author

@emyl3 emyl3 Sep 10, 2024

Choose a reason for hiding this comment

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

⚠️ This else block changes the behavior of this method when the feature flag is enabled.

Previously, even if the org had no admin users this method would succeed

However, with this implementation if an org does not have an admin it will throw an exception.

Let me know if you think this should continue to have the same behavior as before. 🤔

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this makes sense. Btw do we have any additional context on the comment on this method? Is this an old reference to some account request workflow that hasn't been implemented?

/**
   * This method is for verifying an organization after the Experian identity verification process.
   * It should not be used for any other purpose and once we move to the updated account request
   * workflow this should be removed.
   */
  @Transactional(readOnly = false)
  public String verifyOrganizationNoPermissions(String externalId) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good question... Let me check that commit history in see if I can uncover anything... 🕵️

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the PR that introduced this change: #2096
I did a search in the repo and couldn't find any mention of a new or updated account request flow 🤔 so I'm not entirely sure what that comment is referencing....

* @return Integer - count of ApiUsers
*/
public Integer getUserWithSingleFacilityAccessCount(Facility facility) {
List<ApiUser> users = _userRepo.findAllBySingleFacilityAccess(facility);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

⚠️ Let me know if this makes sense to generate this count 🙏

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will fix this bug #7873 🤩

@emyl3 emyl3 marked this pull request as ready for review September 11, 2024 15:52
Copy link
Collaborator

@mpbrown mpbrown left a comment

Choose a reason for hiding this comment

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

Looks really great overall! Awesome work on this Elisa!

String orgAdminEmail = orgAdmin.get().getLoginEmail();
return oktaRepository.activateUser(orgAdminEmail);
} else {
throw new IllegalStateException("Organization does not have any org admins.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this makes sense. Btw do we have any additional context on the comment on this method? Is this an old reference to some account request workflow that hasn't been implemented?

/**
   * This method is for verifying an organization after the Experian identity verification process.
   * It should not be used for any other purpose and once we move to the updated account request
   * workflow this should be removed.
   */
  @Transactional(readOnly = false)
  public String verifyOrganizationNoPermissions(String externalId) {

.anyMatch(Predicate.isEqual(email))) {
List<String> adminUserEmails = getOrgAdminUserEmails(duplicateOrg.get());

if (adminUserEmails.stream().anyMatch(Predicate.isEqual(email))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to handle or otherwise flag if the org doesn't have any admins? (was thinking about no admin users after this comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's OK in this context because we are trying to check if the to-be-created new org might be a duplicate of another org. If there are no org admins in that duplicate org, it would throw the exception on line 155. Let me know what you think!

bobbywells52
bobbywells52 previously approved these changes Sep 17, 2024
Copy link
Collaborator

@bobbywells52 bobbywells52 left a comment

Choose a reason for hiding this comment

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

Tested in dev2 and dev3 and is working as excepted -- LGTM! Thank you for you continued heavy effort on this big lift 🙌🏻

@emyl3 emyl3 requested a review from mpbrown September 17, 2024 14:54
@emyl3
Copy link
Collaborator Author

emyl3 commented Sep 17, 2024

@mpbrown @mehansen @DanielSass Ready for re-review! Changes have been redeployed to dev2 and dev3 respectively

mpbrown
mpbrown previously approved these changes Sep 17, 2024
Copy link
Collaborator

@mpbrown mpbrown left a comment

Choose a reason for hiding this comment

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

LGTM on dev2 and dev3! Great work on this Elisa!

mehansen
mehansen previously approved these changes Sep 18, 2024
Copy link
Collaborator

@mehansen mehansen left a comment

Choose a reason for hiding this comment

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

looks great! I have some non-blocking naming nits but they are more personal preference so still approving

* @return Integer - count of ApiUsers
*/
public Integer getUserWithSingleFacilityAccessCount(Facility facility) {
List<ApiUser> users = _userRepo.findAllBySingleFacilityAccess(facility);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will fix this bug #7873 🤩

Copy link

private String getOrgExternalId(ApiUser apiUser) {
String orgExternalId;
if (_featureFlagsConfig.isOktaMigrationEnabled()) {
Optional<Organization> org = apiUser.getOrganizations().stream().findFirst();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have users with more than one organization? I don't think we do, but do we know that for certain / are there guardrails in place to ensure that can't happen?

Copy link
Collaborator

@DanielSass DanielSass left a comment

Choose a reason for hiding this comment

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

Everything looks good, thanks for pairing with me on the review @emyl3.
I think the only issues we noted were specific corner cases we need to make sure get included in the test plan.

Thanks for all your work on this

@emyl3 emyl3 added this pull request to the merge queue Sep 19, 2024
Merged via the queue into main with commit 8f61a00 Sep 19, 2024
38 checks passed
@emyl3 emyl3 deleted the elisa/7598-refactor-groupapi-calls branch September 19, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants