use of org.hisp.dhis.dto.UserGroup 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);
}
Aggregations