Search in sources :

Example 31 with UserAuthorityGroup

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

the class ObjectBundleServiceUserTest method testCreateUserRoleWithDataSetProgramAssignment.

@Test
public void testCreateUserRoleWithDataSetProgramAssignment() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/userrole_program_dataset_assignment.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    params.setAtomicMode(AtomicMode.ALL);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    assertTrue(objectBundleValidationService.validate(bundle).getErrorReports().isEmpty());
    objectBundleService.commit(bundle);
    List<UserAuthorityGroup> userRoles = manager.getAll(UserAuthorityGroup.class);
    assertEquals(1, userRoles.size());
    UserAuthorityGroup userRole = userRoles.get(0);
    assertNotNull(userRole);
    assertEquals(1, userRole.getDataSets().size());
    assertEquals(1, userRole.getPrograms().size());
}
Also used : UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 32 with UserAuthorityGroup

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

the class DefaultAdminUserPopulator method executeInTransaction.

@Override
public void executeInTransaction() {
    // user.
    if (userService.getUserCount() > 0) {
        return;
    }
    // ---------------------------------------------------------------------
    // Assumes no UserAuthorityGroup called "Superuser" in database
    // ---------------------------------------------------------------------
    String username = "admin";
    String password = "district";
    User user = new User();
    user.setUid("M5zQapPyTZI");
    user.setCode("admin");
    user.setFirstName(username);
    user.setSurname(username);
    userService.addUser(user);
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setUid("yrB6vc5Ip3r");
    userAuthorityGroup.setCode("Superuser");
    userAuthorityGroup.setName("Superuser");
    userAuthorityGroup.setDescription("Superuser");
    userAuthorityGroup.setAuthorities(ALL_AUTHORITIES);
    userService.addUserAuthorityGroup(userAuthorityGroup);
    user.setUuid(UUID.fromString("6507f586-f154-4ec1-a25e-d7aa51de5216"));
    user.setCode(username);
    user.setUsername(username);
    user.getUserAuthorityGroups().add(userAuthorityGroup);
    userService.encodeAndSetPassword(user, password);
    userService.addUser(user);
}
Also used : User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup)

Example 33 with UserAuthorityGroup

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

the class DataApprovalServiceCategoryOptionGroupTest method mockUser.

// -------------------------------------------------------------------------
// Set up/tear down helper methods
// -------------------------------------------------------------------------
private MockCurrentUserService mockUser(String userName, OrganisationUnit orgUnit, String... auths) {
    MockCurrentUserService mockCurrentUserService = new MockCurrentUserService(false, Sets.newHashSet(orgUnit), Sets.newHashSet(orgUnit), auths);
    User user = mockCurrentUserService.getCurrentUser();
    user.setFirstName("Test");
    user.setSurname(userName);
    user.setUsername(userName);
    for (UserAuthorityGroup role : user.getUserAuthorityGroups()) {
        // Arbitrary name
        role.setName(CodeGenerator.generateUid());
        userService.addUserAuthorityGroup(role);
    }
    userService.addUser(user);
    return mockCurrentUserService;
}
Also used : User(org.hisp.dhis.user.User) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup)

Example 34 with UserAuthorityGroup

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

the class AclServiceTest method testUserBCanUpdateEventVisualizationWithAuthority.

@Test
void testUserBCanUpdateEventVisualizationWithAuthority() {
    // Given
    User userA = createUser('A');
    manager.save(userA);
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setName("FavA");
    eventVisualization.setCreatedBy(userA);
    eventVisualization.getSharing().setOwner(userA);
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, eventVisualization));
    manager.save(eventVisualization);
    // Then
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setAutoFields();
    userAuthorityGroup.setName("UR");
    userAuthorityGroup.getAuthorities().add("F_EVENT_VISUALIZATION_PUBLIC_ADD");
    manager.save(userAuthorityGroup);
    User userB = createUser('B');
    userB.getUserAuthorityGroups().add(userAuthorityGroup);
    manager.save(userB);
    eventVisualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(eventVisualization);
    assertTrue(aclService.canUpdate(userB, eventVisualization));
}
Also used : User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserAccess(org.hisp.dhis.user.sharing.UserAccess) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 35 with UserAuthorityGroup

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

the class AclServiceTest method testUserBCanUpdateVisualizationWithAuthority.

@Test
void testUserBCanUpdateVisualizationWithAuthority() {
    User userA = createUser('A');
    manager.save(userA);
    Visualization visualization = new Visualization();
    visualization.setAutoFields();
    visualization.setName("FavA");
    visualization.setCreatedBy(userA);
    visualization.getSharing().setOwner(userA);
    visualization.setPublicAccess(AccessStringHelper.DEFAULT);
    visualization.setType(VisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, visualization));
    manager.save(visualization);
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setAutoFields();
    userAuthorityGroup.setName("UR");
    userAuthorityGroup.getAuthorities().add("F_VISUALIZATION_PUBLIC_ADD");
    manager.save(userAuthorityGroup);
    User userB = createUser('B');
    userB.getUserAuthorityGroups().add(userAuthorityGroup);
    manager.save(userB);
    visualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(visualization);
    assertTrue(aclService.canUpdate(userB, visualization));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserAccess(org.hisp.dhis.user.sharing.UserAccess) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)56 User (org.hisp.dhis.user.User)41 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)19 Test (org.junit.jupiter.api.Test)19 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)17 List (java.util.List)15 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)15 DataSet (org.hisp.dhis.dataset.DataSet)15 DataElement (org.hisp.dhis.dataelement.DataElement)14 ClassPathResource (org.springframework.core.io.ClassPathResource)14 ObjectBundleValidationReport (org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport)11 HashSet (java.util.HashSet)7 Program (org.hisp.dhis.program.Program)7 UserGroup (org.hisp.dhis.user.UserGroup)6 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 Section (org.hisp.dhis.dataset.Section)4 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)4 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)4 ProgramStage (org.hisp.dhis.program.ProgramStage)4 ProgramStageDataElement (org.hisp.dhis.program.ProgramStageDataElement)4