コード例 #1
0
  /** @inheritDoc */
  public List getSectionMembers(final String sectionUuid) {
    Group group = siteService.findGroup(sectionUuid);
    CourseSection section = new CourseSectionImpl(group);
    Set taRoles = getSectionTaRoles(group);
    Set studentRoles = getSectionStudentRoles(group);
    Set members = group.getMembers();

    List<ParticipationRecord> sectionMembershipRecords = new ArrayList<ParticipationRecord>();
    for (Iterator iter = members.iterator(); iter.hasNext(); ) {
      Member member = (Member) iter.next();
      String roleString = member.getRole().getId();
      User user = SakaiUtil.getUserFromSakai(member.getUserId());
      if (user != null) {
        ParticipationRecord record = null;
        if (taRoles.contains(roleString)) {
          record = new TeachingAssistantRecordImpl(section, user);
        } else if (studentRoles.contains(roleString)) {
          record = new EnrollmentRecordImpl(section, null, user);
        }
        if (record != null) {
          sectionMembershipRecords.add(record);
        }
      }
    }
    return sectionMembershipRecords;
  }
コード例 #2
0
  /**
   * Extract a 'Set' of user ids from the given set of members.
   *
   * @param members The Set of members from which to extract the userIds
   * @return The set of user ids that belong to the users in the member set.
   */
  private Set<String> getUserIds(Collection<Member> members) {
    Set<String> userIds = new HashSet<String>();

    for (Member member : members) userIds.add(member.getUserId());

    return userIds;
  }
コード例 #3
0
  private Collection<SyncableGroup> readSakaiGroups() throws IdUnusedException {
    Collection<SyncableGroup> result = new ArrayList<SyncableGroup>();

    Collection<AuthzGroup> sakaiGroups = new ArrayList<AuthzGroup>();
    Site site = SiteService.getSite(siteId);
    sakaiGroups.add(site);
    sakaiGroups.addAll(site.getGroups());

    for (AuthzGroup sakaiGroup : sakaiGroups) {
      List<UserWithRole> members = new ArrayList<UserWithRole>();
      HashSet<String> inactiveUsers = new HashSet<String>();

      // Load direct members of this group
      for (Member m : sakaiGroup.getMembers()) {
        if (!m.isActive()) {
          inactiveUsers.add(m.getUserEid());
          continue;
        }

        if (!m.isProvided()) {
          // Provided users will be handled separately below.
          members.add(new UserWithRole(m.getUserEid(), m.getRole().getId()));
        }
      }

      String provider = sakaiGroup.getProviderGroupId();

      // Plus those provided by sections
      if (provider != null) {
        HashSet<String> seenUsers = new HashSet<String>();

        for (String providerId : provider.split("\\+")) {
          for (org.sakaiproject.coursemanagement.api.Membership m :
              cms.getSectionMemberships(providerId)) {
            if (seenUsers.contains(m.getUserId()) || inactiveUsers.contains(m.getUserId())) {
              continue;
            }

            members.add(new UserWithRole(m.getUserId(), m.getRole()));
            seenUsers.add(m.getUserId());
          }
        }
      }

      result.add(new SyncableGroup(sakaiGroup.getId(), sakaiGroup.getDescription(), members));
    }

    return result;
  }
コード例 #4
0
  protected void processRoster(
      HttpServletRequest request,
      HttpServletResponse response,
      String lti_message_type,
      Site site,
      String siteId,
      String placement_id,
      Properties pitch,
      String user_id,
      Map<String, Object> theMap)
      throws java.io.IOException {
    // Check for permission in placement
    String allowRoster = pitch.getProperty(LTIService.LTI_ALLOWROSTER);
    if (!"on".equals(allowRoster)) {
      doError(
          request,
          response,
          theMap,
          "outcomes.invalid",
          "lti_message_type=" + lti_message_type,
          null);
      return;
    }

    String roleMapProp = pitch.getProperty("rolemap");
    String releaseName = pitch.getProperty(LTIService.LTI_SENDNAME);
    String releaseEmail = pitch.getProperty(LTIService.LTI_SENDEMAILADDR);
    String assignment = pitch.getProperty("assignment");
    String allowOutcomes =
        ServerConfigurationService.getString(
            SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED,
            SakaiBLTIUtil.BASICLTI_OUTCOMES_ENABLED_DEFAULT);
    if (!"true".equals(allowOutcomes)) allowOutcomes = null;

    String maintainRole = site.getMaintainRole();

    SakaiBLTIUtil.pushAdvisor();
    boolean success = false;
    try {
      List<Map<String, Object>> lm = new ArrayList<Map<String, Object>>();
      Set<Member> members = site.getMembers();
      Map<String, String> roleMap = SakaiBLTIUtil.convertRoleMapPropToMap(roleMapProp);
      for (Member member : members) {
        Map<String, Object> mm = new TreeMap<String, Object>();
        Role role = member.getRole();
        String ims_user_id = member.getUserId();
        mm.put("/user_id", ims_user_id);
        String ims_role = "Learner";

        // If there is a role mapping, it has precedence over site.update
        if (roleMap.containsKey(role.getId())) {
          ims_role = roleMap.get(role.getId());
        } else if (ComponentManager.get(AuthzGroupService.class)
            .isAllowed(ims_user_id, SiteService.SECURE_UPDATE_SITE, "/site/" + siteId)) {
          ims_role = "Instructor";
        }

        // Using "/role" is inconsistent with to
        // http://developers.imsglobal.org/ext_membership.html. It
        // should be roles. If we can determine that nobody is using
        // the role tag, we should remove it.

        mm.put("/role", ims_role);
        mm.put("/roles", ims_role);
        User user = null;
        if ("true".equals(allowOutcomes) && assignment != null) {
          user = UserDirectoryService.getUser(ims_user_id);
          String placement_secret = pitch.getProperty(LTIService.LTI_PLACEMENTSECRET);
          String result_sourcedid =
              SakaiBLTIUtil.getSourceDID(user, placement_id, placement_secret);
          if (result_sourcedid != null) mm.put("/lis_result_sourcedid", result_sourcedid);
        }

        if ("on".equals(releaseName) || "on".equals(releaseEmail)) {
          if (user == null) user = UserDirectoryService.getUser(ims_user_id);
          if ("on".equals(releaseName)) {
            mm.put("/person_name_given", user.getFirstName());
            mm.put("/person_name_family", user.getLastName());
            mm.put("/person_name_full", user.getDisplayName());
          }
          if ("on".equals(releaseEmail)) {
            mm.put("/person_contact_email_primary", user.getEmail());
            mm.put("/person_sourcedid", user.getEid());
          }
        }

        Collection groups = site.getGroupsWithMember(ims_user_id);

        if (groups.size() > 0) {
          List<Map<String, Object>> lgm = new ArrayList<Map<String, Object>>();
          for (Iterator i = groups.iterator(); i.hasNext(); ) {
            Group group = (Group) i.next();
            Map<String, Object> groupMap = new HashMap<String, Object>();
            groupMap.put("/id", group.getId());
            groupMap.put("/title", group.getTitle());
            groupMap.put("/set", new HashMap(groupMap));
            lgm.add(groupMap);
          }
          mm.put("/groups/group", lgm);
        }

        lm.add(mm);
      }
      theMap.put("/message_response/members/member", lm);
      success = true;
    } catch (Exception e) {
      doError(request, response, theMap, "memberships.fail", "", e);
    } finally {
      SakaiBLTIUtil.popAdvisor();
    }

    if (!success) return;

    theMap.put("/message_response/statusinfo/codemajor", "Success");
    theMap.put("/message_response/statusinfo/severity", "Status");
    theMap.put("/message_response/statusinfo/codeminor", "fullsuccess");
    String theXml = XMLMap.getXML(theMap, true);
    PrintWriter out = response.getWriter();
    out.println(theXml);
    M_log.debug(theXml);
  }
コード例 #5
0
  public void testSiteRoles() throws Exception {
    actAsUserEid(officialInstructorOfA);
    Site site = siteService.getSite(courseOfferingA);

    // Check for the officially enrolled (but waitlisted) student.
    Member member = site.getMember(waitListedStudentALec1);
    Assert.assertNotNull(member);
    Assert.assertEquals("Student", member.getRole().getId());

    // Check for the student who was added directly to the site.
    member = site.getMember(unofficialStudentALec1);
    Assert.assertNotNull(member);
    Assert.assertEquals("Student", member.getRole().getId());

    // Check for the expelled student.
    member = site.getMember(expelledStudentALec1);
    Assert.assertNull(member);

    // Check for the dropped student.
    member = site.getMember(droppedStudentALec1);
    Assert.assertNull(member);

    // Check for the enrollment record mapped to another role.
    member = site.getMember(taAsEnrollmentALec1);
    Assert.assertNotNull(member);
    Assert.assertEquals("Teaching Assistant", member.getRole().getId());

    // Check for the student in a discussion section.
    member = site.getMember(studentADis1);
    Assert.assertNotNull(member);
    Assert.assertEquals("Student", member.getRole().getId());

    // Check for a student in another course site.
    member = site.getMember(enrolledStudentBLec1);
    Assert.assertNull(member);

    // Check for non-integration of the TA.
    member = site.getMember(gsiALec1);
    Assert.assertNull(member);

    // Check for non-integration of the TA who also happens to be a DeptAdmin.
    member = site.getMember(deptAdminAndGsi);
    Assert.assertNull(member);

    // Check for the official instructor of the enrollment set.
    member = site.getMember(officialInstructorOfA);
    Assert.assertNotNull(member);
    Assert.assertEquals("Instructor", member.getRole().getId());

    // Check for non-integration of the course offering member in the instructor role.
    member = site.getMember(unofficialInstructorOfA);
    Assert.assertNull(member);

    // Check for non-integration of the department administrator.
    member = site.getMember(deptAdminOfADept);
    Assert.assertNull(member);

    // Check for non-integration of the course admin.
    member = site.getMember(adminOfOfferingA);
    Assert.assertNull(member);

    // Check for an instructor in another course site.
    member = site.getMember(instructorOfB);
    Assert.assertNull(member);

    // Check for another department's administrator.
    member = site.getMember(deptAdminOfBDept);
    Assert.assertNull(member);
  }
コード例 #6
0
ファイル: GroupEditProducer.java プロジェクト: yllyx/sakai
  public void fillComponents(UIContainer arg0, ViewParameters arg1, ComponentChecker arg2) {

    String state = "";

    // group
    Group g = null;
    // id for group
    String groupId = null;
    // title for group
    String groupTitle = null;
    // description for group
    String groupDescription = null;
    // member list for group
    Set<Member> groupMembers = new HashSet<>();
    // group provider id
    String groupProviderId = null;
    // list of group role provider ids
    List<String> groupRoleProviderRoles = null;

    UIForm groupForm = UIForm.make(arg0, "groups-form");

    String id = ((GroupEditViewParameters) arg1).id;
    if (id != null) {
      try {
        // SAK-29645
        if (handler.messages.size() == 0) {
          g = siteService.findGroup(id);
          groupId = g.getId();
          groupTitle = g.getTitle();
          groupDescription = g.getDescription();
          handler.allowViewMembership =
              Boolean.valueOf(g.getProperties().getProperty(Group.GROUP_PROP_VIEW_MEMBERS));
          groupMembers = g.getMembers();
          groupProviderId = g.getProviderGroupId();
          groupRoleProviderRoles = handler.getGroupProviderRoles(g);
          String joinableSet = g.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_SET);
          if (joinableSet != null && !"".equals(joinableSet.trim())) {
            handler.joinableSetName = joinableSet;
            handler.joinableSetNameOrig = joinableSet;
            handler.joinableSetNumOfMembers =
                g.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_SET_MAX);
            handler.allowPreviewMembership =
                Boolean.valueOf(
                    g.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_SET_PREVIEW));
            // set unjoinable.  Since you can't change this value at the group edit page, all groups
            // will have the same
            // value in the set.  Find another group in the same set (if exist) and set it to the
            // same value.
            for (Group group : handler.site.getGroups()) {
              String joinableSetName =
                  group.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_SET);
              if (joinableSetName != null && joinableSetName.equals(joinableSet)) {
                // we only need to find the first one since all are the same
                handler.unjoinable =
                    Boolean.valueOf(
                        group.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_UNJOINABLE));
                break;
              }
            }
          } else {
            handler.joinableSetName = "";
            handler.joinableSetNameOrig = "";
            handler.joinableSetNumOfMembers = "";
            handler.allowPreviewMembership = false;
            handler.unjoinable = false;
          }
        }
      } catch (Exception e) {
        M_log.debug(this + "fillComponents: cannot get group id=" + id, e);
      }
    } else {
      handler.resetParams();
    }

    // action button name: Add for adding new group, Update for editing exist group
    String addUpdateButtonName =
        id != null
            ? messageLocator.getMessage("editgroup.update")
            : messageLocator.getMessage("editgroup.new");
    String headerText =
        id == null
            ? messageLocator.getMessage("group.newgroup")
            : messageLocator.getMessage("group.editgroup");

    UIOutput.make(groupForm, "prompt", headerText);
    UIOutput.make(
        groupForm, "emptyGroupTitleAlert", messageLocator.getMessage("editgroup.titlemissing"));
    UIOutput.make(
        groupForm,
        "instructions",
        messageLocator.getMessage("editgroup.instruction", new Object[] {addUpdateButtonName}));

    UIOutput.make(groupForm, "group_title_label", messageLocator.getMessage("group.title"));
    UIInput.make(
        groupForm, "group_title", "#{SiteManageGroupSectionRoleHandler.title}", groupTitle);

    UIMessage groupDescrLabel =
        UIMessage.make(groupForm, "group_description_label", "group.description");
    UIInput groupDescr =
        UIInput.make(
            groupForm,
            "group_description",
            "#{SiteManageGroupSectionRoleHandler.description}",
            groupDescription);
    UILabelTargetDecorator.targetLabel(groupDescrLabel, groupDescr);

    // allow view membership:
    UIBoundBoolean viewMemCheckbox =
        UIBoundBoolean.make(
            groupForm,
            "allowViewMembership",
            "#{SiteManageGroupSectionRoleHandler.allowViewMembership}");
    UILabelTargetDecorator.targetLabel(
        UIMessage.make(groupForm, "allowViewMembership-label", "group.allow.view.membership"),
        viewMemCheckbox);

    // Joinable Set:
    UIMessage joinableSetLabel =
        UIMessage.make(groupForm, "group_joinable_set_label", "group.joinable.set");
    List<String> joinableSetValuesSet = new ArrayList<>();
    for (Group group : handler.site.getGroups()) {
      String joinableSet = group.getProperties().getProperty(Group.GROUP_PROP_JOINABLE_SET);
      if (joinableSet != null && !joinableSetValuesSet.contains(joinableSet)) {
        joinableSetValuesSet.add(joinableSet);
      }
    }
    Collections.sort(joinableSetValuesSet);
    List<String> joinableSetValues = new ArrayList<>();
    List<String> joinableSetNames = new ArrayList<>();
    joinableSetValues.add("");
    joinableSetNames.add(messageLocator.getMessage("none"));
    joinableSetValues.addAll(joinableSetValuesSet);
    joinableSetNames.addAll(joinableSetValuesSet);

    String[] joinableSetNamesArr = joinableSetNames.toArray(new String[joinableSetNames.size()]);
    String[] joinableSetValuesArr = joinableSetValues.toArray(new String[joinableSetValues.size()]);
    UISelect joinableSetSelect =
        UISelect.make(
            groupForm,
            "joinable-set",
            joinableSetValuesArr,
            joinableSetNamesArr,
            "SiteManageGroupSectionRoleHandler.joinableSetName");
    UILabelTargetDecorator.targetLabel(joinableSetLabel, joinableSetSelect);
    // joinable div:
    UIBranchContainer joinableDiv = UIBranchContainer.make(groupForm, "joinable-set-div:");
    if (handler.joinableSetName == null || "".equals(handler.joinableSetName)) {
      Map<String, String> hidden = new HashMap<>();
      hidden.put("display", "none");
      joinableDiv.decorate(new UICSSDecorator(hidden));
    }
    // Max members Row:
    UIMessage.make(joinableDiv, "group-max-members", "group.joinable.maxMembers2");
    UIInput.make(
        joinableDiv,
        "num-max-members",
        "SiteManageGroupSectionRoleHandler.joinableSetNumOfMembers");
    // allow preview row:
    UIBoundBoolean checkbox =
        UIBoundBoolean.make(
            joinableDiv,
            "allowPreviewMembership",
            "#{SiteManageGroupSectionRoleHandler.allowPreviewMembership}");
    UILabelTargetDecorator.targetLabel(
        UIMessage.make(joinableDiv, "allowPreviewMembership-label", "group.joinable.allowPreview"),
        checkbox);

    UIOutput.make(groupForm, "membership_label", messageLocator.getMessage("editgroup.membership"));
    UIOutput.make(
        groupForm, "membership_site_label", messageLocator.getMessage("editgroup.generallist"));
    UIOutput.make(
        groupForm, "membership_group_label", messageLocator.getMessage("editgroup.grouplist"));

    /** ******************** for the site members list ************************* */
    List<String> siteRosters = handler.getSiteRosters(g);
    List<Role> siteRoles = handler.getSiteRoles(g);
    List<Participant> siteMembers = handler.getSiteParticipant(g);
    List<String> siteMemberLabels = new ArrayList<>();
    List<String> siteMemberValues = new ArrayList<>();
    List<String> membersSelected;
    if (handler.memberList != null && handler.memberList.length() > 0) {
      membersSelected = Arrays.asList(handler.memberList.split("##"));
    } else {
      membersSelected = new ArrayList<>();
    }

    // add site roster
    for (String roster : siteRosters) {
      // not include in the group yet
      if ((groupProviderId == null || !groupProviderId.contains(roster))
          && !membersSelected.contains(roster)) {
        siteMemberLabels.add(SECTION_PREFIX + handler.getRosterLabel(roster) + " (" + roster + ")");
        siteMemberValues.add(roster);
      }
    }
    // add site role
    for (Role role : siteRoles) {
      // not include in the group yet
      if ((groupRoleProviderRoles == null || !groupRoleProviderRoles.contains(role.getId()))
          && !membersSelected.contains(role.getId())) {
        siteMemberLabels.add(ROLE_PREFIX + role.getId());
        siteMemberValues.add(role.getId());
      }
    }
    // add site members to the list
    Iterator<Participant> sIterator =
        new SortedIterator(
            siteMembers.iterator(),
            new SiteComparator(SiteConstants.SORTED_BY_PARTICIPANT_NAME, Boolean.TRUE.toString()));
    while (sIterator.hasNext()) {
      Participant p = (Participant) sIterator.next();
      // not in the group yet
      if ((g == null || g.getMember(p.getUniqname()) == null)
          && !membersSelected.contains(p.getUniqname())) {
        siteMemberLabels.add(p.getName() + " (" + p.getDisplayId() + ")");
        siteMemberValues.add(p.getUniqname());
      }
    }

    UISelect.makeMultiple(
        groupForm,
        "siteMembers",
        siteMemberValues.toArray(new String[siteMemberValues.size()]),
        siteMemberLabels.toArray(new String[siteMemberLabels.size()]),
        "#{SiteManageGroupSectionRoleHandler.selectedSiteMembers}",
        new String[] {});

    /** ******************** for the group members list ************************* */
    List<String> groupRosters = handler.getGroupRosters(g);
    List<String> groupProviderRoles = handler.getGroupProviderRoles(g);
    List<Member> groupMembersCopy = new ArrayList<>();
    groupMembersCopy.addAll(groupMembers);
    for (Member p : groupMembersCopy) {
      // exclude those user with provided roles and rosters
      String userId = p.getUserId();
      try {
        // get user
        User u = userDirectoryService.getUser(userId);
        if (handler.isUserFromProvider(u.getEid(), userId, g, groupRosters, groupProviderRoles)) {
          groupMembers.remove(p);
        }
      } catch (Exception e) {
        M_log.debug(this + "fillInComponent: cannot find user with id " + userId, e);
        // need to remove the group member
        groupMembers.remove(p);
      }
    }

    // SAK-29645
    List<String> groupMemberLabels = new ArrayList<>();
    List<String> groupMemberValues = new ArrayList<>();

    // add the rosters first
    if (groupRosters != null) {
      for (String groupRoster : groupRosters) {
        groupMemberLabels.add(SECTION_PREFIX + groupRoster);
        groupMemberValues.add(groupRoster);
      }
    }
    // add the roles next
    if (groupProviderRoles != null) {
      for (String groupProviderRole : groupProviderRoles) {
        groupMemberLabels.add(ROLE_PREFIX + groupProviderRole);
        groupMemberValues.add(groupProviderRole);
      }
    }
    // add the members last
    if (groupMembers != null) {
      Iterator<Member> gIterator =
          new SortedIterator(
              groupMembers.iterator(),
              new SiteComparator(SiteConstants.SORTED_BY_MEMBER_NAME, Boolean.TRUE.toString()));
      while (gIterator.hasNext()) {
        Member p = (Member) gIterator.next();
        String userId = p.getUserId();
        try {
          User u = userDirectoryService.getUser(userId);
          groupMemberLabels.add(u.getSortName() + " (" + u.getDisplayId() + ")");
          groupMemberValues.add(userId);
        } catch (Exception e) {
          M_log.debug(this + ":fillComponents: cannot find user " + userId, e);
        }
      }
    }

    // SAK-29645 - preserve user selected values
    if (!membersSelected.isEmpty()) {
      siteRosters = handler.getSiteRosters(null);
      List<String> siteRoleIDs = handler.getSiteRoleIds();
      for (String memberID : membersSelected) {
        // Selected roster...
        if (siteRosters.contains(memberID)) {
          groupMemberLabels.add(SECTION_PREFIX + memberID);
          groupMemberValues.add(memberID);
        }

        // Selected role...
        else if (siteRoleIDs.contains(memberID)) {
          groupMemberLabels.add(ROLE_PREFIX + memberID);
          groupMemberValues.add(memberID);
        }

        // Selected member...
        else if (groupMembers != null) {
          sIterator =
              new SortedIterator(
                  siteMembers.iterator(),
                  new SiteComparator(
                      SiteConstants.SORTED_BY_PARTICIPANT_NAME, Boolean.TRUE.toString()));
          while (sIterator.hasNext()) {
            Participant p = (Participant) sIterator.next();
            String userID = p.getUniqname();
            if (StringUtils.isNotBlank(userID) && userID.equals(memberID)) {
              groupMemberLabels.add(p.getName() + " (" + p.getDisplayId() + ")");
              groupMemberValues.add(userID);
            }
          }
        }
      }
    }

    UISelect.make(
        groupForm,
        "groupMembers",
        groupMemberValues.toArray(new String[groupMemberValues.size()]),
        groupMemberLabels.toArray(new String[groupMemberLabels.size()]),
        null);
    UICommand.make(
        groupForm,
        "save",
        addUpdateButtonName,
        "#{SiteManageGroupSectionRoleHandler.processAddGroup}");

    UICommand cancel =
        UICommand.make(
            groupForm,
            "cancel",
            messageLocator.getMessage("editgroup.cancel"),
            "#{SiteManageGroupSectionRoleHandler.processBack}");
    cancel.parameters.add(new UIDeletionBinding("#{destroyScope.resultScope}"));

    UIInput.make(groupForm, "newRight", "#{SiteManageGroupSectionRoleHandler.memberList}", state);

    // hidden field for group id
    UIInput.make(groupForm, "groupId", "#{SiteManageGroupSectionRoleHandler.id}", groupId);

    // process any messages
    tml = handler.messages;
    if (tml.size() > 0) {
      for (int i = 0; i < tml.size(); i++) {
        UIBranchContainer errorRow =
            UIBranchContainer.make(arg0, "error-row:", Integer.toString(i));
        TargettedMessage msg = tml.messageAt(i);
        if (msg.args != null) {
          UIMessage.make(errorRow, "error", msg.acquireMessageCode(), (Object[]) msg.args);
        } else {
          UIMessage.make(errorRow, "error", msg.acquireMessageCode());
        }
      }
    }

    frameAdjustingProducer.fillComponents(arg0, "resize", "resetFrame");
  }