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);
}
}
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;
}
Aggregations