예제 #1
0
  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;
    }
  }
예제 #2
0
  @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);
        }
      }
    }
  }