use of org.hisp.dhis.tracker.domain.TrackedEntity in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForTrackedEntityUpdateWithUserNotInOrgUnitSearchHierarchy.
@Test
void verifyValidationFailsForTrackedEntityUpdateWithUserNotInOrgUnitSearchHierarchy() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(organisationUnitService.isInUserSearchHierarchyCached(user, organisationUnit)).thenReturn(false);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
hasTrackerError(reporter, E1003, TrackerType.TRACKED_ENTITY, trackedEntity.getUid());
}
use of org.hisp.dhis.tracker.domain.TrackedEntity in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForTrackedEntityUsingDeleteStrategyAndUserWithoutCascadeAuthority.
@Test
void verifyValidationFailsForTrackedEntityUsingDeleteStrategyAndUserWithoutCascadeAuthority() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(getTEIWithProgramInstances());
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
hasTrackerError(reporter, E1100, TrackerType.TRACKED_ENTITY, trackedEntity.getUid());
}
use of org.hisp.dhis.tracker.domain.TrackedEntity in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackedEntityWithDeletedProgramInstancesUsingDeleteStrategy.
@Test
void verifyValidationSuccessForTrackedEntityWithDeletedProgramInstancesUsingDeleteStrategy() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(getTEIWithDeleteProgramInstances());
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.tracker.domain.TrackedEntity in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationFailsForTrackedEntityAndUserWithoutWriteAccess.
@Test
void verifyValidationFailsForTrackedEntityAndUserWithoutWriteAccess() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(CodeGenerator.generateUid()).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.CREATE_AND_UPDATE);
when(organisationUnitService.isInUserSearchHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(false);
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
hasTrackerError(reporter, E1001, TrackerType.TRACKED_ENTITY, trackedEntity.getUid());
}
use of org.hisp.dhis.tracker.domain.TrackedEntity in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHookTest method verifyValidationSuccessForTrackedEntityUsingDeleteStrategyAndUserWithCascadeAuthority.
@Test
void verifyValidationSuccessForTrackedEntityUsingDeleteStrategyAndUserWithCascadeAuthority() {
TrackedEntity trackedEntity = TrackedEntity.builder().trackedEntity(TEI_ID).orgUnit(ORG_UNIT_ID).trackedEntityType(TEI_TYPE_ID).build();
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(organisationUnit);
when(ctx.getTrackedEntityType(TEI_TYPE_ID)).thenReturn(trackedEntityType);
when(ctx.getStrategy(trackedEntity)).thenReturn(TrackerImportStrategy.DELETE);
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(getTEIWithProgramInstances());
when(organisationUnitService.isInUserHierarchyCached(user, organisationUnit)).thenReturn(true);
when(aclService.canDataWrite(user, trackedEntityType)).thenReturn(true);
bundle.setUser(deleteTeiAuthorisedUser());
reporter = new ValidationErrorReporter(ctx);
validatorToTest.validateTrackedEntity(reporter, trackedEntity);
assertFalse(reporter.hasErrors());
}
Aggregations