mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.1/Cloud)
104361: Merged 5.0.N (5.0.2) to HEAD-BUG-FIX (5.1/Cloud) 104249: Merged V4.2-BUG-FIX (4.2.5) to 5.0.N (5.0.2) 104150: Merged DEV (4.2.5) to V4.2-BUG-FIX (4.2.5) 104089: MNT-13577: Incorrect site handling in Outlook client by Alfresco Administrator and Site Manager - Added unmovable aspect to restrict move of nodes. Unmovable aspect added to st:site type. - Added JUnit test. - Added patch for the fix. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@104517 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -153,6 +153,9 @@ patch.fixWebscriptTemplate.description=Reimport fixed sample template.
|
||||
patch.fixWebscriptTemplate.skip=Template not found. Skipping.
|
||||
patch.fixWebscriptTemplate.result=Fixed template was updated.
|
||||
|
||||
patch.addUnmovableAspect.description=Add unmovable aspect to sites.
|
||||
patch.addUnmovableAspect.result=Unmovable aspect has been added to sites.
|
||||
|
||||
patch.updateDmPermissions.description=Update ACLs on all DM node objects to the new 3.0 permission model
|
||||
|
||||
patch.db-V3.0-0-CreateActivitiesExtras.description=Replaced by 'patch.db-V3.0-ActivityTables', which must run first.
|
||||
|
@@ -49,6 +49,8 @@
|
||||
<aspect>cm:titled</aspect>
|
||||
<!-- Sites are by default undeletable. Only deletable through the SiteService. -->
|
||||
<aspect>sys:undeletable</aspect>
|
||||
<!-- Sites are by default unmovable. -->
|
||||
<aspect>sys:unmovable</aspect>
|
||||
</mandatory-aspects>
|
||||
</type>
|
||||
|
||||
|
@@ -241,6 +241,11 @@
|
||||
<title>Undeletable</title>
|
||||
</aspect>
|
||||
|
||||
<!-- aspect to tag nodes that are, by default, unmovable -->
|
||||
<aspect name="sys:unmovable">
|
||||
<title>Unmovable</title>
|
||||
</aspect>
|
||||
|
||||
<!-- aspect to tag nodes during delete operations -->
|
||||
<aspect name="sys:pendingDelete">
|
||||
<title>Pending Delete</title>
|
||||
|
@@ -278,6 +278,12 @@
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
</bean>
|
||||
|
||||
<!-- The unmovable aspect -->
|
||||
<bean id="unmovableAspect" class="org.alfresco.repo.node.UnmovableAspect" init-method="init">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="policyComponent" ref="policyComponent"/>
|
||||
</bean>
|
||||
|
||||
<!-- Encryptor for node properties -->
|
||||
<bean id="metadataEncryptor" class="org.alfresco.repo.node.encryption.MetadataEncryptor">
|
||||
<property name="dictionaryService" ref="dictionaryService" />
|
||||
|
@@ -1065,6 +1065,24 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="patch.addUnmovableAspect" class="org.alfresco.repo.admin.patch.impl.AddUnmovableAspectToSitesPatch"
|
||||
parent="basePatch">
|
||||
<property name="id" value="patch.addUnmovableAspect" />
|
||||
<property name="description" value="patch.addUnmovableAspect.description" />
|
||||
<property name="fixesFromSchema">
|
||||
<value>0</value>
|
||||
</property>
|
||||
<property name="fixesToSchema">
|
||||
<value>9003</value>
|
||||
</property>
|
||||
<property name="targetSchema">
|
||||
<value>9004</value>
|
||||
</property>
|
||||
<property name="siteService">
|
||||
<ref bean="siteService" />
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="patch.imapSpacesTemplates3" class="org.alfresco.repo.admin.patch.impl.GenericBootstrapPatch" parent="basePatch" >
|
||||
<property name="id"><value>patch.imapSpacesTemplates3</value></property>
|
||||
<property name="description"><value>patch.imapSpacesLocaleTemplates2.description</value></property>
|
||||
|
@@ -23,4 +23,4 @@ version.build=r@scm-revision@-b@build-number@
|
||||
|
||||
# Schema number
|
||||
|
||||
version.schema=9003
|
||||
version.schema=9004
|
||||
|
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.admin.patch.impl;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.admin.patch.AbstractPatch;
|
||||
import org.alfresco.repo.batch.BatchProcessWorkProvider;
|
||||
import org.alfresco.repo.batch.BatchProcessor;
|
||||
import org.alfresco.repo.site.SiteModel;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
/**
|
||||
* MNT-13577: Prevent sites to be moved
|
||||
*
|
||||
* @author Sergey Scherbovich
|
||||
* @author Alex Mukha
|
||||
*
|
||||
*/
|
||||
public class AddUnmovableAspectToSitesPatch extends AbstractPatch
|
||||
{
|
||||
private static Log logger = LogFactory.getLog(AddUnmovableAspectToSitesPatch.class);
|
||||
private static final String MSG_SUCCESS = "patch.addUnmovableAspect.result";
|
||||
|
||||
private final int NUM_THREADS = 4;
|
||||
private final int BATCH_SIZE = 200;
|
||||
|
||||
private SiteService siteService;
|
||||
|
||||
public void setSiteService(SiteService siteService)
|
||||
{
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String applyInternal() throws Exception
|
||||
{
|
||||
BatchProcessWorkProvider<ChildAssociationRef> workProvider = new BatchProcessWorkProvider<ChildAssociationRef>()
|
||||
{
|
||||
NodeRef sitesRoot = siteService.getSiteRoot();
|
||||
List<ChildAssociationRef> sites = nodeService.getChildAssocs(sitesRoot, Collections.singleton(SiteModel.TYPE_SITE));
|
||||
final Iterator<ChildAssociationRef> iterator = sites.listIterator();
|
||||
|
||||
@Override
|
||||
public int getTotalEstimatedWorkSize()
|
||||
{
|
||||
return sites.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ChildAssociationRef> getNextWork()
|
||||
{
|
||||
List<ChildAssociationRef> sites = new ArrayList<ChildAssociationRef>(BATCH_SIZE);
|
||||
while (iterator.hasNext() && sites.size() <= BATCH_SIZE)
|
||||
{
|
||||
sites.add(iterator.next());
|
||||
}
|
||||
return sites;
|
||||
}
|
||||
};
|
||||
|
||||
RetryingTransactionHelper txnHelper = transactionService.getRetryingTransactionHelper();
|
||||
txnHelper.setForceWritable(true);
|
||||
|
||||
BatchProcessor<ChildAssociationRef> batchProcessor = new BatchProcessor<ChildAssociationRef>(
|
||||
"AddUnmovableAspectToSitesPatch",
|
||||
txnHelper,
|
||||
workProvider,
|
||||
NUM_THREADS,
|
||||
BATCH_SIZE,
|
||||
applicationEventPublisher,
|
||||
logger,
|
||||
1000);
|
||||
|
||||
BatchProcessor.BatchProcessWorker<ChildAssociationRef> worker = new BatchProcessor.BatchProcessWorker<ChildAssociationRef>()
|
||||
{
|
||||
public void afterProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public void beforeProcess() throws Throwable
|
||||
{
|
||||
}
|
||||
|
||||
public String getIdentifier(ChildAssociationRef entry)
|
||||
{
|
||||
return entry.toString();
|
||||
}
|
||||
|
||||
public void process(ChildAssociationRef child) throws Throwable
|
||||
{
|
||||
nodeService.addAspect(child.getChildRef(), ContentModel.ASPECT_UNMOVABLE, null);
|
||||
}
|
||||
};
|
||||
|
||||
batchProcessor.process(worker, true);
|
||||
|
||||
return I18NUtil.getMessage(MSG_SUCCESS);
|
||||
}
|
||||
}
|
89
source/java/org/alfresco/repo/node/UnmovableAspect.java
Executable file
89
source/java/org/alfresco/repo/node/UnmovableAspect.java
Executable file
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright (C) 2005-2015 Alfresco Software Limited.
|
||||
*
|
||||
* This file is part of Alfresco
|
||||
*
|
||||
* Alfresco 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 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Alfresco 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.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.alfresco.repo.node;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.BeforeMoveNodePolicy;
|
||||
import org.alfresco.repo.policy.Behaviour;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* Unmovable aspect behaviour bean.
|
||||
*
|
||||
* Deletions of nodes with the {@link ContentModel#ASPECT_UNMOVABLE} are not allowed by default.
|
||||
* This class registers the behaviour that prevents the move.
|
||||
* <p/>
|
||||
* This aspect/behaviour combination allows for detailed application control of when node deletion is allowed
|
||||
* or disallowed for particular nodes. It is not related to the normal permissions controls, which of course apply.
|
||||
* <p/>
|
||||
* @author Sergey Scherbovich
|
||||
* @since 4.2.5
|
||||
*/
|
||||
public class UnmovableAspect implements NodeServicePolicies.BeforeMoveNodePolicy
|
||||
{
|
||||
private PolicyComponent policyComponent;
|
||||
private NodeService nodeService;
|
||||
|
||||
/**
|
||||
* Set the policy component
|
||||
*
|
||||
* @param policyComponent policy component
|
||||
*/
|
||||
public void setPolicyComponent(PolicyComponent policyComponent)
|
||||
{
|
||||
this.policyComponent = policyComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the node service
|
||||
*
|
||||
* @param nodeService node service
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise method
|
||||
*/
|
||||
public void init()
|
||||
{
|
||||
this.policyComponent.bindClassBehaviour(BeforeMoveNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_UNMOVABLE,
|
||||
new JavaBehaviour(this, "beforeMoveNode", Behaviour.NotificationFrequency.EVERY_EVENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents node from to be moved
|
||||
*/
|
||||
@Override
|
||||
public void beforeMoveNode(ChildAssociationRef oldChildAssocRef, NodeRef newParentRef)
|
||||
{
|
||||
QName nodeType = nodeService.getType(oldChildAssocRef.getChildRef());
|
||||
throw new AlfrescoRuntimeException(nodeType.toPrefixString() + " move is not allowed. Attempted to move " + oldChildAssocRef.getChildRef());
|
||||
}
|
||||
}
|
@@ -982,6 +982,30 @@ public class SiteServiceImplTest extends BaseAlfrescoSpringTest
|
||||
}
|
||||
}
|
||||
|
||||
public void testMoveSite_ViaNodeService()
|
||||
{
|
||||
String siteShortName1 = "testMoveSite" + GUID.generate();
|
||||
String siteShortName2 = "testMoveSite" + GUID.generate();
|
||||
this.siteService.createSite(TEST_SITE_PRESET, siteShortName1, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||
this.siteService.createSite(TEST_SITE_PRESET, siteShortName2, TEST_TITLE, TEST_DESCRIPTION, SiteVisibility.PUBLIC);
|
||||
|
||||
SiteInfo siteInfo1 = this.siteService.getSite(siteShortName1);
|
||||
assertNotNull(siteInfo1);
|
||||
SiteInfo siteInfo2 = this.siteService.getSite(siteShortName2);
|
||||
assertNotNull(siteInfo2);
|
||||
|
||||
// move a site through the nodeService - not allowed
|
||||
try
|
||||
{
|
||||
nodeService.moveNode(siteInfo1.getNodeRef(), siteInfo2.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, GUID.generate()));
|
||||
fail("Shouldn't be able to move a site via the nodeService");
|
||||
}
|
||||
catch (AlfrescoRuntimeException expected)
|
||||
{
|
||||
// Intentionally empty
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteSite()
|
||||
{
|
||||
@SuppressWarnings("deprecation")
|
||||
|
Reference in New Issue
Block a user