Skip to content

Commit

Permalink
Temporary fix for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
enricocolasante committed Jan 17, 2025
1 parent 7e591bf commit 22e50cc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,6 @@ public class EventOperationParams {
*/
private List<Order> order;

private boolean includeAttributes;

private boolean includeAllDataElements;

@Builder.Default private Set<UID> events = new HashSet<>();

/** Data element filters per data element UID. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2683,7 +2683,7 @@ protected void injectSecurityContextUser(User user) {
}

user = userService.getUser(user.getUid());
UserDetails userDetails = userService.createUserDetails(user);
UserDetails userDetails = UserDetails.fromUser(user);

injectSecurityContext(userDetails);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
*/
package org.hisp.dhis.tracker.deduplication;

import static org.hisp.dhis.security.Authorities.ALL;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.List;
import java.util.Set;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.UID;
import org.hisp.dhis.dbms.DbmsManager;
Expand All @@ -52,6 +54,7 @@
import org.hisp.dhis.tracker.export.enrollment.EnrollmentService;
import org.hisp.dhis.tracker.imports.bundle.persister.TrackerObjectDeletionService;
import org.hisp.dhis.tracker.trackedentityattributevalue.TrackedEntityAttributeValueService;
import org.hisp.dhis.user.User;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -145,6 +148,8 @@ void shouldDeleteRelationShips() throws NotFoundException {
void shouldDeleteEnrollments() throws ForbiddenException, NotFoundException {
OrganisationUnit ou = createOrganisationUnit("OU_A");
organisationUnitService.addOrganisationUnit(ou);
User user = createAndAddUser(false, "user", Set.of(ou), Set.of(ou), ALL.toString());
injectSecurityContextUser(user);
TrackedEntity original = createTrackedEntity(ou);
TrackedEntity duplicate = createTrackedEntity(ou);
TrackedEntity control1 = createTrackedEntity(ou);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
package org.hisp.dhis.tracker.export.enrollment;

import static java.util.Collections.emptySet;
import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ACCESSIBLE;
import static org.hisp.dhis.common.OrganisationUnitSelectionMode.ALL;
import static org.hisp.dhis.common.OrganisationUnitSelectionMode.CAPTURE;
Expand Down Expand Up @@ -141,17 +140,20 @@ void setUp() {
manager.save(orgUnitChildA, false);
OrganisationUnit orgUnitGrandchildA = createOrganisationUnit('E', orgUnitChildA);
manager.save(orgUnitGrandchildA, false);
OrganisationUnit orgUnitZ = createOrganisationUnit('Z');
manager.save(orgUnitZ, false);

User user =
createAndAddUser(false, "user", Set.of(orgUnitA), Set.of(orgUnitA), "F_EXPORT_DATA");
user.setTeiSearchOrganisationUnits(Set.of(orgUnitA, orgUnitB, orgUnitC));
userWithoutOrgUnit = createUserWithAuth("userWithoutOrgUnit");
userWithoutOrgUnit.setTeiSearchOrganisationUnits(Set.of(orgUnitZ));
authorizedUser =
createAndAddUser(
false,
"test user",
emptySet(),
emptySet(),
Set.of(orgUnitA),
Set.of(orgUnitA),
"F_TRACKED_ENTITY_INSTANCE_SEARCH_IN_ALL_ORGUNITS");

trackedEntityTypeA = createTrackedEntityType('A');
Expand Down Expand Up @@ -373,13 +375,13 @@ void shouldFailGettingEnrollmentWhenUserHasNoAccessToProgramsTrackedEntityType()
trackedEntityTypeA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.updateNoAcl(trackedEntityTypeA);

ForbiddenException exception =
NotFoundException exception =
assertThrows(
ForbiddenException.class,
NotFoundException.class,
() ->
enrollmentService.getEnrollment(
UID.of(enrollmentA), EnrollmentParams.FALSE, false));
assertContains("access to tracked entity type", exception.getMessage());
assertContains("could not be found", exception.getMessage());
}

@Test
Expand Down Expand Up @@ -407,13 +409,13 @@ void shouldFailGettingEnrollmentWhenUserHasReadAccessToProgramButNoAccessToOrgUn

injectSecurityContextUser(userWithoutOrgUnit);

ForbiddenException exception =
NotFoundException exception =
assertThrows(
ForbiddenException.class,
NotFoundException.class,
() ->
enrollmentService.getEnrollment(
UID.of(enrollmentA), EnrollmentParams.FALSE, false));
assertContains("OWNERSHIP_ACCESS_DENIED", exception.getMessage());
assertContains("could not be found", exception.getMessage());
}

@Test
Expand All @@ -423,27 +425,27 @@ void shouldFailGettingEnrollmentWhenUserHasReadWriteAccessToProgramButNoAccessTo

injectSecurityContextUser(userWithoutOrgUnit);

ForbiddenException exception =
NotFoundException exception =
assertThrows(
ForbiddenException.class,
NotFoundException.class,
() ->
enrollmentService.getEnrollment(
UID.of(enrollmentA), EnrollmentParams.FALSE, false));
assertContains("OWNERSHIP_ACCESS_DENIED", exception.getMessage());
assertContains("could not be found", exception.getMessage());
}

@Test
void shouldFailGettingEnrollmentWhenUserHasNoAccessToProgramButAccessToOrgUnit() {
programA.getSharing().setPublicAccess(AccessStringHelper.DEFAULT);
manager.updateNoAcl(programA);

ForbiddenException exception =
NotFoundException exception =
assertThrows(
ForbiddenException.class,
NotFoundException.class,
() ->
enrollmentService.getEnrollment(
UID.of(enrollmentA), EnrollmentParams.FALSE, false));
assertContains("access to program", exception.getMessage());
assertContains("could not be found", exception.getMessage());
}

@Test
Expand Down Expand Up @@ -680,7 +682,7 @@ void shouldFailWhenOrgUnitModeAllAndUserNotAuthorized() {

@Test
void shouldFailWhenUserCanSearchEverywhereModeDescendantsAndOrgUnitNotInSearchScope() {
injectSecurityContextUser(authorizedUser);
injectSecurityContextUser(userWithoutOrgUnit);

EnrollmentOperationParams operationParams =
EnrollmentOperationParams.builder().orgUnitMode(DESCENDANTS).orgUnits(orgUnitA).build();
Expand Down Expand Up @@ -760,19 +762,16 @@ void shouldReturnChildrenOfRequestedOrgUnitWhenOrgUnitModeChildren()
}

@Test
void shouldFailWhenRequestingListOfEnrollmentsAndAtLeastOneNotAccessible() {
void shouldFailWhenRequestingListOfEnrollmentsAndAtLeastOneNotAccessible()
throws ForbiddenException {
injectSecurityContextUser(admin);
programA.getSharing().setPublicAccess("rw------");
manager.update(programA);

injectSecurityContextUser(authorizedUser);
ForbiddenException exception =
assertThrows(
ForbiddenException.class,
() -> enrollmentService.getEnrollments(UID.of(enrollmentA, enrollmentB)));
assertContains(
String.format("User has no data read access to program: %s", programA.getUid()),
exception.getMessage());
List<Enrollment> enrollments =
enrollmentService.getEnrollments(UID.of(enrollmentA, enrollmentB));
assertIsEmpty(enrollments);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void shouldFailToCreateEnrollmentNoteIfUserHasNoAccessToEnrollment() {
Note note = note();

assertThrows(
ForbiddenException.class,
NotFoundException.class,
() -> noteService.addNoteForEnrollment(note, UID.of("nxP7UnKhomJ")));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,6 @@ public EventOperationParams map(
.eventStatus(eventRequestParams.getStatus())
.attributeCategoryCombo(attributeCategoryCombo)
.attributeCategoryOptions(attributeCategoryOptions)
.includeAttributes(false)
.includeAllDataElements(false)
.dataElementFilters(dataElementFilters)
.attributeFilters(attributeFilters)
.events(eventUids)
Expand Down

0 comments on commit 22e50cc

Please sign in to comment.