public void setViewableState(String contextId, String userId, Boolean value, String recordType) { if (contextId == null || userId == null || value == null || recordType == null) { throw new IllegalArgumentException("Null Argument in setViewableState"); } PrivacyRecordImpl pr = getPrivacy(contextId, userId, recordType); if (pr != null) { pr.setViewable(value.booleanValue()); savePrivacyRecord(pr); } else { pr = createPrivacyRecord(userId, contextId, recordType, value.booleanValue()); } }
private boolean checkPrivacyRecord(PrivacyRecordImpl sysRecord, PrivacyRecordImpl userRecord) { if (sysRecord != null && userRecord != null) { if (userRecordHasPrecedence) { return userRecord.getViewable(); } else return sysRecord.getViewable(); } else if (sysRecord == null && userRecord == null) { if (defaultViewable) return true; else return false; } else if (sysRecord != null) { return sysRecord.getViewable(); } else { return userRecord.getViewable(); } }
public Map getViewableState(String contextId, String recordType) { if (contextId == null || recordType == null) { throw new IllegalArgumentException("Null Argument in getViewableState"); } try { AuthzGroup realm = authzGroupService.getAuthzGroup(contextId); List users = new ArrayList(); users.addAll(UserDirectoryService.getUsers(realm.getUsers())); List siteUserIds = new ArrayList(); for (int i = 0; i < users.size(); i++) siteUserIds.add(((User) users.get(i)).getId()); // List returnedList = getPrivacyByContextAndType(contextId, recordType); List returnedList = new ArrayList(); List pieceList = new ArrayList(); List resultPieceList = new ArrayList(); for (int i = 0; i <= (int) (siteUserIds.size() / maxResultSetNumber); i++) { pieceList.clear(); if (i == (int) (siteUserIds.size() / maxResultSetNumber)) { for (int j = 0; j < (siteUserIds.size() % maxResultSetNumber); j++) { pieceList.add(siteUserIds.get(j + ((int) i * maxResultSetNumber))); } } else { for (int j = 0; j < maxResultSetNumber; j++) { pieceList.add(siteUserIds.get(j + ((int) i * maxResultSetNumber))); } } if (pieceList.size() > 0) { resultPieceList = getPrivacyByContextAndTypeAndUserIds(contextId, recordType, pieceList); for (int j = 0; j < resultPieceList.size(); j++) returnedList.add(resultPieceList.get(j)); } } if (returnedList != null) { HashMap returnMap = new HashMap(); PrivacyRecordImpl pr; for (int i = 0; i < returnedList.size(); i++) { pr = (PrivacyRecordImpl) returnedList.get(i); returnMap.put(pr.getUserId(), Boolean.valueOf(pr.getViewable())); } return returnMap; } return null; } catch (org.sakaiproject.authz.api.GroupNotDefinedException gnde) { return null; } }
@Override public void update(AuthzGroup group) { // the authz group is changing if (group == null) { return; } // /site/7e7c810d-fbd5-4017-a0bf-76be2d50a79d String[] gIdParts = group.getId().split("/"); // only updating site level authz groups if (gIdParts.length == 3 && "site".equals(gIdParts[1])) { String context = "/site/" + gIdParts[2]; List<PrivacyRecordImpl> prList = getPrivacyByContextAndType(context, PrivacyManager.USER_RECORD_TYPE); Set<String> grpMembers = new HashSet<String>(); grpMembers.addAll(group.getUsers()); // ignore members who already have a privacy record for this site for (PrivacyRecordImpl record : prList) { if (!grpMembers.remove(record.getUserId())) { // user is no longer a member of this authz group remove their record removePrivacyObject(record); } } // the remaining members will need to lookup their default preference for (String member : grpMembers) { // the default is visible so we only need to update those that are set to hidden String privacy = getDefaultPrivacyState(member); if (PrivacyManager.VISIBLE.equals(privacy)) { setViewableState(context, member, true, PrivacyManager.USER_RECORD_TYPE); } else if (PrivacyManager.HIDDEN.equals(privacy)) { setViewableState(context, member, false, PrivacyManager.USER_RECORD_TYPE); } } } }