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] Add checks to avoid exception on query execution if user is not mapped to location #1187

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<artifactId>opensrp-server-web</artifactId>
<packaging>war</packaging>
<version>3.2.11-SNAPSHOT</version>
<version>3.2.12-SNAPSHOT</version>
<name>opensrp-server-web</name>
<description>OpenSRP Server Web Application</description>
<url>https://github.com/OpenSRP/opensrp-server-web</url>
Expand All @@ -25,7 +25,7 @@
<redis.lettuce.version>6.1.6.RELEASE</redis.lettuce.version>
<opensrp.updatePolicy>always</opensrp.updatePolicy>
<nexus-staging-maven-plugin.version>1.5.1</nexus-staging-maven-plugin.version>
<opensrp.core.version>3.2.8-SNAPSHOT</opensrp.core.version>
<opensrp.core.version>3.2.9-ALPHA1-SNAPSHOT</opensrp.core.version>
<opensrp.connector.version>2.4.1-SNAPSHOT</opensrp.connector.version>
<opensrp.interface.version>2.0.1-SNAPSHOT</opensrp.interface.version>
<powermock.version>2.0.5</powermock.version>
Expand Down
22 changes: 13 additions & 9 deletions src/main/java/org/opensrp/web/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import org.opensrp.service.PractitionerService;
import org.opensrp.web.exceptions.MissingTeamAssignmentException;
import org.opensrp.web.rest.RestUtils;
import org.slf4j.LoggerFactory;
import org.smartregister.domain.Jurisdiction;
import org.smartregister.domain.PhysicalLocation;
import org.smartregister.domain.PlanDefinition.PlanStatus;
Expand Down Expand Up @@ -201,14 +200,19 @@ public ResponseEntity<String> authenticate(Authentication authentication) throws
try {
String userId = u.getBaseEntityId();
practionerOrganizationIds = practitionerService.getOrganizationsByUserId(userId);

for (AssignedLocations assignedLocation : organizationService
.findAssignedLocationsAndPlans(practionerOrganizationIds.right)) {
if (StringUtils.isNotBlank(assignedLocation.getJurisdictionId()))
locationIds.add(assignedLocation.getJurisdictionId());
if (StringUtils.isNotBlank(assignedLocation.getPlanId()))
planIdentifiers.add(assignedLocation.getPlanId());
}

if (practionerOrganizationIds != null && practionerOrganizationIds.right.size() > 0) {
for (AssignedLocations assignedLocation : organizationService
.findAssignedLocationsAndPlans(practionerOrganizationIds.right)) {
if (StringUtils.isNotBlank(assignedLocation.getJurisdictionId()))
locationIds.add(assignedLocation.getJurisdictionId());
if (StringUtils.isNotBlank(assignedLocation.getPlanId()))
planIdentifiers.add(assignedLocation.getPlanId());
}
} else {
throw new MissingTeamAssignmentException(
"User not mapped on any location. Make sure that user is assigned to an organization with valid Location(s) ");
}

jurisdictions.addAll(locationService.findLocationByIdsWithChildren(false, locationIds, Integer.MAX_VALUE));

Expand Down