Search in sources :

Example 1 with Me

use of org.hisp.dhis.dto.Me in project dhis2-core by dhis2.

the class TrackedEntityInstanceAclReadTests method setupUser.

/**
 * Takes a User object and retrieves information about the users from the
 * api. Updates the password of the user to allow access.
 *
 * @param user to setup
 */
private void setupUser(User user) {
    userActions.updateUserPassword(user.getUid(), user.getPassword());
    new LoginActions().loginAsUser(user.getUsername(), user.getPassword());
    // Get User information from /me
    ApiResponse apiResponse = new RestApiActions("/me").get();
    String asString = apiResponse.getAsString();
    Me me = apiResponse.as(Me.class);
    // Add userGroups
    user.setGroups(me.getUserGroups().stream().map(UserGroup::getId).collect(Collectors.toList()));
    // Add search-scope ous
    user.setSearchScope(me.getTeiSearchOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add capture-scope ous
    user.setCaptureScope(me.getOrganisationUnits().stream().map(OrgUnit::getId).collect(Collectors.toList()));
    // Add hasAllAuthority if user has ALL authority
    user.setAllAuthority(me.getAuthorities().contains("ALL"));
    // Setup map to decide what data can and cannot be read.
    setupAccessMap(user);
}
Also used : OrgUnit(org.hisp.dhis.dto.OrgUnit) RestApiActions(org.hisp.dhis.actions.RestApiActions) Me(org.hisp.dhis.dto.Me) LoginActions(org.hisp.dhis.actions.LoginActions) ApiResponse(org.hisp.dhis.dto.ApiResponse) UserGroup(org.hisp.dhis.dto.UserGroup)

Aggregations

LoginActions (org.hisp.dhis.actions.LoginActions)1 RestApiActions (org.hisp.dhis.actions.RestApiActions)1 ApiResponse (org.hisp.dhis.dto.ApiResponse)1 Me (org.hisp.dhis.dto.Me)1 OrgUnit (org.hisp.dhis.dto.OrgUnit)1 UserGroup (org.hisp.dhis.dto.UserGroup)1