/** * Can the user read from this CategoryOptionGroupSet (COGS)? * * <p>If the COGS is null, then the user must have no dimension constraints. (In other words, the * user must be able to read across all category option groups.) * * <p>If the COGS is not null, then the user must be able to read at least one category option * group from the category option group set. * * @param cogs The category option group set to test * @return true if user can read at least one category option group. */ private boolean canReadCOGS(User user, CategoryOptionGroupSet cogs) { if (cogs == null) { UserCredentials userCredentials = user.getUserCredentials(); return CollectionUtils.isEmpty(userCredentials.getCogsDimensionConstraints()) && CollectionUtils.isEmpty(userCredentials.getCatDimensionConstraints()); } return !CollectionUtils.isEmpty(categoryService.getCategoryOptionGroups(cogs)); }
@Override public List<DataApprovalLevel> getUserDataApprovalLevels() { UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials(); boolean mayApprove = userCredentials.isAuthorized(DataApproval.AUTH_APPROVE); boolean mayApproveAtLowerLevels = userCredentials.isAuthorized(DataApproval.AUTH_APPROVE_LOWER_LEVELS); boolean mayAcceptAtLowerLevels = userCredentials.isAuthorized(DataApproval.AUTH_ACCEPT_LOWER_LEVELS); if (!mayApprove && !mayApproveAtLowerLevels && !mayAcceptAtLowerLevels) { return new ArrayList<>(); } int lowestNumberOrgUnitLevel = getCurrentUsersLowestNumberOrgUnitLevel(); boolean canSeeAllDimensions = CollectionUtils.isEmpty(userService.getCoDimensionConstraints(userCredentials)) && CollectionUtils.isEmpty(userService.getCogDimensionConstraints(userCredentials)); List<DataApprovalLevel> approvalLevels = getAllDataApprovalLevels(); List<DataApprovalLevel> userDataApprovalLevels = new ArrayList<>(); boolean addLevel = false; for (DataApprovalLevel approvalLevel : approvalLevels) { if (!addLevel && approvalLevel.getOrgUnitLevel() >= lowestNumberOrgUnitLevel) { CategoryOptionGroupSet cogs = approvalLevel.getCategoryOptionGroupSet(); addLevel = securityService.canRead(approvalLevel) && cogs == null ? canSeeAllDimensions : (securityService.canRead(cogs) && !CollectionUtils.isEmpty(categoryService.getCategoryOptionGroups(cogs))); } if (addLevel) { userDataApprovalLevels.add(approvalLevel); } } return userDataApprovalLevels; }
private List<DataSet> getDataSetsForCurrentUser(int id) { OrganisationUnit organisationUnit = organisationUnitService.getOrganisationUnit(id); if (organisationUnit == null) { return new ArrayList<DataSet>(); } List<DataSet> dataSets = new ArrayList<DataSet>(); if (organisationUnit.getDataSets() != null) { dataSets.addAll(organisationUnit.getDataSets()); } UserCredentials userCredentials = currentUserService.getCurrentUser().getUserCredentials(); if (!userCredentials.isSuper()) { dataSets.retainAll(userCredentials.getAllDataSets()); } return dataSets; }
public String execute() throws Exception { UserCredentials currentUserCredentials = currentUserService.getCurrentUser() != null ? currentUserService.getCurrentUser().getUserCredentials() : null; // --------------------------------------------------------------------- // Prepare values // --------------------------------------------------------------------- if (email != null && email.trim().length() == 0) { email = null; } if (rawPassword != null && rawPassword.trim().length() == 0) { rawPassword = null; } // --------------------------------------------------------------------- // Update userCredentials and user // --------------------------------------------------------------------- Collection<OrganisationUnit> units = selectionTreeManager.getReloadedSelectedOrganisationUnits(); User user = userService.getUser(id); user.setSurname(surname); user.setFirstName(firstName); user.setEmail(email); user.setPhoneNumber(phoneNumber); user.updateOrganisationUnits(new HashSet<OrganisationUnit>(units)); UserCredentials userCredentials = userService.getUserCredentials(user); Set<UserAuthorityGroup> userAuthorityGroups = new HashSet<UserAuthorityGroup>(); for (String id : selectedList) { UserAuthorityGroup group = userService.getUserAuthorityGroup(Integer.parseInt(id)); if (currentUserCredentials != null && currentUserCredentials.canIssue(group)) { userAuthorityGroups.add(group); } } userCredentials.setUserAuthorityGroups(userAuthorityGroups); if (rawPassword != null) { userCredentials.setPassword( passwordManager.encodePassword(userCredentials.getUsername(), rawPassword)); } if (jsonAttributeValues != null) { AttributeUtils.updateAttributeValuesFromJson( user.getAttributeValues(), jsonAttributeValues, attributeService); } userService.updateUserCredentials(userCredentials); userService.updateUser(user); if (currentUserService.getCurrentUser() == user) { selectionManager.setRootOrganisationUnits(units); selectionManager.setSelectedOrganisationUnits(units); selectionTreeManager.setRootOrganisationUnits(units); selectionTreeManager.setSelectedOrganisationUnits(units); } if (units.size() > 0) { selectionManager.setSelectedOrganisationUnits(units); } return SUCCESS; }
/** * Creates a table with the given validation rule * * @param user The User * @param i18n i18n object * @param format I18nFormat object * @param keepTogether Indicates whether the table could be broken across multiple pages or should * be kept at one page. * @param columnWidths The column widths. */ public static PdfPTable printUser( UserCredentials userCredentials, I18n i18n, I18nFormat format, boolean keepTogether, float... columnWidths) { User user = userCredentials.getUser(); PdfPTable table = getPdfPTable(keepTogether, columnWidths); table.addCell(getHeaderCell(user.getFirstName() + ", " + user.getSurname(), 2)); table.addCell(getEmptyCell(2, 15)); table.addCell(getItalicCell(i18n.getString("username"))); table.addCell(getTextCell(userCredentials.getUsername())); if (nullIfEmpty(user.getEmail()) != null) { table.addCell(getItalicCell(i18n.getString("email"))); table.addCell(getTextCell(user.getEmail())); } if (nullIfEmpty(user.getPhoneNumber()) != null) { table.addCell(getItalicCell(i18n.getString("phone_number"))); table.addCell(getTextCell(user.getPhoneNumber())); } table.addCell(getItalicCell(i18n.getString("last_login"))); table.addCell( getTextCell( userCredentials.getLastLogin() != null ? format.formatDate(userCredentials.getLastLogin()) : EMPTY)); String temp = ""; for (OrganisationUnit unit : user.getOrganisationUnits()) { temp += unit.getName().concat(", "); } temp = temp.trim(); temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1); table.addCell(getItalicCell(i18n.getString("organisation_units"))); table.addCell(getTextCell(temp)); temp = ""; for (UserAuthorityGroup role : userCredentials.getUserAuthorityGroups()) { temp += role.getName().concat(", "); } temp = temp.trim(); temp = temp.substring(0, temp.isEmpty() ? 0 : temp.length() - 1); table.addCell(getItalicCell(i18n.getString("roles"))); table.addCell(getTextCell(temp)); for (AttributeValue value : user.getAttributeValues()) { table.addCell(getItalicCell(value.getAttribute().getName())); table.addCell(getTextCell(value.getValue())); } table.addCell(getEmptyCell(2, 30)); return table; }