Search in sources :

Example 11 with UserInGroup

use of org.openforis.collect.model.UserInGroup in project collect by openforis.

the class LocalUserManager method loadAllAvailableUsers.

@Override
public List<User> loadAllAvailableUsers(User availableTo) {
    if (availableTo.getRoles().contains(UserRole.ADMIN)) {
        return loadAll();
    } else {
        Set<User> users = new TreeSet<User>();
        List<UserGroup> userGroups = groupManager.findByUser(availableTo);
        for (UserGroup userGroup : userGroups) {
            List<UserInGroup> groupUsers = groupManager.findUsersInGroup(userGroup);
            for (UserInGroup userInGroup : groupUsers) {
                Integer userId = userInGroup.getUserId();
                User user = loadById(userId);
                users.add(user);
            }
        }
        // sorted by username by default (see User.compareTo)
        return new ArrayList<User>(users);
    }
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup)

Example 12 with UserInGroup

use of org.openforis.collect.model.UserInGroup in project collect by openforis.

the class RecordController method canDeleteRecords.

private boolean canDeleteRecords(int surveyId, Set<Integer> recordIds) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    RecordFilter filter = new RecordFilter(survey);
    filter.setRecordIds(recordIds);
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    User loggedUser = sessionManager.getLoggedUser();
    RecordAccessControlManager recordAccessControlManager = new RecordAccessControlManager();
    UserInGroup userInSurveyGroup = userGroupManager.findUserInGroupOrDescendants(survey.getUserGroup(), loggedUser);
    boolean canDeleteRecords = userInSurveyGroup != null && recordAccessControlManager.canDeleteRecords(loggedUser, userInSurveyGroup.getRole(), recordSummaries);
    return canDeleteRecords;
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) RecordFilter(org.openforis.collect.model.RecordFilter)

Aggregations

UserInGroup (org.openforis.collect.model.UserInGroup)12 UserGroup (org.openforis.collect.model.UserGroup)7 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Transactional (org.springframework.transaction.annotation.Transactional)4 CollectSurvey (org.openforis.collect.model.CollectSurvey)3 User (org.openforis.collect.model.User)3 HashMap (java.util.HashMap)2 Timestamp (java.sql.Timestamp)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Condition (org.jooq.Condition)1 Record (org.jooq.Record)1 RecordHandler (org.jooq.RecordHandler)1 RecordAccessControlManager (org.openforis.collect.manager.RecordAccessControlManager)1 CodeListItemProxy (org.openforis.collect.metamodel.proxy.CodeListItemProxy)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)1 NodeChangeMap (org.openforis.collect.model.NodeChangeMap)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1