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:
@@ -1,32 +1,36 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Repository
|
* Alfresco Repository
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* 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
|
* 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
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.node;
|
package org.alfresco.repo.node;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.model.ContentModel;
|
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;
|
||||||
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
|
import org.alfresco.repo.node.NodeServicePolicies.BeforeDeleteNodePolicy;
|
||||||
import org.alfresco.repo.policy.Behaviour;
|
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.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
import org.alfresco.service.cmr.site.SiteService;
|
import org.alfresco.service.cmr.site.SiteService;
|
||||||
|
import org.alfresco.service.namespace.NamespaceService;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +59,8 @@ import org.alfresco.service.namespace.QName;
|
|||||||
* @author Neil Mc Erlean
|
* @author Neil Mc Erlean
|
||||||
* @since 3.5.0
|
* @since 3.5.0
|
||||||
*/
|
*/
|
||||||
public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePolicy
|
public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePolicy,
|
||||||
|
CopyServicePolicies.OnCopyNodePolicy
|
||||||
{
|
{
|
||||||
private PolicyComponent policyComponent;
|
private PolicyComponent policyComponent;
|
||||||
private NodeService nodeService;
|
private NodeService nodeService;
|
||||||
@@ -87,6 +93,11 @@ public class UndeletableAspect implements NodeServicePolicies.BeforeDeleteNodePo
|
|||||||
this.policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
|
this.policyComponent.bindClassBehaviour(BeforeDeleteNodePolicy.QNAME,
|
||||||
ContentModel.ASPECT_UNDELETABLE,
|
ContentModel.ASPECT_UNDELETABLE,
|
||||||
new JavaBehaviour(this, "beforeDeleteNode", Behaviour.NotificationFrequency.EVERY_EVENT));
|
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);
|
QName nodeType = nodeService.getType(nodeRef);
|
||||||
throw new AlfrescoRuntimeException(nodeType.toPrefixString() + " deletion is not allowed. Attempted to delete " + 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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1047,6 +1047,29 @@ public class CheckOutCheckInServiceImplTest extends BaseSpringTest
|
|||||||
fail("Lockable aspect should not be copied from the working copy to the original document");
|
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)
|
private NodeRef createFolderWithPermission(NodeRef parent, String username, String permission)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user