Exemplo n.º 1
0
  public List<Group> getAncestors() throws PortalException, SystemException {
    List<Group> groups = new ArrayList<Group>();

    Group group = this;

    while (true) {
      if (!group.isRoot()) {
        group = group.getParentGroup();

        groups.add(group);
      } else {
        break;
      }
    }

    return groups;
  }
  @Override
  public List<Group> getAncestors() throws PortalException, SystemException {
    Group group = null;

    if (isStagingGroup()) {
      group = getLiveGroup();
    } else {
      group = this;
    }

    List<Group> groups = new ArrayList<Group>();

    while (!group.isRoot()) {
      group = group.getParentGroup();

      groups.add(group);
    }

    return groups;
  }
  @Override
  public boolean contains(PermissionChecker permissionChecker, Group group, String actionId)
      throws PortalException, SystemException {

    long groupId = group.getGroupId();

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    if (group.isUser()) {

      // An individual user would never reach this block because he would
      // be an administrator of his own layouts. However, a user who
      // manages a set of organizations may be modifying pages of a user
      // he manages.

      User user = UserLocalServiceUtil.getUserById(group.getClassPK());

      if ((permissionChecker.getUserId() != user.getUserId())
          && UserPermissionUtil.contains(
              permissionChecker, user.getUserId(), user.getOrganizationIds(), ActionKeys.UPDATE)) {

        return true;
      }
    }

    if (actionId.equals(ActionKeys.ADD_COMMUNITY)
            && permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_SUBGROUPS)
        || PortalPermissionUtil.contains(permissionChecker, ActionKeys.ADD_COMMUNITY)) {

      return true;
    } else if (actionId.equals(ActionKeys.ADD_LAYOUT)
        && !group.isLayoutPrototype()
        && permissionChecker.hasPermission(
            groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS)) {

      return true;
    } else if ((actionId.equals(ActionKeys.EXPORT_IMPORT_LAYOUTS)
            || actionId.equals(ActionKeys.EXPORT_IMPORT_PORTLET_INFO))
        && permissionChecker.hasPermission(
            groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING)) {

      return true;
    } else if (actionId.equals(ActionKeys.VIEW)
        && (permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.ASSIGN_USER_ROLES)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS))) {

      return true;
    } else if (actionId.equals(ActionKeys.VIEW_STAGING)
        && (permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_LAYOUTS)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.MANAGE_STAGING)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.PUBLISH_STAGING)
            || permissionChecker.hasPermission(
                groupId, Group.class.getName(), groupId, ActionKeys.UPDATE))) {

      return true;
    }

    // Group id must be set so that users can modify their personal pages

    if (permissionChecker.hasPermission(groupId, Group.class.getName(), groupId, actionId)) {

      return true;
    }

    while (!group.isRoot()) {
      if (contains(permissionChecker, group.getParentGroupId(), ActionKeys.MANAGE_SUBGROUPS)) {

        return true;
      }

      group = group.getParentGroup();
    }

    return false;
  }