Search in sources :

Example 31 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testUserBCanUpdateVisualizationWithoutAuthority.

@Test
void testUserBCanUpdateVisualizationWithoutAuthority() {
    User userA = createUser('A');
    manager.save(userA);
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setName("FavA");
    visualization.setCreatedBy(userA);
    visualization.getSharing().setOwner(userA);
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setType(VisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, visualization));
    manager.save(visualization);
    User userB = createUser('B');
    manager.save(userB);
    visualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(visualization);
    assertTrue(aclService.canUpdate(userB, visualization));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 32 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testUserBCanUpdateVisualizationWithAuthority.

@Test
void testUserBCanUpdateVisualizationWithAuthority() {
    User userA = createUser('A');
    manager.save(userA);
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setName("FavA");
    visualization.setCreatedBy(userA);
    visualization.getSharing().setOwner(userA);
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setType(VisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, visualization));
    manager.save(visualization);
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setAutoFields();
    userAuthorityGroup.setName("UR");
    userAuthorityGroup.getAuthorities().add("F_VISUALIZATION_PUBLIC_ADD");
    manager.save(userAuthorityGroup);
    User userB = createUser('B');
    userB.getUserAuthorityGroups().add(userAuthorityGroup);
    manager.save(userB);
    visualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(visualization);
    assertTrue(aclService.canUpdate(userB, visualization));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserAccess(org.hisp.dhis.user.sharing.UserAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 33 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testCanUpdatePrivateVisualization.

@Test
void testCanUpdatePrivateVisualization() {
    User user = createAdminUser("F_DATAELEMENT_PRIVATE_ADD");
    Visualization visualization = new Visualization("Visualization");
    visualization.setAutoFields();
    visualization.setCreatedBy(user);
    visualization.getSharing().setOwner(user);
    visualization.setType(VisualizationType.COLUMN);
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    assertTrue(aclService.canUpdate(user, visualization));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 34 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testShouldBlockUpdatesForNoAuthorityUserEvenWithNonPublicObject.

@Test
void testShouldBlockUpdatesForNoAuthorityUserEvenWithNonPublicObject() {
    User adminUser = createAndInjectAdminUser();
    assertEquals(adminUser, currentUserService.getCurrentUser());
    User user1 = createUser("user1A3");
    User user2 = createUser("user2A3");
    injectSecurityContext(user1);
    assertEquals(user1, currentUserService.getCurrentUser());
    Visualization visualization = new Visualization();
    visualization.setName("RT");
    visualization.setCreatedBy(user1);
    visualization.getSharing().setOwner(user1);
    visualization.setAutoFields();
    visualization.setExternalAccess(false);
    visualization.setType(VisualizationType.COLUMN);
    manager.save(visualization);
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.update(visualization);
    injectSecurityContext(user2);
    assertEquals(user2, currentUserService.getCurrentUser());
    List<ErrorReport> errorReports = aclService.verifySharing(visualization, user2);
    assertFalse(errorReports.isEmpty());
}
Also used : ErrorReport(org.hisp.dhis.feedback.ErrorReport) Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 35 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AclServiceTest method testVerifyVisualizationCantExternalize.

@Test
void testVerifyVisualizationCantExternalize() {
    User user = createAdminUser("F_VISUALIZATION_PUBLIC_ADD");
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setExternalAccess(true);
    visualization.setType(VisualizationType.COLUMN);
    assertFalse(aclService.verifySharing(visualization, user).isEmpty());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Visualization (org.hisp.dhis.visualization.Visualization)48 Test (org.junit.jupiter.api.Test)36 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)26 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)14 User (org.hisp.dhis.user.User)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 List (java.util.List)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 Period (org.hisp.dhis.period.Period)4 Date (java.util.Date)3 Dashboard (org.hisp.dhis.dashboard.Dashboard)3 DataSet (org.hisp.dhis.dataset.DataSet)3 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2