use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ConfigurationController method setSelfRegistrationRole.
@PreAuthorize("hasRole('ALL') or hasRole('F_SYSTEM_SETTING')")
@PostMapping("/selfRegistrationRole")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void setSelfRegistrationRole(@RequestBody String uid) throws NotFoundException {
uid = trim(uid);
UserAuthorityGroup userGroup = identifiableObjectManager.get(UserAuthorityGroup.class, uid);
if (userGroup == null) {
throw new NotFoundException("User authority group", uid);
}
Configuration configuration = configurationService.getConfiguration();
configuration.setSelfRegistrationRole(userGroup);
configurationService.setConfiguration(configuration);
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testCreateSimpleProgramWithSectionsNoReg.
@Test
void testCreateSimpleProgramWithSectionsNoReg() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg_sections.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);
List<DataSet> dataSets = manager.getAll(DataSet.class);
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<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
List<Program> programs = manager.getAll(Program.class);
List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
List<ProgramStageSection> programStageSections = manager.getAll(ProgramStageSection.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, validationRules.size());
assertEquals(1, programs.size());
assertEquals(1, programStages.size());
assertEquals(3, programStageDataElements.size());
assertEquals(2, programStageSections.size());
ProgramStage programStage = programStages.get(0);
assertEquals(3, programStage.getProgramStageDataElements().size());
assertEquals(2, programStage.getProgramStageSections().size());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testCreateSimpleProgramReg.
@Test
void testCreateSimpleProgramReg() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_reg1.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);
validate.forEachErrorReport(System.out::println);
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<Program> programs = manager.getAll(Program.class);
List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
List<ProgramTrackedEntityAttribute> programTrackedEntityAttributes = manager.getAll(ProgramTrackedEntityAttribute.class);
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, programs.size());
assertEquals(2, programStages.size());
assertEquals(4, programStageDataElements.size());
assertEquals(2, programTrackedEntityAttributes.size());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceProgramTest method testCreateSimpleProgramNoReg.
@Test
void testCreateSimpleProgramNoReg() throws IOException {
Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/program_noreg.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);
validate.forEachErrorReport(System.out::println);
assertFalse(validate.hasErrorReports());
objectBundleService.commit(bundle);
List<DataSet> dataSets = manager.getAll(DataSet.class);
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<ValidationRule> validationRules = manager.getAll(ValidationRule.class);
List<Program> programs = manager.getAll(Program.class);
List<ProgramStage> programStages = manager.getAll(ProgramStage.class);
List<ProgramStageDataElement> programStageDataElements = manager.getAll(ProgramStageDataElement.class);
assertFalse(dataSets.isEmpty());
assertFalse(organisationUnits.isEmpty());
assertFalse(dataElements.isEmpty());
assertFalse(users.isEmpty());
assertFalse(userRoles.isEmpty());
assertEquals(1, validationRules.size());
assertEquals(1, programs.size());
assertEquals(1, programStages.size());
assertEquals(3, programStageDataElements.size());
ProgramStage programStage = programStages.get(0);
assertEquals(3, programStage.getProgramStageDataElements().size());
}
use of org.hisp.dhis.user.UserAuthorityGroup in project dhis2-core by dhis2.
the class ObjectBundleServiceUserTest method testUpdateUserWithNoAccessUserRole.
@Test
void testUpdateUserWithNoAccessUserRole() throws IOException {
createUserAndInjectSecurityContext(true);
ObjectBundleParams params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.CREATE_AND_UPDATE, AtomicMode.ALL, "dxf2/user_userrole.json");
ObjectBundle bundle1 = objectBundleService.create(params);
objectBundleService.commit(bundle1);
User userB = manager.get(User.class, "MwhEJUnTHkn");
User userA = manager.get(User.class, "sPWjoHSY03y");
assertEquals(2, userA.getUserAuthorityGroups().size());
assertEquals(2, userB.getUserAuthorityGroups().size());
UserAuthorityGroup userManagerRole = manager.get(UserAuthorityGroup.class, "xJZBzAHI88H");
assertNotNull(userManagerRole);
userManagerRole.getSharing().resetUserAccesses();
userManagerRole.getSharing().addUserAccess(new UserAccess(userB, "rw------"));
userManagerRole.setPublicAccess("--------");
userManagerRole.setCreatedBy(userB);
manager.update(userManagerRole);
SecurityContextHolder.clearContext();
userA.setPassword("passwordUserA");
manager.update(userA);
injectSecurityContext(userA);
params = createBundleParams(ObjectBundleMode.COMMIT, ImportStrategy.CREATE_AND_UPDATE, AtomicMode.ALL, "dxf2/user_userrole_update.json");
ObjectBundle bundle2 = objectBundleService.create(params);
objectBundleService.commit(bundle2);
assertEquals(2, userA.getUserAuthorityGroups().size());
assertEquals(2, userB.getUserAuthorityGroups().size());
}
Aggregations