use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ProgramSupplierAclIntegrationTest method verifyUserHasWriteAccessToTrackedEntityTypeForGroupAccess.
@Test
void verifyUserHasWriteAccessToTrackedEntityTypeForGroupAccess() {
// Given
final User user = createUser("user1");
final TrackedEntityType tet = createTrackedEntityType('A');
manager.save(tet);
UserGroup userGroup = new UserGroup("test-group-tet", singleton(user));
manager.save(userGroup, true);
user.getGroups().add(userGroup);
UserGroupAccess userGroupAccess = new UserGroupAccess(userGroup, AccessStringHelper.DATA_READ_WRITE);
tet.setUserGroupAccesses(singleton(userGroupAccess));
manager.save(tet, false);
final Program program = createProgram('A');
program.setTrackedEntityType(tet);
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, getTrackedEntityType(programs.get(program.getUid()))));
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class MetadataImportServiceTest method testImportEmbeddedObjectWithSkipSharingIsTrue.
@Test
void testImportEmbeddedObjectWithSkipSharingIsTrue() throws IOException {
User user = createUser('A');
manager.save(user);
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user));
manager.save(userGroup);
userGroup = manager.get(UserGroup.class, "ugabcdefghA");
assertNotNull(userGroup);
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses.json").getInputStream(), RenderFormat.JSON);
MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
ImportReport report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
Visualization visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
assertNotNull(visualization);
assertEquals(1, visualization.getUserGroupAccesses().size());
assertEquals(1, visualization.getUserAccesses().size());
assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUserUid());
assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroupUid());
Visualization dataElementOperandVisualization = manager.get(Visualization.class, "qD72aBqsHvt");
assertNotNull(dataElementOperandVisualization);
assertEquals(2, dataElementOperandVisualization.getDataDimensionItems().size());
dataElementOperandVisualization.getDataDimensionItems().stream().forEach(item -> assertNotNull(item.getDataElementOperand()));
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses_update.json").getInputStream(), RenderFormat.JSON);
params = createParams(ImportStrategy.UPDATE, metadata);
params.setSkipSharing(true);
dbmsManager.clearSession();
report = importService.importMetadata(params);
assertEquals(Status.OK, report.getStatus());
visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
assertNotNull(visualization);
assertEquals(1, visualization.getUserGroupAccesses().size());
assertEquals(1, visualization.getUserAccesses().size());
assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUser().getUid());
assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroup().getUid());
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method defaultSetup.
private void defaultSetup() {
DataElement de1 = createDataElement('A');
DataElement de2 = createDataElement('B');
DataElement de3 = createDataElement('C');
DataElement de4 = createDataElement('D');
manager.save(de1);
manager.save(de2);
manager.save(de3);
manager.save(de4);
User user = createUser('A');
manager.save(user);
UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user));
manager.save(userGroup);
}
use of org.hisp.dhis.user.UserGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceTest method testCreateAndUpdateMetadata2.
@Test
void testCreateAndUpdateMetadata2() 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_update2.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);
assertFalse(objectBundleValidationService.validate(bundle).hasErrorReports());
objectBundleService.commit(bundle);
DataElement dataElementA = manager.get(DataElement.class, "deabcdefghA");
DataElement dataElementB = manager.get(DataElement.class, "deabcdefghB");
DataElement dataElementC = manager.get(DataElement.class, "deabcdefghC");
DataElement dataElementD = manager.get(DataElement.class, "deabcdefghD");
DataElement dataElementE = manager.get(DataElement.class, "deabcdefghE");
assertNotNull(dataElementA);
assertNotNull(dataElementB);
assertNotNull(dataElementC);
assertNotNull(dataElementD);
assertNotNull(dataElementE);
assertEquals("DEA", dataElementA.getName());
assertEquals("DEB", dataElementB.getName());
assertEquals("DEC", dataElementC.getName());
assertEquals("DED", dataElementD.getName());
assertEquals("DEE", dataElementE.getName());
assertEquals("DECA", dataElementA.getCode());
assertEquals("DECB", dataElementB.getCode());
assertEquals("DECC", dataElementC.getCode());
assertEquals("DECD", dataElementD.getCode());
assertEquals("DECE", dataElementE.getCode());
assertEquals("DESA", dataElementA.getShortName());
assertEquals("DESB", dataElementB.getShortName());
assertEquals("DESC", dataElementC.getShortName());
assertEquals("DESD", dataElementD.getShortName());
assertEquals("DESE", dataElementE.getShortName());
assertEquals("DEDA", dataElementA.getDescription());
assertEquals("DEDB", dataElementB.getDescription());
assertEquals("DEDC", dataElementC.getDescription());
assertEquals("DEDD", dataElementD.getDescription());
assertEquals("DEDE", dataElementE.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 testCreateAndUpdateDataSetsWithUgaUID.
@Test
void testCreateAndUpdateDataSetsWithUgaUID() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_uga.json").getInputStream(), RenderFormat.JSON);
ObjectBundleParams params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.CREATE);
params.setObjects(metadata);
ObjectBundle bundle = objectBundleService.create(params);
ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
metadata = renderService.fromMetadata(new ClassPathResource("dxf2/simple_metadata_uga.json").getInputStream(), RenderFormat.JSON);
params = new ObjectBundleParams();
params.setObjectBundleMode(ObjectBundleMode.COMMIT);
params.setImportStrategy(ImportStrategy.UPDATE);
params.setObjects(metadata);
bundle = objectBundleService.create(params);
validate = objectBundleValidationService.validate(bundle);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
List<DataElement> dataElements = manager.getAll(DataElement.class);
List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
List<User> users = manager.getAll(User.class);
List<UserGroup> userGroups = manager.getAll(UserGroup.class);
assertEquals(1, organisationUnits.size());
assertEquals(2, dataElements.size());
assertEquals(1, userRoles.size());
assertEquals(1, users.size());
assertEquals(2, userGroups.size());
assertEquals(1, dataElements.get(0).getUserGroupAccesses().size());
assertEquals(1, dataElements.get(1).getUserGroupAccesses().size());
}
Aggregations