Search in sources :

Example 6 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class AclServiceTest method testResetSharingEventVisualizationPropsPrivate.

@Test
void testResetSharingEventVisualizationPropsPrivate() {
    // Given
    User user = createAdminUser();
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setExternalAccess(true);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertFalse(aclService.verifySharing(eventVisualization, user).isEmpty());
    // When
    aclService.resetSharing(eventVisualization, user);
    // Then
    assertEquals(AccessStringHelper.DEFAULT, eventVisualization.getPublicAccess());
    assertFalse(eventVisualization.getExternalAccess());
    assertTrue(eventVisualization.getUserAccesses().isEmpty());
    assertTrue(eventVisualization.getUserGroupAccesses().isEmpty());
}
Also used : User(org.hisp.dhis.user.User) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 7 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class AclServiceTest method testUserBCanUpdateEventVisualizationWithAuthorityNoUserAccess.

@Test
void testUserBCanUpdateEventVisualizationWithAuthorityNoUserAccess() {
    // Given
    User userA = createUser('A');
    manager.save(userA);
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setName("FavA");
    eventVisualization.setCreatedBy(userA);
    eventVisualization.getSharing().setOwner(userA);
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, eventVisualization));
    manager.save(eventVisualization);
    // Then
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setAutoFields();
    userAuthorityGroup.setName("UR");
    userAuthorityGroup.getAuthorities().add("F_EVENT_VISUALIZATION_PUBLIC_ADD");
    manager.save(userAuthorityGroup);
    User userB = createUser('B');
    userB.getUserAuthorityGroups().add(userAuthorityGroup);
    manager.save(userB);
    manager.update(eventVisualization);
    assertFalse(aclService.canUpdate(userB, eventVisualization));
}
Also used : User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 8 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class AclServiceTest method testResetSharingEventVisualizationPropsPublic.

@Test
void testResetSharingEventVisualizationPropsPublic() {
    // Given
    User user = createAdminUser("F_EVENT_VISUALIZATION_PUBLIC_ADD");
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setExternalAccess(true);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertFalse(aclService.verifySharing(eventVisualization, user).isEmpty());
    // When
    aclService.resetSharing(eventVisualization, user);
    // Then
    assertEquals(AccessStringHelper.READ_WRITE, eventVisualization.getPublicAccess());
    assertFalse(eventVisualization.getExternalAccess());
    assertTrue(eventVisualization.getUserAccesses().isEmpty());
    assertTrue(eventVisualization.getUserGroupAccesses().isEmpty());
}
Also used : User(org.hisp.dhis.user.User) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class AclServiceTest method testCanUpdatePrivateEventVisualization.

@Test
void testCanUpdatePrivateEventVisualization() {
    // Given
    User user = createAdminUser("F_DATAELEMENT_PRIVATE_ADD");
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.setAutoFields();
    eventVisualization.setCreatedBy(user);
    eventVisualization.getSharing().setOwner(user);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    // Then
    assertTrue(aclService.canUpdate(user, eventVisualization));
}
Also used : User(org.hisp.dhis.user.User) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class DashboardItemDeletionHandlerTest method testDeleteEventVisualization.

@Test
void testDeleteEventVisualization() {
    programService.addProgram(program);
    EventVisualization eventVisualization = createEventVisualization('A', program);
    eventVisualizationService.save(eventVisualization);
    dashboardItem.setEventVisualization(eventVisualization);
    dashboardService.saveDashboard(dashboard);
    assertEquals(1, dashboardService.getEventVisualizationDashboardItems(eventVisualization).size());
    assertEquals(1, dashboard.getItemCount());
    eventVisualizationService.delete(eventVisualization);
    assertEquals(0, dashboardService.getEventVisualizationDashboardItems(eventVisualization).size());
    assertEquals(0, dashboard.getItemCount());
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)31 Test (org.junit.jupiter.api.Test)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)7 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 User (org.hisp.dhis.user.User)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 JpaQueryParameters (org.hisp.dhis.hibernate.JpaQueryParameters)3 Interpretation (org.hisp.dhis.interpretation.Interpretation)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 EventChart (org.hisp.dhis.eventchart.EventChart)2 EventReport (org.hisp.dhis.eventreport.EventReport)2 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2