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

Add mutation to clear user roles and facilities #7978

Merged
merged 2 commits into from
Aug 5, 2024

Conversation

emyl3
Copy link
Collaborator

@emyl3 emyl3 commented Aug 2, 2024

BACKEND PULL REQUEST

Related Issue

Changes Proposed

  • Introduces a mutation that takes a user's email and marks their ApiUserRole and ApiUserFacility entries as deleted

Additional Information

  • Left the mutation flexible to be called on any user, but wrote a comment about the repercussions of calling the mutation on a non-site-admin user
    • will be ok to call this while the feature flag is off because user role and facility info will be repopulated but if this is called after the transition it will be an issue

Testing

  • deployed on dev2
  • call this mutation on a user that has role and facility entries populated, check in metabase they are deleted
mutation ($username: String!) {
    clearUserRolesAndFacilities (
        username: $username
    ) {
        nameInfo {
            firstName
        }
    }
}

@emyl3 emyl3 force-pushed the elisa/7598-remove-roles-facilities-mutation branch 2 times, most recently from d550010 to 594a1fd Compare August 2, 2024 16:08
Comment on lines 180 to 181
public ApiUser markUserRolesAndFacilitiesAsDeleted(@Argument String username) {
return _us.markUserRolesAndFacilitiesAsDeleted(username);
Copy link
Collaborator

Choose a reason for hiding this comment

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

only nit is can we name these clearUserRolesandFacilities or something like that? "mark as deleted" to me implies that there's an isDeleted flag we are flipping and that this is reversible, but we're just clearing them for 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.

Will do! thank you, merethe!

Copy link

sonarcloud bot commented Aug 5, 2024

@emyl3
Copy link
Collaborator Author

emyl3 commented Aug 5, 2024

@mehansen method has been renamed -- ready for rereview!

@emyl3 emyl3 requested a review from mehansen August 5, 2024 15:33
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! Created a new user with roles on dev2 and confirmed these were deleted after the mutation

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 on dev2 with a new user whose rolls were deleted after successfully calling the new endpoint -- LGTM! Thanks for your work on this

public ApiUser clearUserRolesAndFacilities(String username) {
ApiUser foundUser =
_apiUserRepo.findByLoginEmail(username).orElseThrow(NonexistentUserException::new);
foundUser.clearRolesAndFacilities();
Copy link
Contributor

Choose a reason for hiding this comment

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

worth considering for a followup PR: could we stick a check for whether the found user is a site admin? Think this would entail extending our site admin validation code since from what I can tell, it grabs that information from the currently-logged in user auth properties, but think that

  1. doing an explicit check is the safest way to make sure we don't end up in a unsupported state
  2. Having a "is this email in the site admin group" is a generally useful method to have.

Since all this is behind a feature flag / this mutation is needed to clean up a testing env, no need to address here, but to consider as a follow up

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created this issue to keep track of this effort: #8001
Thank you, @fzhao99! 😸

@emyl3 emyl3 added this pull request to the merge queue Aug 5, 2024
Merged via the queue into main with commit df5dabb Aug 5, 2024
42 checks passed
@emyl3 emyl3 deleted the elisa/7598-remove-roles-facilities-mutation branch August 5, 2024 18:22
@emyl3
Copy link
Collaborator Author

emyl3 commented Aug 5, 2024

Paired with @mehansen to remove roles and facilities of prod site admin users on 08/05/2024.

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