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

fix: Org Unit split being assigned to incorrect users [DHIS2-18423] #19239

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

david-mackessy
Copy link
Contributor

@david-mackessy david-mackessy commented Nov 20, 2024

Issue

Org Unit split feature is assigning the split org units to incorrect users (sometimes all the users in the DB in certain circumstances)

Cause

After creating the UserQueryParams with the source OrganisationUnit, that OrganisationUnit was being overridden to use the User's OrganisationUnits carrying out the split.

In cases where the User either had no organisationUnits, dataViewOrganisationUnits, or teiSearchOrganisationUnits, then all the Users in the DB would be returned from the query, resulting in all Users getting the split OrganisationUnits.

Fix avoids using:

  • UserService#handleUserQueryParams which was overriding the source OrganisationUnit already set
  • UserStore#getUsers which tries to generate a handcrafted SQL query taking into consideration a multitude of options & checks using UserQueryParams (this looks too complex and tries to accommodate too many things). This resulted in returning all Users in the DB

Fix

Use a dedicated query to fetch the Users to be actioned.
Fewer select queries are generated as a result of the fix, and is not proportionate to the number of users found (old query was triggering 1 extra query per user found - manual testing).
Warning added to UserQueryParams property.

Testing

Automated

2 integration tests added

  • 1 for Org Unit split service: checking that the correct users get assigned the split org units
  • 1 for the store: checking the generated select query count & retrieved users

@david-mackessy david-mackessy marked this pull request as ready for review November 20, 2024 14:30
Copy link

sonarcloud bot commented Nov 20, 2024

@@ -224,4 +226,15 @@ Map<String, Optional<Locale>> findNotifiableUsersWithPasswordLastUpdatedBetween(
User getUserByVerificationToken(String token);

User getUserByVerifiedEmail(String email);

/**
* Method that retrieves all {@link User}s that have an entry for the {@link OrganisationUnit} in
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps not use "Method that" in method Javadoc, as it is implicit.

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.

2 participants