-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Validate transfer program/orgUnit combo [DHIS2-17880][2.40]
- Loading branch information
Showing
4 changed files
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ | |
import static org.hisp.dhis.utils.Assertions.assertIsEmpty; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.time.Instant; | ||
|
@@ -61,6 +62,7 @@ | |
import org.hisp.dhis.user.sharing.UserAccess; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.security.access.AccessDeniedException; | ||
|
||
/** | ||
* @author Ameen Mohamed <[email protected]> | ||
|
@@ -141,6 +143,7 @@ protected void setUpTest() throws Exception { | |
programA = createProgram('A'); | ||
programA.setAccessLevel(AccessLevel.PROTECTED); | ||
programA.setTrackedEntityType(trackedEntityType); | ||
programA.setOrganisationUnits(Set.of(organisationUnitA, organisationUnitB)); | ||
programService.addProgram(programA); | ||
UserAccess userAccess = new UserAccess(userA.getUid(), FULL); | ||
programA.setSharing(new Sharing(FULL, userAccess)); | ||
|
@@ -293,6 +296,19 @@ void shouldFindTrackedEntityWhenTransferredToInaccessibleOrgUnitIfSuperUser() { | |
.collect(Collectors.toList())); | ||
} | ||
|
||
@Test | ||
void shouldNotTransferOwnershipWhenOrgUnitNotAssociatedToProgram() { | ||
OrganisationUnit notAssociatedOrgUnit = createOrganisationUnit('C'); | ||
organisationUnitService.addOrganisationUnit(notAssociatedOrgUnit); | ||
Exception exception = | ||
assertThrows( | ||
AccessDeniedException.class, | ||
() -> transferOwnership(entityInstanceA1, programA, notAssociatedOrgUnit)); | ||
assertEquals( | ||
"User does not have access to change ownership for the entity-program combination", | ||
exception.getMessage()); | ||
} | ||
|
||
@Test | ||
void shouldFindTrackedEntityWhenProgramSuppliedAndUserIsOwner() { | ||
assignOwnership(entityInstanceA1, programA, organisationUnitA); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters