mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
MNT-18546: exclude the undeletable aspect from node copies
Added a policy implementation to the UndeletableAspect class so that the aspect is not copied to other nodes. This solves the problem where a document has the aspect added to it by Cloud sync (for example) and is then checked-out, but may never be checked in again (or editing cancelled) as the working copy included the sys:undeletable aspect.
This commit is contained in:
@@ -27,6 +27,10 @@ package org.alfresco.repo.node;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
||||
import org.alfresco.repo.copy.CopyDetails;
|
||||
import org.alfresco.repo.copy.CopyServicePolicies;
|
||||
import org.alfresco.repo.copy.DoNothingCopyBehaviourCallback;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
|
||||
import org.alfresco.repo.policy.Behaviour;
|
||||
@@ -35,6 +39,7 @@ import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
@@ -54,7 +59,8 @@ import org.alfresco.service.namespace.QName;
|
||||
* @author Neil Mc Erlean
|
||||
* @since 3.5.0
|
||||
*/
|
||||
public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePolicy
|
||||
public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePolicy,
|
||||
CopyServicePolicies.OnCopyNodePolicy
|
||||
{
|
||||
private PolicyComponent policyComponent;
|
||||
private NodeService nodeService;
|
||||
@@ -87,6 +93,11 @@ public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePo
|
||||
this.policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
|
||||
ContentModel.ASPECT_UNDELETABLE,
|
||||
new JavaBehaviour(this, "beforeDeleteNode", Behaviour.NotificationFrequency.EVERY_EVENT));
|
||||
|
||||
policyComponent.bindClassBehaviour(
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "getCopyCallback"),
|
||||
ContentModel.ASPECT_UNDELETABLE,
|
||||
new JavaBehaviour(this, "getCopyCallback"));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,4 +109,10 @@ public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePo
|
||||
QName nodeType = nodeService.getType(nodeRef);
|
||||
throw new AlfrescoRuntimeException(nodeType.toPrefixString() + " deletion is not allowed. Attempted to delete " + nodeRef);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CopyBehaviourCallback getCopyCallback(QName classRef, CopyDetails copyDetails)
|
||||
{
|
||||
return DoNothingCopyBehaviourCallback.getInstance();
|
||||
}
|
||||
}
|
||||
|
@@ -1048,6 +1048,29 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
||||
}
|
||||
}
|
||||
|
||||
public void testCanCheckInWhenOriginalHasUndeletableAspect()
|
||||
{
|
||||
nodeService.addAspect(nodeRef, ContentModel.ASPECT_UNDELETABLE, null);
|
||||
// Pre-condition of test, original must have sys:undeletable
|
||||
assertTrue(nodeService.hasAspect(nodeRef, ContentModel.ASPECT_UNDELETABLE));
|
||||
|
||||
// Check-out nodeRef
|
||||
NodeRef workingCopy = this.cociService.checkout(
|
||||
this.nodeRef,
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName("workingCopy"));
|
||||
assertNotNull(workingCopy);
|
||||
|
||||
// Check that the working copy does not have the sys:undeletable aspect
|
||||
assertFalse(nodeService.hasAspect(workingCopy, ContentModel.ASPECT_UNDELETABLE));
|
||||
|
||||
// Check-in: must work despite original having the sys:undeletable aspect (MNT-18546)
|
||||
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>();
|
||||
versionProperties.put(Version.PROP_DESCRIPTION, "This is a test version");
|
||||
cociService.checkin(workingCopy, versionProperties);
|
||||
}
|
||||
|
||||
private NodeRef createFolderWithPermission(NodeRef parent, String username, String permission)
|
||||
{
|
||||
// Authenticate as system user because the current user should not be node owner
|
||||
|
Reference in New Issue
Block a user