| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU Lesser General Public License as published by the Free | ||
| * Software Foundation; either version 2.1 of the License, or (at your option) | ||
| * any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
| * details. | ||
| */ | ||
|
|
||
| package com.liferay.portlet.wiki.model; | ||
|
|
||
| import com.liferay.portal.ModelListenerException; | ||
| import com.liferay.portal.kernel.exception.SystemException; | ||
| import com.liferay.portal.kernel.util.ReflectionUtil; | ||
| import com.liferay.portal.kernel.util.StringUtil; | ||
| import com.liferay.portal.kernel.util.Validator; | ||
| import com.liferay.portal.model.BaseModelListener; | ||
| import com.liferay.portlet.wiki.service.persistence.WikiPageUtil; | ||
|
|
||
| /** | ||
| * @author Tomas Polesovsky | ||
| */ | ||
| public class CycleDetectorWikiPageModelListener | ||
| extends BaseModelListener<WikiPage> { | ||
|
|
||
| @Override | ||
| public void onBeforeCreate(WikiPage model) throws ModelListenerException { | ||
| if (isCycleDetectedInWikiPagesGraph(model)) { | ||
| throw new ModelListenerException( | ||
| "Unable to create wiki page " + model.getTitle() + | ||
| " because a cycle was detected"); | ||
| } | ||
|
|
||
| super.onBeforeCreate(model); | ||
| } | ||
|
|
||
| @Override | ||
| public void onBeforeUpdate(WikiPage model) throws ModelListenerException { | ||
| if (isCycleDetectedInWikiPagesGraph(model)) { | ||
| throw new ModelListenerException( | ||
| "Unable to update wiki page " + model.getTitle() + | ||
| " because a cycle was detected"); | ||
| } | ||
|
|
||
| super.onBeforeUpdate(model); | ||
| } | ||
|
|
||
| protected boolean isCycleDetectedInWikiPagesGraph(WikiPage wikiPage) { | ||
| String title = wikiPage.getTitle(); | ||
|
|
||
| if (Validator.isBlank(title)) { | ||
| return false; | ||
| } | ||
|
|
||
| title = title.trim(); | ||
|
|
||
| try { | ||
| while (wikiPage != null) { | ||
| String parentTitle = wikiPage.getParentTitle(); | ||
|
|
||
| if (Validator.isBlank(parentTitle)) { | ||
| return false; | ||
| } | ||
|
|
||
| parentTitle = parentTitle.trim(); | ||
|
|
||
| if (StringUtil.equalsIgnoreCase(title, parentTitle)) { | ||
| return true; | ||
| } | ||
|
|
||
| wikiPage = WikiPageUtil.fetchByN_T_H_First( | ||
| wikiPage.getNodeId(), wikiPage.getParentTitle(), true, | ||
| null); | ||
| } | ||
| } | ||
| catch (SystemException se) { | ||
| ReflectionUtil.throwException(se); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU Lesser General Public License as published by the Free | ||
| * Software Foundation; either version 2.1 of the License, or (at your option) | ||
| * any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
| * details. | ||
| */ | ||
|
|
||
| package com.liferay.portlet.workflowdefinitions.action; | ||
|
|
||
| import com.liferay.portal.security.permission.PermissionChecker; | ||
| import com.liferay.portal.util.PropsValues; | ||
|
|
||
| /** | ||
| * @author Inácio Nery | ||
| */ | ||
| public class WorkflowDefinitionPermissionChecker { | ||
|
|
||
| public static boolean canPublishWorkflowDefinition( | ||
| PermissionChecker permissionChecker) { | ||
|
|
||
| if (permissionChecker == null) { | ||
| return true; | ||
| } | ||
|
|
||
| if (PropsValues.WORKFLOW_COMPANY_ADMINISTRATOR_CAN_PUBLISH && | ||
| permissionChecker.isCompanyAdmin()) { | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| if (permissionChecker.isOmniadmin()) { | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?xml version="1.0"?> | ||
|
|
||
| <properties> | ||
| <parsers> | ||
| <parser class="org.apache.tika.parser.asm.ClassParser" /> | ||
| <parser class="org.apache.tika.parser.audio.AudioParser" /> | ||
| <parser class="org.apache.tika.parser.audio.MidiParser" /> | ||
| <parser class="org.apache.tika.parser.chm.ChmParser" /> | ||
| <parser class="org.apache.tika.parser.code.SourceCodeParser" /> | ||
| <parser class="org.apache.tika.parser.dif.DIFParser" /> | ||
| <parser class="org.apache.tika.parser.dwg.DWGParser" /> | ||
| <parser class="org.apache.tika.parser.epub.EpubParser" /> | ||
| <parser class="org.apache.tika.parser.executable.ExecutableParser" /> | ||
| <parser class="org.apache.tika.parser.external.CompositeExternalParser" /> | ||
| <parser class="org.apache.tika.parser.feed.FeedParser" /> | ||
| <parser class="org.apache.tika.parser.font.AdobeFontMetricParser" /> | ||
| <parser class="org.apache.tika.parser.font.TrueTypeParser" /> | ||
| <parser class="org.apache.tika.parser.gdal.GDALParser" /> | ||
| <parser class="org.apache.tika.parser.grib.GribParser" /> | ||
| <parser class="org.apache.tika.parser.hdf.HDFParser" /> | ||
| <parser class="org.apache.tika.parser.html.HtmlParser" /> | ||
| <parser class="org.apache.tika.parser.image.BPGParser" /> | ||
| <parser class="org.apache.tika.parser.image.ImageParser" /> | ||
| <parser class="org.apache.tika.parser.image.PSDParser" /> | ||
| <parser class="org.apache.tika.parser.image.TiffParser" /> | ||
| <parser class="org.apache.tika.parser.image.WebPParser" /> | ||
| <parser class="org.apache.tika.parser.iptc.IptcAnpaParser" /> | ||
| <parser class="org.apache.tika.parser.isatab.ISArchiveParser" /> | ||
| <parser class="org.apache.tika.parser.iwork.IWorkPackageParser" /> | ||
| <parser class="org.apache.tika.parser.jdbc.SQLite3Parser" /> | ||
| <parser class="org.apache.tika.parser.jpeg.JpegParser" /> | ||
| <parser class="org.apache.tika.parser.mail.RFC822Parser" /> | ||
| <parser class="org.apache.tika.parser.mat.MatParser" /> | ||
| <parser class="org.apache.tika.parser.mbox.MboxParser" /> | ||
| <parser class="org.apache.tika.parser.mbox.OutlookPSTParser" /> | ||
| <parser class="org.apache.tika.parser.microsoft.OfficeParser" /> | ||
| <parser class="org.apache.tika.parser.microsoft.OldExcelParser" /> | ||
| <parser class="org.apache.tika.parser.microsoft.TNEFParser" /> | ||
| <parser class="org.apache.tika.parser.microsoft.ooxml.OOXMLParser" /> | ||
| <parser class="org.apache.tika.parser.mp3.Mp3Parser" /> | ||
| <parser class="org.apache.tika.parser.mp4.MP4Parser" /> | ||
| <parser class="org.apache.tika.parser.netcdf.NetCDFParser" /> | ||
| <parser class="org.apache.tika.parser.ocr.TesseractOCRParser" /> | ||
| <parser class="org.apache.tika.parser.odf.OpenDocumentParser" /> | ||
| <parser class="org.apache.tika.parser.pdf.PDFParser" /> | ||
| <parser class="org.apache.tika.parser.pkg.CompressorParser" /> | ||
| <parser class="org.apache.tika.parser.pkg.PackageParser" /> | ||
| <parser class="org.apache.tika.parser.rtf.RTFParser" /> | ||
| <parser class="org.apache.tika.parser.txt.TXTParser" /> | ||
| <parser class="org.apache.tika.parser.video.FLVParser" /> | ||
| <parser class="org.apache.tika.parser.xml.DcXMLParser" /> | ||
| <parser class="org.apache.tika.parser.xml.FictionBookParser" /> | ||
| <parser class="org.gagravarr.tika.FlacParser" /> | ||
| <parser class="org.gagravarr.tika.OggParser" /> | ||
| <parser class="org.gagravarr.tika.OpusParser" /> | ||
| <parser class="org.gagravarr.tika.SpeexParser" /> | ||
| <parser class="org.gagravarr.tika.VorbisParser" /> | ||
| </parsers> | ||
| </properties> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| /** | ||
| * Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU Lesser General Public License as published by the Free | ||
| * Software Foundation; either version 2.1 of the License, or (at your option) | ||
| * any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
| * details. | ||
| */ | ||
|
|
||
| package com.liferay.portlet.wiki.model; | ||
|
|
||
| import com.liferay.portal.ModelListenerException; | ||
| import com.liferay.portal.kernel.test.ExecutionTestListeners; | ||
| import com.liferay.portal.kernel.util.StringPool; | ||
| import com.liferay.portal.model.Group; | ||
| import com.liferay.portal.service.GroupLocalServiceUtil; | ||
| import com.liferay.portal.service.ServiceContext; | ||
| import com.liferay.portal.service.ServiceTestUtil; | ||
| import com.liferay.portal.test.EnvironmentExecutionTestListener; | ||
| import com.liferay.portal.test.LiferayIntegrationJUnitTestRunner; | ||
| import com.liferay.portal.test.Sync; | ||
| import com.liferay.portal.test.SynchronousDestinationExecutionTestListener; | ||
| import com.liferay.portal.util.GroupTestUtil; | ||
| import com.liferay.portal.util.TestPropsValues; | ||
| import com.liferay.portlet.wiki.service.WikiPageLocalServiceUtil; | ||
| import com.liferay.portlet.wiki.util.WikiTestUtil; | ||
|
|
||
| import org.junit.After; | ||
| import org.junit.Assert; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| /** | ||
| * @author Tomas Polesovsky | ||
| */ | ||
| @ExecutionTestListeners(listeners = { | ||
| EnvironmentExecutionTestListener.class, | ||
| SynchronousDestinationExecutionTestListener.class | ||
| }) | ||
| @RunWith(LiferayIntegrationJUnitTestRunner.class) | ||
| @Sync | ||
| public class CycleDetectorWikiPageModelListenerTest { | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| ServiceTestUtil.setUser(TestPropsValues.getUser()); | ||
|
|
||
| _group = GroupTestUtil.addGroup(); | ||
|
|
||
| _node = WikiTestUtil.addNode( | ||
| TestPropsValues.getUserId(), _group.getGroupId(), | ||
| ServiceTestUtil.randomString(), ServiceTestUtil.randomString(50)); | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| GroupLocalServiceUtil.deleteGroup(_group); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCycle() throws Exception { | ||
| WikiPage wikiPage1 = WikiPageLocalServiceUtil.addPage( | ||
| TestPropsValues.getUserId(), _node.getNodeId(), "Title1", | ||
| StringPool.BLANK, StringPool.BLANK, true, new ServiceContext()); | ||
|
|
||
| WikiPage wikiPage2 = WikiPageLocalServiceUtil.addPage( | ||
| TestPropsValues.getUserId(), _node.getNodeId(), "Title2", | ||
| StringPool.BLANK, StringPool.BLANK, true, new ServiceContext()); | ||
|
|
||
| WikiPage wikiPage3 = WikiPageLocalServiceUtil.addPage( | ||
| TestPropsValues.getUserId(), _node.getNodeId(), "Title3", | ||
| StringPool.BLANK, StringPool.BLANK, true, new ServiceContext()); | ||
|
|
||
| try { | ||
| wikiPage1.setParentTitle("Title2"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage1); | ||
|
|
||
| wikiPage2.setParentTitle("Title3"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage2); | ||
|
|
||
| wikiPage3.setParentTitle("Title1"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage3); | ||
|
|
||
| Assert.fail(); | ||
| } | ||
| catch (ModelListenerException mle) { | ||
| String message = mle.getMessage(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Unable to update wiki page Title3 because a cycle was " + | ||
| "detected", | ||
| message); | ||
| } | ||
|
|
||
| try { | ||
| wikiPage3.setParentTitle("Other"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage3); | ||
|
|
||
| wikiPage1.setTitle("Other"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage1); | ||
|
|
||
| Assert.fail(); | ||
| } | ||
| catch (ModelListenerException mle) { | ||
| String message = mle.getMessage(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Unable to update wiki page Other because a cycle was detected", | ||
| message); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSelfReferencingWikiPage() throws Exception { | ||
| String title = "Cycling Page"; | ||
|
|
||
| String parentTitle = title; | ||
|
|
||
| try { | ||
| WikiPageLocalServiceUtil.addPage( | ||
| TestPropsValues.getUserId(), _node.getNodeId(), title, | ||
| WikiPageConstants.VERSION_DEFAULT, StringPool.BLANK, | ||
| StringPool.BLANK, false, "creole", false, parentTitle, | ||
| StringPool.BLANK, new ServiceContext()); | ||
|
|
||
| Assert.fail(); | ||
| } | ||
| catch (ModelListenerException mle) { | ||
| String message = mle.getMessage(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Unable to create wiki page " + title + | ||
| " because a cycle was detected", | ||
| message); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSelfReferencingWikiPageDelayedSet() throws Exception { | ||
| WikiPage wikiPage1 = WikiPageLocalServiceUtil.addPage( | ||
| TestPropsValues.getUserId(), _node.getNodeId(), "Title", | ||
| StringPool.BLANK, StringPool.BLANK, true, new ServiceContext()); | ||
|
|
||
| try { | ||
| wikiPage1.setParentTitle("Title"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage1); | ||
|
|
||
| Assert.fail(); | ||
| } | ||
| catch (ModelListenerException mle) { | ||
| String message = mle.getMessage(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Unable to update wiki page Title because a cycle was detected", | ||
| message); | ||
| } | ||
|
|
||
| try { | ||
| wikiPage1.setParentTitle("Other Title"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage1); | ||
|
|
||
| wikiPage1.setTitle("Other Title"); | ||
|
|
||
| WikiPageLocalServiceUtil.updateWikiPage(wikiPage1); | ||
|
|
||
| Assert.fail(); | ||
| } | ||
| catch (ModelListenerException mle) { | ||
| String message = mle.getMessage(); | ||
|
|
||
| Assert.assertEquals( | ||
| "Unable to update wiki page Other Title because a cycle was " + | ||
| "detected", | ||
| message); | ||
| } | ||
| } | ||
|
|
||
| private Group _group; | ||
|
|
||
| private WikiNode _node; | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <%-- | ||
| /** | ||
| * Copyright (c) 2000-present Liferay, Inc. All rights reserved. | ||
| * | ||
| * This library is free software; you can redistribute it and/or modify it under | ||
| * the terms of the GNU Lesser General Public License as published by the Free | ||
| * Software Foundation; either version 2.1 of the License, or (at your option) | ||
| * any later version. | ||
| * | ||
| * This library is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
| * details. | ||
| */ | ||
| --%> | ||
|
|
||
| <%@ include file="/html/taglib/init.jsp" %> | ||
|
|
||
| <% | ||
| String errorMessage = (String)request.getAttribute("liferay-portlet:runtime:errorMessage"); | ||
| %> | ||
|
|
||
| <div class="alert alert-warning lfr-configurator-visibility lfr-meta-actions"> | ||
| <%= errorMessage %> | ||
| </div> |