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);
}
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())));
}
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()))));
}
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());
}
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());
}
Aggregations