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:
Matt Ward
2017-09-25 16:54:05 +01:00
parent 29743d8f74
commit 6b50c33740
2 changed files with 66 additions and 26 deletions

View File

@@ -1,32 +1,36 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* 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/>.
* #L%
*/
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();
}
}

View File

@@ -1047,6 +1047,29 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
fail("Lockable aspect should not be copied from the working copy to the original document");
}
}
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)
{