Search in sources :

Example 31 with UserGroup

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

the class ConfigurationController method setFeedbackRecipients.

@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/feedbackRecipients")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setFeedbackRecipients(@RequestBody String uid) throws NotFoundException {
    uid = trim(uid);
    UserGroup group = identifiableObjectManager.get(UserGroup.class, uid);
    if (group == null) {
        throw new NotFoundException("User group", uid);
    }
    Configuration configuration = configurationService.getConfiguration();
    configuration.setFeedbackRecipients(group);
    configurationService.setConfiguration(configuration);
}
Also used : Configuration(org.hisp.dhis.configuration.Configuration) NotFoundException(org.hisp.dhis.webapi.controller.exception.NotFoundException) UserGroup(org.hisp.dhis.user.UserGroup) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 32 with UserGroup

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

the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToProgramForUserGroupAccess.

@Test
void verifyUserHasWriteAccessToProgramForUserGroupAccess() {
    // Given
    final User user = createUser("A");
    final Program program = createProgram('A');
    UserGroup userGroup = new UserGroup("test-group", singleton(user));
    manager.save(userGroup, true);
    user.getGroups().add(userGroup);
    UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.DATA_READ_WRITE);
    program.setUserGroupAccesses(singleton(userGroupAccess));
    manager.save(program, false);
    manager.flush();
    // When
    final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
    // Then
    assertThat(programs.keySet(), hasSize(1));
    assertTrue(aclService.canDataWrite(user, programs.get(program.getUid())));
}
Also used : User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) UserGroup(org.hisp.dhis.user.UserGroup) UserGroupAccess(org.hisp.dhis.user.UserGroupAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 33 with UserGroup

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

the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToProgramStageForGroupAccess.

@Test
void verifyUserHasWriteAccessToProgramStageForGroupAccess() {
    // Given
    final User user = createUser("user1");
    final ProgramStage programStage = createProgramStage('A', 1);
    programStage.setPublicAccess(AccessStringHelper.DEFAULT);
    UserGroup userGroup = new UserGroup("test-group-programstage", singleton(user));
    manager.save(userGroup, true);
    user.getGroups().add(userGroup);
    programStage.getSharing().addUserGroupAccess(new org.hisp.dhis.user.sharing.UserGroupAccess(userGroup, AccessStringHelper.DATA_READ_WRITE));
    manager.save(programStage, false);
    final Program program = createProgram('A');
    program.setProgramStages(singleton(programStage));
    program.setPublicAccess(AccessStringHelper.DEFAULT);
    manager.save(program, false);
    manager.flush();
    // When
    final Map<String, Program> programs = programSupplier.get(getDefaultImportOptions(), singletonList(event));
    // Then
    assertThat(programs.keySet(), hasSize(1));
    assertTrue(aclService.canDataWrite(user, getProgramStage(programs.get(program.getUid()))));
}
Also used : User(org.hisp.dhis.user.User) Program(org.hisp.dhis.program.Program) ProgramStage(org.hisp.dhis.program.ProgramStage) UserGroup(org.hisp.dhis.user.UserGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 34 with UserGroup

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

the class ObjectBundleServiceTest method testCreateAndUpdateMetadata1.

@Test
void testCreateAndUpdateMetadata1() throws IOException {
    defaultSetup();
    Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
    UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertEquals(4, dataElementMap.size());
    assertNotNull(userGroup);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_create_and_update1.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport objectBundleValidationReport = objectBundleValidationService.validate(bundle);
    assertFalse(objectBundleValidationReport.hasErrorReports());
    objectBundleService.commit(bundle);
    DataElement dataElementA = dataElementMap.get("deabcdefghA");
    DataElement dataElementB = dataElementMap.get("deabcdefghB");
    DataElement dataElementC = dataElementMap.get("deabcdefghC");
    DataElement dataElementD = dataElementMap.get("deabcdefghD");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertEquals("DEA", dataElementA.getName());
    assertEquals("DEB", dataElementB.getName());
    assertEquals("DEC", dataElementC.getName());
    assertEquals("DED", dataElementD.getName());
    assertEquals("DECA", dataElementA.getCode());
    assertEquals("DECB", dataElementB.getCode());
    assertEquals("DECC", dataElementC.getCode());
    assertEquals("DECD", dataElementD.getCode());
    assertEquals("DESA", dataElementA.getShortName());
    assertEquals("DESB", dataElementB.getShortName());
    assertEquals("DESC", dataElementC.getShortName());
    assertEquals("DESD", dataElementD.getShortName());
    assertEquals("DEDA", dataElementA.getDescription());
    assertEquals("DEDB", dataElementB.getDescription());
    assertEquals("DEDC", dataElementC.getDescription());
    assertEquals("DEDD", dataElementD.getDescription());
    assertEquals(1, dataElementA.getUserGroupAccesses().size());
    assertEquals(0, dataElementB.getUserGroupAccesses().size());
    assertEquals(1, dataElementC.getUserGroupAccesses().size());
    assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) UserGroup(org.hisp.dhis.user.UserGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 35 with UserGroup

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

the class ObjectBundleServiceTest method testUpdateDataElementsCODE.

@Test
void testUpdateDataElementsCODE() throws IOException {
    defaultSetup();
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/de_update2.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setPreheatIdentifier(PreheatIdentifier.CODE);
    params.setImportStrategy(ImportStrategy.UPDATE);
    params.setObjects(metadata);
    Map<String, DataElement> dataElementMap = manager.getIdMap(DataElement.class, IdScheme.UID);
    UserGroup userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertEquals(4, dataElementMap.size());
    assertNotNull(userGroup);
    ObjectBundle bundle = objectBundleService.create(params);
    objectBundleValidationService.validate(bundle);
    objectBundleService.commit(bundle);
    DataElement dataElementA = dataElementMap.get("deabcdefghA");
    DataElement dataElementB = dataElementMap.get("deabcdefghB");
    DataElement dataElementC = dataElementMap.get("deabcdefghC");
    DataElement dataElementD = dataElementMap.get("deabcdefghD");
    assertNotNull(dataElementA);
    assertNotNull(dataElementB);
    assertNotNull(dataElementC);
    assertNotNull(dataElementD);
    assertEquals("DEA", dataElementA.getName());
    assertEquals("DEB", dataElementB.getName());
    assertEquals("DEC", dataElementC.getName());
    assertEquals("DED", dataElementD.getName());
    assertEquals("DataElementCodeA", dataElementA.getCode());
    assertEquals("DataElementCodeB", dataElementB.getCode());
    assertEquals("DataElementCodeC", dataElementC.getCode());
    assertEquals("DataElementCodeD", dataElementD.getCode());
    assertEquals("DESA", dataElementA.getShortName());
    assertEquals("DESB", dataElementB.getShortName());
    assertEquals("DESC", dataElementC.getShortName());
    assertEquals("DESD", dataElementD.getShortName());
    assertEquals("DEDA", dataElementA.getDescription());
    assertEquals("DEDB", dataElementB.getDescription());
    assertEquals("DEDC", dataElementC.getDescription());
    assertEquals("DEDD", dataElementD.getDescription());
    assertEquals(1, dataElementA.getUserGroupAccesses().size());
    assertEquals(0, dataElementB.getUserGroupAccesses().size());
    assertEquals(1, dataElementC.getUserGroupAccesses().size());
    assertEquals(0, dataElementD.getUserGroupAccesses().size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) UserGroup(org.hisp.dhis.user.UserGroup) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserGroup (org.hisp.dhis.user.UserGroup)76 User (org.hisp.dhis.user.User)50 Test (org.junit.jupiter.api.Test)32 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)23 UserGroupAccess (org.hisp.dhis.user.sharing.UserGroupAccess)22 DataElement (org.hisp.dhis.dataelement.DataElement)17 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)12 HashSet (java.util.HashSet)11 List (java.util.List)11 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)10 UserAccess (org.hisp.dhis.user.sharing.UserAccess)10 ClassPathResource (org.springframework.core.io.ClassPathResource)9 Program (org.hisp.dhis.program.Program)6 ArrayList (java.util.ArrayList)5 CategoryOption (org.hisp.dhis.category.CategoryOption)5 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Set (java.util.Set)4 ImportReport (org.hisp.dhis.dxf2.metadata.feedback.ImportReport)4 UserGroupAccess (org.hisp.dhis.user.UserGroupAccess)4