use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToTrackedEntityTypeForUserAccess.
@Test
void verifyUserHasWriteAccessToTrackedEntityTypeForUserAccess() {
// Given
final User user = createUser("A");
final TrackedEntityType tet = createTrackedEntityType('A');
manager.save(tet);
UserAccess userAccess = new UserAccess(user, AccessStringHelper.DATA_READ_WRITE);
tet.setUserAccesses(Collections.singleton(userAccess));
manager.save(tet, false);
final Program program = createProgram('A');
program.setTrackedEntityType(tet);
program.setPublicAccess(AccessStringHelper.DEFAULT);
manager.save(program, false);
manager.flush();
// When
final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
// Then
assertThat(programs.keySet(), hasSize(1));
assertTrue(aclService.canDataWrite(user, getTrackedEntityType(programs.get(program.getUid()))));
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method verifyValidationSuccessForEnrollment.
@Test
void verifyValidationSuccessForEnrollment() {
OrganisationUnit orgUnit = organisationUnit(ORG_UNIT_ID);
when(ctx.getOrganisationUnit(ORG_UNIT_ID)).thenReturn(orgUnit);
TrackedEntityType teiType = trackedEntityType(TEI_TYPE_ID);
when(ctx.getProgram(PROGRAM_UID)).thenReturn(programWithRegistration(PROGRAM_UID, orgUnit, teiType));
when(ctx.getProgramWithOrgUnitsMap()).thenReturn(Collections.singletonMap(PROGRAM_UID, Collections.singletonList(ORG_UNIT_ID)));
when(ctx.getTrackedEntityInstance(TEI_ID)).thenReturn(trackedEntityInstance(TEI_TYPE_ID, teiType, orgUnit));
Enrollment enrollment = Enrollment.builder().orgUnit(ORG_UNIT_ID).program(PROGRAM_UID).enrollment(CodeGenerator.generateUid()).trackedEntity(TEI_ID).build();
hook.validateEnrollment(reporter, enrollment);
assertFalse(reporter.hasErrors());
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckDataRelationsValidationHookTest method trackedEntityType.
private TrackedEntityType trackedEntityType(String uid, char uniqueChar) {
TrackedEntityType trackedEntityType = createTrackedEntityType(uniqueChar);
trackedEntityType.setUid(uid);
return trackedEntityType;
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class JacksonRelationshipServiceTest method createRelationshipTypeWithTeiConstraint.
private RelationshipType createRelationshipTypeWithTeiConstraint() {
RelationshipType relationshipType = new RelationshipType();
relationshipType.setUid(CodeGenerator.generateUid());
RelationshipConstraint from = new RelationshipConstraint();
from.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
from.setTrackedEntityType(new TrackedEntityType("a", "b"));
RelationshipConstraint to = rnd.nextObject(RelationshipConstraint.class);
to.setRelationshipEntity(RelationshipEntity.TRACKED_ENTITY_INSTANCE);
to.setTrackedEntityType(new TrackedEntityType("b", "c"));
relationshipType.setFromConstraint(from);
relationshipType.setToConstraint(to);
return relationshipType;
}
use of org.hisp.dhis.trackedentity.TrackedEntityType in project dhis2-core by dhis2.
the class PreCheckSecurityOwnershipValidationHook method validateTrackedEntity.
@Override
public void validateTrackedEntity(ValidationErrorReporter reporter, TrackedEntity trackedEntity) {
TrackerImportValidationContext context = reporter.getValidationContext();
TrackerImportStrategy strategy = context.getStrategy(trackedEntity);
TrackerBundle bundle = context.getBundle();
User user = bundle.getUser();
checkNotNull(user, USER_CANT_BE_NULL);
checkNotNull(trackedEntity, TRACKED_ENTITY_CANT_BE_NULL);
checkNotNull(trackedEntity.getOrgUnit(), ORGANISATION_UNIT_CANT_BE_NULL);
// scope has to be checked
if (strategy.isCreate() || strategy.isDelete()) {
checkOrgUnitInCaptureScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
} else // if its to update trackedEntity, search scope has to be checked
{
checkOrgUnitInSearchScope(reporter, trackedEntity, context.getOrganisationUnit(trackedEntity.getOrgUnit()));
}
if (strategy.isDelete()) {
TrackedEntityInstance tei = context.getTrackedEntityInstance(trackedEntity.getTrackedEntity());
if (tei.getProgramInstances().stream().anyMatch(pi -> !pi.isDeleted()) && !user.isAuthorized(Authorities.F_TEI_CASCADE_DELETE.getAuthority())) {
TrackerErrorReport error = TrackerErrorReport.builder().uid(trackedEntity.getUid()).trackerType(TrackerType.TRACKED_ENTITY).errorCode(E1100).addArg(user).addArg(tei).build(bundle);
reporter.addError(error);
}
}
TrackedEntityType trackedEntityType = context.getTrackedEntityType(trackedEntity.getTrackedEntityType());
checkTeiTypeWriteAccess(reporter, trackedEntity.getUid(), trackedEntityType);
}
Aggregations