Search in sources :

Example 31 with UserAccess

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());
}
Also used : User(org.hisp.dhis.user.User) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) ProgramTrackedEntityAttribute(org.hisp.dhis.program.ProgramTrackedEntityAttribute) TrackedEntityAttribute(org.hisp.dhis.trackedentity.TrackedEntityAttribute) UserAccess(org.hisp.dhis.user.sharing.UserAccess) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) List(java.util.List) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserAccess (org.hisp.dhis.user.sharing.UserAccess)31 Test (org.junit.jupiter.api.Test)25 User (org.hisp.dhis.user.User)19 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)14 Sharing (org.hisp.dhis.user.sharing.Sharing)12 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)9 DataElement (org.hisp.dhis.dataelement.DataElement)8 Dashboard (org.hisp.dhis.dashboard.Dashboard)7 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)6 UserGroup (org.hisp.dhis.user.UserGroup)6 HashMap (java.util.HashMap)4 List (java.util.List)3 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)3 Schema (org.hisp.dhis.schema.Schema)3 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)3 Visualization (org.hisp.dhis.visualization.Visualization)3 Date (java.util.Date)2 DhisSpringTest (org.hisp.dhis.DhisSpringTest)2 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)2 BaseIdentifiableObject (org.hisp.dhis.common.BaseIdentifiableObject)2