Search in sources :

Example 16 with Visualization

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

the class DashboardTest method testGetAvailableItemByType.

@Test
void testGetAvailableItemByType() {
    Dashboard dashboard = new Dashboard();
    DashboardItem diA = new DashboardItem();
    DashboardItem diB = new DashboardItem();
    DashboardItem diC = new DashboardItem();
    diA.setUid("A");
    diB.setUid("B");
    diC.setUid("C");
    diA.setVisualization(new Visualization("A"));
    diB.getReports().add(new Report("A", null, null, new Visualization()));
    diB.getReports().add(new Report("B", null, null, new Visualization()));
    diC.getResources().add(new Document("A", null, false, null));
    diC.getResources().add(new Document("B", null, false, null));
    diC.getResources().add(new Document("C", null, false, null));
    dashboard.getItems().add(diA);
    dashboard.getItems().add(diB);
    dashboard.getItems().add(diC);
    assertEquals(diB, dashboard.getAvailableItemByType(DashboardItemType.REPORTS));
    assertEquals(diC, dashboard.getAvailableItemByType(DashboardItemType.RESOURCES));
    assertNull(dashboard.getAvailableItemByType(DashboardItemType.MAP));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) Report(org.hisp.dhis.report.Report) Document(org.hisp.dhis.document.Document) Test(org.junit.jupiter.api.Test)

Example 17 with Visualization

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

the class AclServiceTest method testNotShouldBlockAdminUpdatesForNoAuthorityUserEvenWithNonPublicObject.

@Test
void testNotShouldBlockAdminUpdatesForNoAuthorityUserEvenWithNonPublicObject() {
    User adminUser = createAndInjectAdminUser();
    assertEquals(adminUser, currentUserService.getCurrentUser());
    User user1 = createUser("user1A4");
    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(adminUser);
    assertEquals(adminUser, currentUserService.getCurrentUser());
    List<ErrorReport> errorReports = aclService.verifySharing(visualization, adminUser);
    assertTrue(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 18 with Visualization

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

the class AclServiceTest method testUserBCanUpdateVisualizationWithAuthorityNoUserAccess.

@Test
void testUserBCanUpdateVisualizationWithAuthorityNoUserAccess() {
    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);
    manager.update(visualization);
    assertFalse(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) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with Visualization

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

the class AclServiceTest method testShouldBlockUpdatesForNoAuthorityUser.

@Test
void testShouldBlockUpdatesForNoAuthorityUser() {
    User adminUser = createAndInjectAdminUser();
    assertEquals(adminUser, currentUserService.getCurrentUser());
    User userNoAuthorities = createUser("user1A2");
    manager.save(userNoAuthorities);
    Visualization visualization = new Visualization();
    visualization.setName("RT");
    visualization.setCreatedBy(adminUser);
    visualization.getSharing().setOwner(adminUser);
    visualization.setAutoFields();
    visualization.setPublicAccess(AccessStringHelper.READ);
    visualization.setExternalAccess(true);
    visualization.setType(VisualizationType.COLUMN);
    manager.save(visualization);
    injectSecurityContext(userNoAuthorities);
    assertEquals(userNoAuthorities, currentUserService.getCurrentUser());
    List<ErrorReport> errorReports = aclService.verifySharing(visualization, userNoAuthorities);
    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 20 with Visualization

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

the class AclServiceTest method testResetSharingPropsPrivate.

@Test
void testResetSharingPropsPrivate() {
    User user = createAdminUser();
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setExternalAccess(true);
    visualization.setType(VisualizationType.COLUMN);
    assertFalse(aclService.verifySharing(visualization, user).isEmpty());
    aclService.resetSharing(visualization, user);
    assertTrue(AccessStringHelper.DEFAULT.equals(visualization.getPublicAccess()));
    assertFalse(visualization.getExternalAccess());
    assertTrue(visualization.getUserAccesses().isEmpty());
    assertTrue(visualization.getUserGroupAccesses().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