Search in sources :

Example 26 with UserAccess

use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.

the class PatchServiceTest method testEmbeddedObjectEquality.

@Test
void testEmbeddedObjectEquality() {
    User adminUser = createAndInjectAdminUser();
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(adminUser));
    manager.save(userGroup);
    DataElement deA = createDataElement('A');
    DataElement deB = createDataElement('B');
    deA.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deA.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    deB.getSharing().addUserGroupAccess(new UserGroupAccess(userGroup, "rw------"));
    deB.getSharing().addUserAccess(new UserAccess(adminUser, "rw------"));
    patchService.diff(new PatchParams(deA, deB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.sharing.UserGroupAccess) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 27 with UserAccess

use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.

the class ProgramStageValidationStrategyTest method setUpTest.

@Override
protected void setUpTest() {
    final int testYear = Calendar.getInstance().get(Calendar.YEAR) - 1;
    userService = _userService;
    createUserAndInjectSecurityContext(false, "F_TRACKED_ENTITY_DATAVALUE_ADD", "F_TRACKED_ENTITY_DATAVALUE_DELETE", "F_UNCOMPLETE_EVENT", "F_PROGRAMSTAGE_ADD", "F_PROGRAMSTAGE_DELETE", "F_PROGRAM_PUBLIC_ADD", "F_PROGRAM_PRIVATE_ADD", "F_PROGRAM_DELETE", "F_TRACKED_ENTITY_ADD", "F_TRACKED_ENTITY_UPDATE", "F_TRACKED_ENTITY_DELETE", "F_DATAELEMENT_PUBLIC_ADD", "F_DATAELEMENT_PRIVATE_ADD", "F_DATAELEMENT_DELETE", "F_CATEGORY_COMBO_PUBLIC_ADD", "F_CATEGORY_COMBO_PRIVATE_ADD", "F_CATEGORY_COMBO_DELETE");
    User currentUser = currentUserService.getCurrentUser();
    UserAccess userAccess1 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess2 = new UserAccess(currentUser, "rwrw----");
    UserAccess userAccess3 = new UserAccess(currentUser, "rwrw----");
    organisationUnitA = createOrganisationUnit('A');
    organisationUnitA.addUser(currentUser);
    organisationUnitA.getSharing().addUserAccess(userAccess1);
    currentUser.getTeiSearchOrganisationUnits().add(organisationUnitA);
    manager.save(organisationUnitA, false);
    userService.updateUser(currentUser);
    TrackedEntityType trackedEntityType = createTrackedEntityType('A');
    trackedEntityType.getSharing().addUserAccess(userAccess1);
    manager.save(trackedEntityType, false);
    org.hisp.dhis.trackedentity.TrackedEntityInstance maleA = createTrackedEntityInstance(organisationUnitA);
    maleA.setTrackedEntityType(trackedEntityType);
    maleA.getSharing().addUserAccess(userAccess1);
    maleA.setCreatedBy(currentUser);
    manager.save(maleA, false);
    trackedEntityInstanceMaleA = trackedEntityInstanceService.getTrackedEntityInstance(maleA);
    DataElement dataElementA = createDataElement('A');
    dataElementA.setValueType(ValueType.INTEGER);
    dataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(dataElementA, false);
    DataElement dataElementB = createDataElement('B');
    dataElementB.setValueType(ValueType.TEXT);
    dataElementB.getSharing().addUserAccess(userAccess2);
    manager.save(dataElementB, false);
    DataElement dataElementC = createDataElement('C');
    dataElementC.setValueType(ValueType.INTEGER);
    dataElementC.getSharing().addUserAccess(userAccess3);
    manager.save(dataElementC, false);
    programStageA = createProgramStage('A', 0);
    programStageA.setValidationStrategy(ValidationStrategy.ON_COMPLETE);
    programStageA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageA, false);
    programA = createProgram('A', new HashSet<>(), organisationUnitA);
    programA.setProgramType(ProgramType.WITH_REGISTRATION);
    programA.getSharing().addUserAccess(userAccess1);
    manager.save(programA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementA = new ProgramStageDataElement();
    programStageDataElementA.setDataElement(dataElementA);
    programStageDataElementA.setProgramStage(programStageA);
    programStageDataElementA.setCompulsory(true);
    programStageDataElementA.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementA, false);
    // Create a compulsory PSDE
    ProgramStageDataElement programStageDataElementB = new ProgramStageDataElement();
    programStageDataElementB.setDataElement(dataElementB);
    programStageDataElementB.setProgramStage(programStageA);
    programStageDataElementB.setCompulsory(true);
    programStageDataElementB.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementB, false);
    // Create a NON-compulsory PSDE
    ProgramStageDataElement programStageDataElementC = new ProgramStageDataElement();
    programStageDataElementC.setDataElement(dataElementC);
    programStageDataElementC.setProgramStage(programStageA);
    programStageDataElementC.setCompulsory(false);
    programStageDataElementC.getSharing().addUserAccess(userAccess1);
    manager.save(programStageDataElementC, false);
    // Assign all 3 created PSDEs to created ProgramStage programStageA and
    // to
    // created Program programA
    programStageA.getProgramStageDataElements().add(programStageDataElementA);
    programStageA.getProgramStageDataElements().add(programStageDataElementB);
    programStageA.getProgramStageDataElements().add(programStageDataElementC);
    programStageA.setProgram(programA);
    programA.getProgramStages().add(programStageA);
    manager.update(programStageA);
    manager.update(programA);
    ProgramInstance programInstance = new ProgramInstance();
    programInstance.setProgram(programA);
    programInstance.setIncidentDate(new Date());
    programInstance.setEnrollmentDate(new Date());
    programInstance.setEntityInstance(maleA);
    programInstance.getSharing().addUserAccess(userAccess1);
    maleA.getProgramInstances().add(programInstance);
    manager.save(programInstance, false);
    manager.update(maleA);
    Period periodA = createPeriod(testYear + "03");
    periodA.getSharing().addUserAccess(userAccess1);
    manager.save(periodA, false);
    CategoryCombo categoryComboA = createCategoryCombo('A');
    CategoryOptionCombo categoryOptionComboA = createCategoryOptionCombo('A');
    categoryOptionComboA.setCategoryCombo(categoryComboA);
    categoryComboA.getSharing().addUserAccess(userAccess1);
    categoryOptionComboA.getSharing().addUserAccess(userAccess1);
    manager.save(categoryComboA, false);
    manager.save(categoryOptionComboA, false);
    dataValueAMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "");
    dataValueBMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "");
    dataValueCMissing = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "");
    dataValueA = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementA.getUid(), "42");
    dataValueB = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementB.getUid(), "Ford Prefect");
    dataValueC = new org.hisp.dhis.dxf2.events.event.DataValue(dataElementC.getUid(), "84");
}
Also used : DataValue(org.hisp.dhis.dxf2.events.event.DataValue) User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) ProgramInstance(org.hisp.dhis.program.ProgramInstance) Period(org.hisp.dhis.period.Period) Date(java.util.Date) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) TrackedEntityType(org.hisp.dhis.trackedentity.TrackedEntityType) ProgramStageDataElement(org.hisp.dhis.program.ProgramStageDataElement) DataElement(org.hisp.dhis.dataelement.DataElement) CategoryCombo(org.hisp.dhis.category.CategoryCombo) CategoryOptionCombo(org.hisp.dhis.category.CategoryOptionCombo) HashSet(java.util.HashSet)

Example 28 with UserAccess

use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.

the class SharingTest method setDtoUserAccessesClearsExisting.

@Test
void setDtoUserAccessesClearsExisting() {
    Sharing actual = new Sharing();
    User user1 = new User();
    user1.setUid("id");
    actual.setDtoUserAccesses(singleton(new org.hisp.dhis.user.UserAccess(user1, "rw------")));
    User user2 = new User();
    user2.setUid("uid");
    actual.setDtoUserAccesses(singleton(new org.hisp.dhis.user.UserAccess(user2, "r-------")));
    assertEquals(1, actual.getUsers().size());
    UserAccess userAccess = actual.getUsers().values().iterator().next();
    assertEquals("r-------", userAccess.getAccess());
    assertEquals("uid", userAccess.getId());
}
Also used : User(org.hisp.dhis.user.User) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 29 with UserAccess

use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.

the class SharingTest method addUserAccessIgnoresNull.

@Test
void addUserAccessIgnoresNull() {
    Sharing actual = new Sharing();
    actual.setUserAccesses(singleton(new UserAccess("rw------", "uid")));
    actual.addUserAccess(null);
    assertEquals(1, actual.getUsers().size());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Test(org.junit.jupiter.api.Test)

Example 30 with UserAccess

use of org.hisp.dhis.user.sharing.UserAccess in project dhis2-core by dhis2.

the class SharingTest method setUserAccessesClearsExisting.

@Test
void setUserAccessesClearsExisting() {
    Sharing actual = new Sharing();
    actual.setUserAccesses(singleton(new UserAccess("rw------", "id")));
    actual.setUserAccesses(singleton(new UserAccess("r-------", "uid")));
    assertEquals(1, actual.getUsers().size());
    UserAccess userAccess = actual.getUsers().values().iterator().next();
    assertEquals("r-------", userAccess.getAccess());
    assertEquals("uid", userAccess.getId());
}
Also used : Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) 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