Search in sources :

Example 16 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess5.

/**
 * program = DATA READ programStage = DATA READ orgUnit = Accessible status
 * = SUCCESS
 */
@Test
void testAddEventSimpleUserFullAccess5() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DATA_READ);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    Event eventFromPsi = eventService.getEvent(programStageInstance);
    assertNotNull(eventFromPsi);
    assertEquals(event.getUid(), eventFromPsi.getEvent());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 17 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess6.

/**
 * program = DATA WRITE programStage = DATA WRITE orgUnit = Accessible
 * status = SUCCESS
 */
@Test
void testAddEventSimpleUserFullAccess6() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    Event eventFromPsi = eventService.getEvent(programStageInstance);
    assertNotNull(eventFromPsi);
    assertEquals(event.getUid(), eventFromPsi.getEvent());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 18 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess9.

/**
 * program = programStage = DATA READ orgUnit = Accessible status = ERROR
 */
@Test
void testAddEventSimpleUserFullAccess9() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DEFAULT);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    assertThrows(IllegalQueryException.class, () -> eventService.getEvent(programStageInstance));
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 19 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess7.

/**
 * program = DATA WRITE programStage = DATA WRITE orgUnit = Not Accessible
 * status = ERROR
 */
@Test
void testAddEventSimpleUserFullAccess7() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.SUCCESS, importSummary.getStatus());
    assertEquals(event.getEvent(), importSummary.getReference());
    programA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    programStageA.setPublicAccess(AccessStringHelper.DATA_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1");
    injectSecurityContext(user);
    assertTrue(programStageInstanceService.programStageInstanceExists(event.getEvent()));
    ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance(event.getUid());
    assertNotNull(programStageInstance);
    assertThrows(IllegalQueryException.class, () -> eventService.getEvent(programStageInstance));
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) ProgramStageInstance(org.hisp.dhis.program.ProgramStageInstance) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 20 with STATUS

use of org.hisp.dhis.dxf2.events.trackedentity.store.query.EventQuery.COLUMNS.STATUS in project dhis2-core by dhis2.

the class EventSecurityTest method testAddEventSimpleUserFullAccess2.

/**
 * program = DATA READ programStage = DATA READ/WRITE orgUnit = Accessible
 * status = ERROR
 */
@Test
void testAddEventSimpleUserFullAccess2() {
    programA.setPublicAccess(AccessStringHelper.DATA_READ);
    programStageA.setPublicAccess(AccessStringHelper.DATA_READ_WRITE);
    manager.update(programA);
    manager.update(programStageA);
    User user = createUser("user1").setOrganisationUnits(Sets.newHashSet(organisationUnitA));
    injectSecurityContext(user);
    Event event = createEvent(programA.getUid(), programStageA.getUid(), organisationUnitA.getUid());
    ImportSummary importSummary = eventService.addEvent(event, ImportOptions.getDefaultImportOptions(), false);
    assertEquals(ImportStatus.ERROR, importSummary.getStatus());
}
Also used : User(org.hisp.dhis.user.User) ImportSummary(org.hisp.dhis.dxf2.importsummary.ImportSummary) Event(org.hisp.dhis.dxf2.events.event.Event) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)28 User (org.hisp.dhis.user.User)20 ImportSummary (org.hisp.dhis.dxf2.importsummary.ImportSummary)18 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)16 Event (org.hisp.dhis.dxf2.events.event.Event)14 EventSearchParams (org.hisp.dhis.dxf2.events.event.EventSearchParams)10 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 ProgramStageInstance (org.hisp.dhis.program.ProgramStageInstance)8 GetMapping (org.springframework.web.bind.annotation.GetMapping)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 CategoryOptionCombo (org.hisp.dhis.category.CategoryOptionCombo)6 Enrollment (org.hisp.dhis.dxf2.events.enrollment.Enrollment)6 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)6 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)5 Period (org.hisp.dhis.period.Period)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5