public static boolean contains(
      PermissionChecker permissionChecker, WikiPage page, String actionId) {

    if (actionId.equals(ActionKeys.VIEW)) {
      WikiPage redirectPage = page.getRedirectPage();

      if (redirectPage != null) {
        page = redirectPage;
      }
    }

    if (page.isPending()) {
      Boolean hasPermission =
          WorkflowPermissionUtil.hasPermission(
              permissionChecker,
              page.getGroupId(),
              WikiPage.class.getName(),
              page.getResourcePrimKey(),
              actionId);

      if (hasPermission != null) {
        return hasPermission.booleanValue();
      }
    }

    if (page.isDraft()
        && actionId.equals(ActionKeys.DELETE)
        && (page.getStatusByUserId() == permissionChecker.getUserId())) {

      return true;
    }

    if (permissionChecker.hasOwnerPermission(
        page.getCompanyId(),
        WikiPage.class.getName(),
        page.getResourcePrimKey(),
        page.getUserId(),
        actionId)) {

      return true;
    }

    if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
      WikiPage parentPage = page.getParentPage();

      if ((parentPage != null) && !contains(permissionChecker, parentPage, ActionKeys.VIEW)) {

        return false;
      }
    }

    return permissionChecker.hasPermission(
        page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId);
  }
  @Override
  public String getRestoreLink(PortletRequest portletRequest, long classPK)
      throws PortalException, SystemException {

    String portletId = PortletKeys.WIKI;

    WikiPage page = WikiPageLocalServiceUtil.getPage(classPK);

    long plid = PortalUtil.getPlidFromPortletId(page.getGroupId(), PortletKeys.WIKI);

    if (plid == LayoutConstants.DEFAULT_PLID) {
      plid = PortalUtil.getControlPanelPlid(portletRequest);

      portletId = PortletKeys.WIKI_ADMIN;
    }

    PortletURL portletURL =
        PortletURLFactoryUtil.create(portletRequest, portletId, plid, PortletRequest.RENDER_PHASE);

    WikiNode node = page.getNode();

    portletURL.setParameter("struts_action", "/wiki/view");
    portletURL.setParameter("nodeName", node.getName());
    portletURL.setParameter("title", HtmlUtil.unescape(page.getTitle()));

    return portletURL.toString();
  }
  private static boolean _hasPermission(
      PermissionChecker permissionChecker, WikiPage page, String actionId) {

    if (permissionChecker.hasOwnerPermission(
            page.getCompanyId(),
            WikiPage.class.getName(),
            page.getResourcePrimKey(),
            page.getUserId(),
            actionId)
        || permissionChecker.hasPermission(
            page.getGroupId(), WikiPage.class.getName(), page.getResourcePrimKey(), actionId)) {

      return true;
    }

    return false;
  }
  public static boolean contains(
      PermissionChecker permissionChecker, WikiPage page, String actionId) {

    Boolean hasPermission =
        StagingPermissionUtil.hasPermission(
            permissionChecker,
            page.getGroupId(),
            WikiPage.class.getName(),
            page.getPageId(),
            PortletKeys.WIKI,
            actionId);

    if (hasPermission != null) {
      return hasPermission.booleanValue();
    }

    if (page.isDraft()) {
      if (actionId.equals(ActionKeys.VIEW)
          && !contains(permissionChecker, page, ActionKeys.UPDATE)) {

        return false;
      }

      if (actionId.equals(ActionKeys.DELETE)
          && (page.getStatusByUserId() == permissionChecker.getUserId())) {

        return true;
      }
    } else if (page.isPending()) {
      hasPermission =
          WorkflowPermissionUtil.hasPermission(
              permissionChecker,
              page.getGroupId(),
              WikiPage.class.getName(),
              page.getResourcePrimKey(),
              actionId);

      if ((hasPermission != null) && hasPermission.booleanValue()) {
        return true;
      }
    } else if (page.isScheduled()) {
      if (actionId.equals(ActionKeys.VIEW)
          && !contains(permissionChecker, page, ActionKeys.UPDATE)) {

        return false;
      }
    }

    if (actionId.equals(ActionKeys.VIEW)) {
      WikiPage redirectPage = page.fetchRedirectPage();

      if (redirectPage != null) {
        page = redirectPage;
      }

      if (PropsValues.PERMISSIONS_VIEW_DYNAMIC_INHERITANCE) {
        WikiNode node = page.getNode();

        if (!WikiNodePermission.contains(permissionChecker, node, actionId)) {

          return false;
        }

        while (page != null) {
          if (!_hasPermission(permissionChecker, page, actionId)) {
            return false;
          }

          page = page.fetchParentPage();
        }

        return true;
      }
    }

    return _hasPermission(permissionChecker, page, actionId);
  }
Пример #5
0
  private String formatJournalArticleURL() {

    /* This checks if the object is viewable by the current user and, if so, works out
     * the original url for the search results. The "visible" flag variable is set for each one.
     */

    Long lGroupId;
    Long lArticleId;
    Long lUserId;
    String strJournalURL = Global.strNoURLReturned;

    JournalContentSearchLocalServiceUtil jcslu = new JournalContentSearchLocalServiceUtil();
    LayoutLocalServiceUtil llsu = new LayoutLocalServiceUtil();
    List<Long> listLayouts = new ArrayList<Long>();
    Layout layLayout;
    User user;
    int iCount = 0;
    this.isVisible = false;

    try {
      this.context = FacesContext.getCurrentInstance();
      this.portletRequest = (PortletRequest) context.getExternalContext().getRequest();
      this.themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);
    } catch (Exception e) {
      System.out.println(e);
    }

    try {
      lGroupId = Long.decode(this.getGroupId());
    } catch (NumberFormatException n) {
      lGroupId = 0l; // zero long, not letter O
    }

    try {
      lArticleId = Long.decode(this.getArticleId());
    } catch (NumberFormatException n) {
      lArticleId = 0l; // zero long, not letter O
    }

    try {
      lUserId = Long.decode(this.getUserId());
    } catch (NumberFormatException n) {
      lUserId = 0l; // zero long, not letter O
    }

    if ((lGroupId != 0) && (lArticleId != 0)) {
      try {
        try {
          permissionChecker = themeDisplay.getPermissionChecker();
          this.setIsVisible(
              permissionChecker.hasPermission(
                  lGroupId, this.entryClassName, this.rootEntryClassPK, ActionKeys.VIEW));
          if (this.isIsVisible()) {
            if (getEntryClassName().equalsIgnoreCase(JournalArticle.class.getName())) {
              iCount = jcslu.getLayoutIdsCount(lGroupId, false, articleId);
              listLayouts = jcslu.getLayoutIds(lGroupId, false, articleId);
              if (iCount > 0) {
                layLayout = llsu.getLayout(lGroupId, false, listLayouts.get(0));
                layoutFriendlyURL = PortalUtil.getLayoutFriendlyURL(layLayout, themeDisplay);
                layoutFullURL =
                    PortalUtil.getLayoutActualURL(layLayout, themeDisplay.getPathMain());
                strHost = portletRequest.getServerName();
                iServerPort = portletRequest.getServerPort();
                strScheme = portletRequest.getScheme();

                if (layoutFullURL.startsWith("http://")) {
                  strJournalURL = layoutFullURL;
                } else {
                  if (strHost.equalsIgnoreCase("localhost")) {
                    strJournalURL =
                        strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;
                  } else {
                    strJournalURL = layoutFriendlyURL;
                  }
                }
              }
            } else if (getEntryClassName().equalsIgnoreCase(BlogsEntry.class.getName())) {
              BlogsEntry entry = BlogsEntryLocalServiceUtil.getEntry(lArticleId);

              Group trgtGroup = GroupLocalServiceUtil.getGroup(lGroupId);
              String strFrUrl = trgtGroup.getFriendlyURL();
              String strUrlPath;
              user = UserLocalServiceUtil.getUser(lUserId);

              if (strFrUrl.equalsIgnoreCase("/fishnet")) {
                strUrlPath = "/home/-/blogs/";
              } else if (strFrUrl.equalsIgnoreCase("/fishlink")) {
                strUrlPath = "/home/-/blogs/";
              } else if (strFrUrl.equalsIgnoreCase("/freshwater-biological-association")) {
                strUrlPath = "/home/-/blogs/";
              } else {
                strUrlPath = "/blog/-/blogs/";
              }
              layoutFriendlyURL = "/web" + strFrUrl + strUrlPath + entry.getUrlTitle();

              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();

              strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;
            } else if (getEntryClassName().equalsIgnoreCase(WikiPage.class.getName())) {
              WikiPageResource pageResource =
                  WikiPageResourceLocalServiceUtil.getPageResource(lArticleId);

              WikiPage wikiPage =
                  WikiPageLocalServiceUtil.getPage(
                      pageResource.getNodeId(), pageResource.getTitle());
              WikiNode wikiNode = WikiNodeLocalServiceUtil.getNode(pageResource.getNodeId());
              String strWikiNodeName = wikiNode.getName();
              String strWikiTitle = wikiPage.getTitle();
              Long lPageGroupId = wikiPage.getGroupId();
              Group trgtGroup = GroupLocalServiceUtil.getGroup(lPageGroupId);
              String strFrUrl = trgtGroup.getFriendlyURL();

              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();
              // Extremely nasty hack!
              if (strFrUrl.equalsIgnoreCase("/tera")) {
                String strReplacedTitle = strWikiTitle.replaceAll("\\s", "\\+");
                layoutFriendlyURL =
                    "/web"
                        + strFrUrl
                        + "/home?p_p_id=54_INSTANCE_rU18&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_54_INSTANCE_rU18_struts_action=%2Fwiki_display%2Fview&_54_INSTANCE_rU18_nodeName="
                        + strWikiNodeName
                        + "&_54_INSTANCE_rU18_title="
                        + strReplacedTitle;
              } else if (strFrUrl.equalsIgnoreCase("/fwl")) {
                layoutFriendlyURL =
                    "/web" + strFrUrl + "/wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle;
              } else if (strFrUrl.equalsIgnoreCase("/fishlink")) {
                layoutFriendlyURL =
                    "/web"
                        + strFrUrl
                        + strFrUrl
                        + "-wiki/-/wiki/"
                        + strWikiNodeName
                        + "/"
                        + strWikiTitle;
              } else {
                layoutFriendlyURL =
                    "/freshwater-wiki/-/wiki/" + strWikiNodeName + "/" + strWikiTitle;
              }
              // </hack>
              strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;

            } else if (getEntryClassName().equalsIgnoreCase(DLFileEntry.class.getName())) {
              DLFileEntry fileEntry = DLFileEntryLocalServiceUtil.getFileEntry(lArticleId);
              lGroupId = fileEntry.getGroupId();

              AssetEntry assetEntry =
                  AssetEntryLocalServiceUtil.getEntry(getEntryClassName(), lArticleId);
              Long lEntryId = assetEntry.getEntryId();

              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();
              // Another hack
              layoutFriendlyURL = "/fwl/documents/-/asset_publisher/8Ztl/document/id/" + lEntryId;
              strJournalURL =
                  strScheme + "://" + strHost + ":" + iServerPort + "/web" + layoutFriendlyURL;
              if (fileEntry.getTitle().isEmpty()) {
                this.setTitle("From Document Library");
              } else {
                this.setTitle(fileEntry.getTitle());
              }
              //

            } else if (getEntryClassName().equalsIgnoreCase(IGImage.class.getName())) {
              IGImage image = IGImageLocalServiceUtil.getImage(lArticleId);

              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();

              layoutFriendlyURL = "igimage.fba.org.uk";
              // if (layoutFullURL.startsWith("http://")) {
              // strJournalURL = layoutFullURL;
              // } else {
              strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;
              // }
              // PortletURL viewImageURL = new PortletURLImpl(request, PortletKeys.IMAGE_GALLERY,
              // plid, PortletRequest.RENDER_PHASE);

              // viewImageURL.setWindowState(WindowState.MAXIMIZED);

              // viewImageURL.setParameter("struts_action", "/image_gallery/view");
              // viewImageURL.setParameter("folderId", String.valueOf(image.getFolderId()));

            } else if (getEntryClassName().equalsIgnoreCase(MBMessage.class.getName())) {
              MBMessage message = MBMessageLocalServiceUtil.getMessage(lArticleId);
              String aHref =
                  "<a href="
                      + themeDisplay.getPathMain()
                      + "/message_boards/find_message?messageId="
                      + message.getMessageId()
                      + ">";
              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();

              layoutFriendlyURL = "mbmessage.fba.org.uk";
              // if (layoutFullURL.startsWith("http://")) {
              // strJournalURL = layoutFullURL;
              // } else {
              strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;
              // }

            } else if (getEntryClassName().equalsIgnoreCase(BookmarksEntry.class.getName())) {
              BookmarksEntry entry = BookmarksEntryLocalServiceUtil.getEntry(lArticleId);

              String entryURL =
                  themeDisplay.getPathMain()
                      + "/bookmarks/open_entry?entryId="
                      + entry.getEntryId();

              strHost = portletRequest.getServerName();
              iServerPort = portletRequest.getServerPort();
              strScheme = portletRequest.getScheme();

              layoutFriendlyURL = "bookmarks.fba.org.uk";
              // if (layoutFullURL.startsWith("http://")) {
              // strJournalURL = layoutFullURL;
              // } else {
              strJournalURL = strScheme + "://" + strHost + ":" + iServerPort + layoutFriendlyURL;
              // }

            }
          }
        } catch (PortalException ex) {
          Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex);
        }
      } catch (SystemException ex) {
        Logger.getLogger(Liferay.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
    return strJournalURL;
  }
  public void markNotSpamWikiPages(ActionRequest actionRequest, ActionResponse actionResponse)
      throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    checkWikiPagePermission(themeDisplay.getScopeGroupId());

    long[] wikiPageIds = ParamUtil.getLongValues(actionRequest, "notSpamWikiPageIds");

    List<String> wikiPageLinks = new ArrayList<String>();

    for (long wikiPageId : wikiPageIds) {
      WikiPage wikiPage = WikiPageLocalServiceUtil.getPageByPageId(wikiPageId);

      WikiPage latestVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), false);

      String latestContent = null;

      if (latestVersionWikiPage != null) {
        latestContent = latestVersionWikiPage.getContent();
      }

      WikiPage previousVersionWikiPage =
          AkismetUtil.getWikiPage(
              wikiPage.getNodeId(), wikiPage.getTitle(), wikiPage.getVersion(), true);

      String previousContent = null;

      if (previousVersionWikiPage != null) {
        previousContent = previousVersionWikiPage.getContent();
      }

      // Selected version

      wikiPage.setStatus(WorkflowConstants.STATUS_APPROVED);
      wikiPage.setSummary(StringPool.BLANK);

      wikiPage = WikiPageLocalServiceUtil.updateWikiPage(wikiPage);

      // Latest version

      if ((latestContent != null)
          && ((previousContent == null) || latestContent.equals(previousContent))) {

        ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

        WikiPageLocalServiceUtil.revertPage(
            themeDisplay.getUserId(),
            wikiPage.getNodeId(),
            wikiPage.getTitle(),
            wikiPage.getVersion(),
            serviceContext);
      } else {
        StringBundler sb = new StringBundler(5);

        sb.append("<a href=\"");

        long plid = PortalUtil.getPlidFromPortletId(wikiPage.getGroupId(), PortletKeys.WIKI);

        LiferayPortletURL liferayPortletURL =
            PortletURLFactoryUtil.create(
                actionRequest, PortletKeys.WIKI, plid, PortletRequest.RENDER_PHASE);

        WikiNode wikiNode = wikiPage.getNode();

        liferayPortletURL.setParameter("struts_action", "/wiki/view");
        liferayPortletURL.setParameter("nodeName", wikiNode.getName());
        liferayPortletURL.setParameter("title", wikiPage.getTitle());
        liferayPortletURL.setParameter("version", String.valueOf(wikiPage.getVersion()));

        sb.append(liferayPortletURL.toString());
        sb.append("\" target=\"_blank\">");
        sb.append(HtmlUtil.escape(wikiPage.getTitle()));
        sb.append("</a>");

        wikiPageLinks.add(sb.toString());
      }

      // Akismet

      if (AkismetUtil.isWikiEnabled(wikiPage.getCompanyId())) {
        AkismetUtil.submitHam(wikiPage);
      }
    }

    if (!wikiPageLinks.isEmpty()) {
      SessionMessages.add(actionRequest, "requestProcessed");

      SessionMessages.add(
          actionRequest,
          "anotherUserHasMadeChangesToThesePages",
          StringUtil.merge(wikiPageLinks, "<br />"));

      super.sendRedirect(actionRequest, actionResponse);
    }
  }