Search in sources :

Example 26 with UserCredentials

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

the class FormUtilsImpl method getDataSetsForCurrentUser.

@Override
public List<DataSet> getDataSetsForCurrentUser(Integer organisationUnitId) {
    Validate.notNull(organisationUnitId);
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(organisationUnitId);
    List<DataSet> dataSets = new ArrayList<>(organisationUnit.getDataSets());
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    if (!userCredentials.isSuper()) {
        dataSets.retainAll(userCredentials.getAllDataSets());
    }
    return dataSets;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 27 with UserCredentials

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

the class GetDataSetsAction method getDataSetsForCurrentUser.

private List<DataSet> getDataSetsForCurrentUser(String ids) {
    Set<DataSet> dataSets = new HashSet<>();
    if (ids.length() == 0) {
        return new ArrayList<>();
    }
    for (String id : ids.split(",")) {
        OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
        if (organisationUnit == null) {
            continue;
        }
        if (organisationUnit.getDataSets() != null) {
            dataSets.addAll(organisationUnit.getDataSets());
        }
    }
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    if (!userCredentials.isSuper()) {
        dataSets.retainAll(userCredentials.getAllDataSets());
    }
    return new ArrayList<>(dataSets);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials) HashSet(java.util.HashSet)

Example 28 with UserCredentials

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

the class GetLockExceptionFormAction method getDataSetsForCurrentUser.

private List<DataSet> getDataSetsForCurrentUser(int id) {
    OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id);
    if (organisationUnit == null) {
        return new ArrayList<>();
    }
    List<DataSet> dataSets = new ArrayList<>();
    if (organisationUnit.getDataSets() != null) {
        dataSets.addAll(organisationUnit.getDataSets());
    }
    UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials();
    if (!userCredentials.isSuper()) {
        dataSets.retainAll(userCredentials.getAllDataSets());
    }
    return dataSets;
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DataSet(org.hisp.dhis.dataset.DataSet) ArrayList(java.util.ArrayList) UserCredentials(org.hisp.dhis.user.UserCredentials)

Example 29 with UserCredentials

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

the class DhisConvenienceTest method createUser.

public static User createUser(char uniqueCharacter) {
    UserCredentials credentials = new UserCredentials();
    User user = new User();
    user.setUid(BASE_USER_UID + uniqueCharacter);
    credentials.setUserInfo(user);
    user.setUserCredentials(credentials);
    credentials.setUsername("username" + uniqueCharacter);
    credentials.setPassword("password" + uniqueCharacter);
    user.setFirstName("FirstName" + uniqueCharacter);
    user.setSurname("Surname" + uniqueCharacter);
    user.setEmail("Email" + uniqueCharacter);
    user.setPhoneNumber("PhoneNumber" + uniqueCharacter);
    user.setCode("UserCode" + uniqueCharacter);
    user.setAutoFields();
    return user;
}
Also used : User(org.hisp.dhis.user.User) UserCredentials(org.hisp.dhis.user.UserCredentials)

Aggregations

UserCredentials (org.hisp.dhis.user.UserCredentials)29 User (org.hisp.dhis.user.User)15 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)7 HashSet (java.util.HashSet)5 ArrayList (java.util.ArrayList)4 Query (org.hibernate.Query)4 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)4 CategoryOptionGroupSet (org.hisp.dhis.dataelement.CategoryOptionGroupSet)3 DataSet (org.hisp.dhis.dataset.DataSet)3 UserGroup (org.hisp.dhis.user.UserGroup)3 IllegalQueryException (org.hisp.dhis.common.IllegalQueryException)2 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)2 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 Program (org.hisp.dhis.program.Program)2 AccessDeniedException (org.springframework.security.access.AccessDeniedException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 List (java.util.List)1