From 394858c2c870fd1091b128cfbe68b32f26330ba4 Mon Sep 17 00:00:00 2001 From: Marc Date: Mon, 27 Nov 2023 16:05:13 +0100 Subject: [PATCH] fix: Minor refactor after PR [TECH-1656] --- .../tracker/export/event/EventOperationParamsMapper.java | 5 ++++- .../tracker/export/event/EventOperationParamsMapperTest.java | 3 --- .../TrackedEntityOperationParamsMapperTest.java | 5 ++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java index 2579758ff93d..58c41bfcd0c5 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapper.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.tracker.export.event; +import static org.hisp.dhis.security.Authorities.F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS; import static org.hisp.dhis.tracker.export.OperationsParamsValidator.validateOrgUnitMode; import java.util.List; @@ -190,7 +191,9 @@ private void validateUser( User user, Program program, ProgramStage programStage, OrganisationUnit requestedOrgUnit) throws ForbiddenException { - if (user == null || user.isSuper()) { + if (user == null + || user.isSuper() + || user.isAuthorized(F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS)) { return; } if (program != null && !aclService.canDataRead(user, program)) { diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java index c896814dac72..d216d01f1299 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/event/EventOperationParamsMapperTest.java @@ -531,9 +531,6 @@ void shouldMapOrgUnitWhenModeAllProgramProvidedAndRequestedOrgUnitInSearchScope( when(currentUserService.getCurrentUser()).thenReturn(user); when(organisationUnitService.getOrganisationUnit(searchScopeChildOrgUnit.getUid())) .thenReturn(searchScopeChildOrgUnit); - when(organisationUnitService.isInUserHierarchy( - searchScopeChildOrgUnit.getUid(), user.getTeiSearchOrganisationUnitsWithFallback())) - .thenReturn(true); EventOperationParams operationParams = eventBuilder diff --git a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java index f48d45c46921..7a481af71454 100644 --- a/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java +++ b/dhis-2/dhis-services/dhis-service-tracker/src/test/java/org/hisp/dhis/tracker/export/trackedentity/TrackedEntityOperationParamsMapperTest.java @@ -79,7 +79,6 @@ import org.hisp.dhis.user.User; import org.hisp.dhis.user.UserRole; import org.hisp.dhis.webapi.controller.event.mapper.SortDirection; -import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -688,7 +687,7 @@ void shouldFailWhenGlobalSearchAndNoAttributeSpecified() { .build(); Exception IllegalQueryException = - Assert.assertThrows(IllegalQueryException.class, () -> mapper.map(operationParams)); + assertThrows(IllegalQueryException.class, () -> mapper.map(operationParams)); assertEquals( "At least 1 attributes should be mentioned in the search criteria.", @@ -715,7 +714,7 @@ void shouldaFailWhenGlobalSearchAndNoAttributeSpecified() { .build(); Exception IllegalQueryException = - Assert.assertThrows(IllegalQueryException.class, () -> mapper.map(operationParams)); + assertThrows(IllegalQueryException.class, () -> mapper.map(operationParams)); assertEquals("maxteicountreached", IllegalQueryException.getMessage()); }