Example #1
0
 public BaseForum getForumById(boolean flag, Long id) {
   try {
     return forumManager.getForumById(flag, id);
   } catch (Exception e) {
     return null;
   }
 }
Example #2
0
  // find topics in site, but organized by forum
  public List<LessonEntity> getEntitiesInSite(SimplePageBean bean) {

    List<LessonEntity> ret = new ArrayList<LessonEntity>();

    // LSNBLDR-21. If the tool is not in the current site we shouldn't query
    // for topics owned by the tool.
    Site site = null;
    try {
      site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext());
    } catch (Exception impossible) {
      return ret;
    }

    ToolConfiguration tool = site.getToolForCommonId("sakai.forums");

    if (tool == null) {

      // Forums is not in this site. Move on to the next provider.

      if (nextEntity != null) ret.addAll(nextEntity.getEntitiesInSite());

      return ret;
    }

    // ForumEntity e = new ForumEntity(TYPE_FORUM_TOPIC, 3L, 2);

    // e.setGroups(Arrays.asList("1c24287b-b880-43da-8cdd-c6cdc1249c5c",
    // "75184424-853e-4dd4-9e92-980c851f0580"));
    // e.setGroups(Arrays.asList("75184424-853e-4dd4-9e92-980c851f0580"));

    SortedSet<DiscussionForum> forums =
        new TreeSet<DiscussionForum>(new ForumBySortIndexAscAndCreatedDateDesc());
    for (DiscussionForum forum : forumManager.getForumsForMainPage()) forums.add(forum);

    // security. assume this is only used in places where it's OK, so skip security checks
    for (DiscussionForum forum : forums) {
      if (!forum.getDraft()) {
        ForumEntity entity = new ForumEntity(TYPE_FORUM_FORUM, forum.getId(), 1);
        entity.forum = forum;
        ret.add(entity);
        for (Object o : forum.getTopicsSet()) {
          DiscussionTopic topic = (DiscussionTopic) o;
          if (topic.getDraft().equals(Boolean.FALSE)) {
            entity = new ForumEntity(TYPE_FORUM_TOPIC, topic.getId(), 2);
            entity.topic = topic;
            ret.add(entity);
          }
        }
      }
    }

    if (nextEntity != null) ret.addAll(nextEntity.getEntitiesInSite(bean));

    return ret;
  }
Example #3
0
 public Topic getTopicById(boolean flag, Long id) {
   try {
     Topic topic = forumManager.getTopicById(flag, id);
     if (topic == null) return null;
     // the purpose of this is to trigger a null pointer error if the forum doesn't exist
     // if you delete the forum, it doesn't delete the topics, but showing a topic without
     // its forum causes confusion. The /direct code does the following, so it will give
     // an error.
     if (topic.getOpenForum().getArea() == null) return null;
     return topic;
   } catch (Exception e) {
     return null;
   }
 }
Example #4
0
  // set the item to be accessible only to the specific groups.
  // null to make it accessible to the whole site
  public void setGroups(Collection<String> groups) {

    if (type != TYPE_FORUM_TOPIC) return;

    // Setgroups with a non-null list: we set all contributor entries to none, and then set the
    //    specified groups to contribtor. By only handling groups, we avoid interfering with
    //    anything you might do in the tool. But the moment you use access control, we take
    //    over. Sorry. Once we've done that you could go back into the tool and hack, but I
    //    don't recommend that.
    // Setgroups with a null list: we set all contributor entries to none, and then set all roles
    //    other than maintain to contributor.

    setMasks();

    // System.out.println("topic 1 " + topic + " " + groups);
    //	if (topic == null)
    topic = getTopicById(true, id);
    // System.out.println("topic 2 " + topic);
    if (topic == null) return;

    Site site = null;
    try {
      site = SiteService.getSite(ToolManager.getCurrentPlacement().getContext());
    } catch (Exception e) {
      System.out.println("Unable to get site info for AddEntityControl " + e);
      return;
    }

    // topicCache.remove(id);

    // old entries
    Set<DBMembershipItem> oldMembershipItemSet =
        uiPermissionsManager.getTopicItemsSet((DiscussionTopic) topic);

    DBMembershipItem membershipItem = null;

    boolean haveOwner = false;
    boolean changed = false;

    if (groups != null && groups.size() > 0) {

      // this is the groups we've been asked to use
      // remove groups form this as we see them if they already have access
      // so at the end we just add the ones remaining
      List<String> groupNames = new ArrayList<String>();
      Set<String> addGroupNames = new HashSet<String>();
      for (String groupId : groups) {
        groupNames.add(site.getGroup(groupId).getTitle());
        addGroupNames.add(site.getGroup(groupId).getTitle());
      }
      //	    System.out.println("groups " + groups + " " + groupNames + " " + addGroupNames);
      //	    System.out.println("oldMembership " + oldMembershipItemSet.size());

      // delete groups from here as they are done.

      // if we've seen an owner. Otherwise set the maintain role as owner

      // Setgroups with a non-null list: we set all contributor entries to none, and then set the
      //    specified groups to contribtor. However we don't touch owner.
      // By only handling groups, we avoid interfering with
      //    anything you might do in the tool. But the moment you use access control, we take
      //    over. Sorry. Once we've done that you could go back into the tool and hack, but I
      //    don't recommend that.

      for (DBMembershipItem item : oldMembershipItemSet) {
        // kill everything except our own groups
        // this will leave the owner but remove all other roles
        // System.out.println("item " + item.getType() + " " + item.getName() + " " +
        // item.getPermissionLevelName());
        if (item.getType().equals(MembershipItem.TYPE_GROUP)
            && groupNames.contains(item.getName())) {
          //		    System.out.println("found group " + item.getName());
          addGroupNames.remove(item.getName()); // we've seen it
          // if it's one of our groups make it a contributor if it's not already an owner
          if (!item.getPermissionLevelName().equals("Contributor")
              && !item.getPermissionLevelName().equals("Owner")) {

            PermissionLevel contributorLevel =
                permissionLevelManager.createPermissionLevel(
                    "Contributor", IdManager.createUuid(), contributorMask);
            permissionLevelManager.savePermissionLevel(contributorLevel);

            item.setPermissionLevel(contributorLevel);
            item.setPermissionLevelName("Contributor");
            permissionLevelManager.saveDBMembershipItem(item);
          }
        } else if (!item.getPermissionLevelName()
            .equals("Owner")) { // only group members are contributors
          // remove contributor from anything else, both groups and roles
          // System.out.println("set none");
          //		    System.out.println("setgroups make none " + item.getName());
          PermissionLevel noneLevel =
              permissionLevelManager.createPermissionLevel(
                  "None", IdManager.createUuid(), noneMask);
          permissionLevelManager.savePermissionLevel(noneLevel);

          item.setPermissionLevel(noneLevel);
          item.setPermissionLevelName("None");
          permissionLevelManager.saveDBMembershipItem(item);
        }
      }
      for (String newGroupName : addGroupNames) {
        // System.out.println("addgroup " + newGroupName);
        changed = true;
        PermissionLevel contributorLevel =
            permissionLevelManager.createPermissionLevel(
                "Contributor", IdManager.createUuid(), contributorMask);
        permissionLevelManager.savePermissionLevel(contributorLevel);
        membershipItem =
            permissionLevelManager.createDBMembershipItem(
                newGroupName, "Contributor", MembershipItem.TYPE_GROUP);
        membershipItem.setPermissionLevel(contributorLevel);
        permissionLevelManager.saveDBMembershipItem(membershipItem);
        oldMembershipItemSet.add(membershipItem);
      }

    } else {
      // Setgroups with a null list: we set all contributor entries to none, and then set all roles
      //    to contributor.  However we don't touch Owners.

      for (DBMembershipItem item : oldMembershipItemSet) {
        if (item.getPermissionLevelName().equals("Owner")) {
          haveOwner = true;
        } else if (item.getType().equals(MembershipItem.TYPE_ROLE)) {
          // default state has all roles except owner as contributor
          if (!item.getPermissionLevelName().equals("Contributor")) {
            PermissionLevel contributorLevel =
                permissionLevelManager.createPermissionLevel(
                    "Contributor", IdManager.createUuid(), contributorMask);
            permissionLevelManager.savePermissionLevel(contributorLevel);

            item.setPermissionLevel(contributorLevel);
            item.setPermissionLevelName("Contributor");
            permissionLevelManager.saveDBMembershipItem(item);
          }
        } else if (!item.getPermissionLevelName().equals("None")) {
          // kill other contributors
          PermissionLevel noneLevel =
              permissionLevelManager.createPermissionLevel(
                  "None", IdManager.createUuid(), noneMask);
          permissionLevelManager.savePermissionLevel(noneLevel);

          item.setPermissionLevel(noneLevel);
          item.setPermissionLevelName("None");
          permissionLevelManager.saveDBMembershipItem(item);
        }
      }
    }

    if (changed) {
      // System.out.println("changed");
      // have to refresh the topic or the save won't work
      topic = getTopicById(true, id);
      topic.setMembershipItemSet(oldMembershipItemSet);
      forumManager.saveDiscussionForumTopic((DiscussionTopic) topic);

      //	    topic.setVersion(null);
      //	    try {
      //		System.out.println("simplepagetool dao " + simplePageToolDao);
      //		hibernateTemplate.merge(topic);
      //	    } catch (Exception e){
      //		System.out.println("Unable to save forum topic " + e);
      //	    }

    }
  }
Example #5
0
  public String findObject(String objectid, Map<String, String> objectMap, String siteid) {
    if (!objectid.startsWith("forum_topic/") && !objectid.startsWith("forum_forum/")) {
      if (nextEntity != null) {
        return nextEntity.findObject(objectid, objectMap, siteid);
      }
      return null;
    }

    // isolate forum_topic/NNN from title
    int i = 0;

    if (objectid.startsWith("forum_topic/")) i = objectid.indexOf("/", "forum_topic/".length());
    else i = objectid.indexOf("/", "forum_forum/".length());
    if (i <= 0) return null;
    String realobjectid = objectid.substring(0, i);
    // msgcenter uses forum/ not forum_forum/
    if (objectid.startsWith("forum_forum/"))
      realobjectid = realobjectid.substring("forum_".length());

    // now see if it's in the map
    String newtopic = objectMap.get(realobjectid);
    if (newtopic != null) {
      if (objectid.startsWith("forum_forum/"))
        return "/forum_" + newtopic; // forum/ID >> /forum_forum/ID
      else return "/" + newtopic; // sakaiid is /forum_topic/ID
    }

    // this must be 2.8. Can't find the topic in the map
    // i is start of title
    String title = null;
    String forumtitle = null;
    if (objectid.startsWith("forum_topic/")) {
      int j = objectid.indexOf("\n");
      title = objectid.substring(i + 1, j);
      forumtitle = objectid.substring(j + 1);
    } else {
      forumtitle = objectid.substring(i + 1);
    }

    // unfortunately we have to search the topic tree to find it.
    SortedSet<DiscussionForum> forums =
        new TreeSet<DiscussionForum>(new ForumBySortIndexAscAndCreatedDateDesc());
    for (DiscussionForum forum : forumManager.getForumsForMainPage()) forums.add(forum);

    // security. assume this is only used in places where it's OK, so skip security checks
    // ignore draft status. We want to show drafts.
    for (DiscussionForum forum : forums) {
      if (forum.getTitle().equals(forumtitle)) {
        if (title == null) // object is forum not topic
        return "/forum_forum/" + forum.getId();
        for (Object o : forum.getTopicsSet()) {
          DiscussionTopic topic = (DiscussionTopic) o;
          if (topic.getTitle().equals(title)) {
            return "/forum_topic/" + topic.getId();
          }
        }
      }
    }

    return null;
  }