Search in sources :

Example 1 with UserCredentialsDto

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

the class MeController method getCurrentUser.

@GetMapping
public ResponseEntity<JsonNode> getCurrentUser(@CurrentUser(required = true) User user, @RequestParam(defaultValue = "*") List<String> fields) {
    if (fieldsContains("access", fields)) {
        Access access = aclService.getAccess(user, user);
        user.setAccess(access);
    }
    Map<String, Serializable> userSettings = userSettingService.getUserSettingsWithFallbackByUserAsMap(user, USER_SETTING_KEYS, true);
    List<String> programs = programService.getUserPrograms().stream().map(BaseIdentifiableObject::getUid).collect(Collectors.toList());
    List<String> dataSets = dataSetService.getUserDataRead(user).stream().map(BaseIdentifiableObject::getUid).collect(Collectors.toList());
    MeDto meDto = new MeDto(user, userSettings, programs, dataSets);
    UserCredentialsDto userCredentialsDto = user.getUserCredentials();
    meDto.setUserCredentials(userCredentialsDto);
    var params = org.hisp.dhis.fieldfiltering.FieldFilterParams.of(meDto, fields);
    ObjectNode jsonNodes = fieldFilterService.toObjectNodes(params).get(0);
    return ResponseEntity.ok(jsonNodes);
}
Also used : Serializable(java.io.Serializable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Access(org.hisp.dhis.security.acl.Access) UserCredentialsDto(org.hisp.dhis.user.UserCredentialsDto) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 2 with UserCredentialsDto

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

the class UserController method populateUserCredentialsDtoFields.

private void populateUserCredentialsDtoFields(User user) {
    UserCredentialsDto userCredentialsRaw = user.getUserCredentialsRaw();
    if (userCredentialsRaw != null) {
        copyProperties(userCredentialsRaw, user, KEY_PASSWORD);
        if (userCredentialsRaw.getPassword() != null) {
            user.setPassword(userCredentialsRaw.getPassword());
        }
        Set<UserAuthorityGroup> userRoles = userCredentialsRaw.getUserRoles();
        if (userRoles != null) {
            user.setUserAuthorityGroups(userRoles);
        }
    }
}
Also used : UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserCredentialsDto(org.hisp.dhis.user.UserCredentialsDto)

Aggregations

UserCredentialsDto (org.hisp.dhis.user.UserCredentialsDto)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Serializable (java.io.Serializable)1 Access (org.hisp.dhis.security.acl.Access)1 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1