use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testValidateTrackedEntityAttributeSecurityShared.
@Test
void testValidateTrackedEntityAttributeSecurityShared() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_tea_not_shared.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
String[] testAuths = { "F_DATAELEMENT_PUBLIC_ADD", "F_PROGRAM_PUBLIC_ADD", "F_ORGANISATIONUNIT_ADD", "F_ORGANISATIONUNITLEVEL_UPDATE", "F_TRACKED_ENTITY_ATTRIBUTE_PUBLIC_ADD", "F_USER_ADD", "F_PROGRAMSTAGE_ADD", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_USER_ADD_WITHIN_MANAGED_GROUP" };
User testUser = createUser("A", testAuths);
TrackedEntityAttribute tea1 = manager.get(TrackedEntityAttribute.class, "cpaMZredRXb");
TrackedEntityAttribute tea2 = manager.get(TrackedEntityAttribute.class, "QhEcRpLZwMb");
UserAccess userAccess1 = new UserAccess(testUser, "rw------");
tea1.getSharing().addUserAccess(userAccess1);
UserAccess userAccess2 = new UserAccess(testUser, "rw------");
tea2.getSharing().addUserAccess(userAccess2);
manager.update(tea1);
manager.update(tea2);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_tea_update.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
params.setObjects(metadata);
params.setUser(testUser);
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
}
Aggregations