Merge branch 'feature/RM-6911_AddActiveContentToHoldRestAPI' of https://git.alfresco.com/records-management/records-management into feature/RM-6914_AddRemoveToHold_Tests

This commit is contained in:
Rodica Sutu
2019-08-20 08:54:40 +03:00
4 changed files with 37 additions and 49 deletions

View File

@@ -2,4 +2,8 @@ rm.hold.not-hold=The node {0} is not a hold.
rm.hold.add-to-hold-invalid-type={0} is neither a record nor a record folder nor active content. Only records, record \
folders or active content can be added to a hold.
rm.hold.add-to-hold-archived-node=Archived nodes can't be added to hold.
rm.hold.add-to-hold-locked-node=Locked nodes can't be added to hold.
rm.hold.add-to-hold-locked-node=Locked nodes can't be added to hold.
rm.hold.delete-frozen-node=Frozen nodes can not be deleted.
rm.hold.delete-node-frozen-children=Can not delete node, because it contains a frozen child node.
rm.hold.move-frozen-node=Frozen nodes can not be moved.
rm.hold.update-frozen-node=Frozen nodes can not be updated.

View File

@@ -45,10 +45,11 @@ import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* rma:frozen behaviour bean
@@ -95,7 +96,7 @@ public class FrozenAspect extends BaseBehaviourBean
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef))
{
// never allow to delete a frozen node
throw new AccessDeniedException("Frozen nodes can not be deleted.");
throw new PermissionDeniedException(I18NUtil.getMessage("rm.hold.delete-frozen-node"));
}
// check children
@@ -121,7 +122,7 @@ public class FrozenAspect extends BaseBehaviourBean
if (freezeService.isFrozen(nodeRef))
{
// never allow to delete a node with a frozen child
throw new AccessDeniedException("Can not delete node, because it contains a frozen child node.");
throw new PermissionDeniedException(I18NUtil.getMessage("rm.hold.delete-node-frozen-children"));
}
// check children
@@ -214,7 +215,7 @@ public class FrozenAspect extends BaseBehaviourBean
if (nodeService.exists(oldChildAssocRef.getChildRef()) &&
freezeService.isFrozen(oldChildAssocRef.getChildRef()))
{
throw new AccessDeniedException("Frozen nodes can not be moved.");
throw new PermissionDeniedException(I18NUtil.getMessage("rm.hold.move-frozen-node"));
}
return null;
});
@@ -232,14 +233,13 @@ public class FrozenAspect extends BaseBehaviourBean
notificationFrequency = NotificationFrequency.FIRST_EVENT
)
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
{
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
// check to not throw exception when the aspect is being added
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef) &&
!transactionalResourceHelper.getSet("frozen").contains(nodeRef) )
{
throw new AccessDeniedException("Frozen nodes can not be updated.");
throw new PermissionDeniedException(I18NUtil.getMessage("rm.hold.update-frozen-node"));
}
return null;
});

View File

@@ -30,6 +30,7 @@ import org.alfresco.model.ContentModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -72,11 +73,11 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
try
{
fileFolderService.delete(dmDocument);
fail("Expected AccessDeniedException to be thrown");
fail("Expected PermissionDeniedException to be thrown");
}
catch (AccessDeniedException ade)
catch (PermissionDeniedException pde)
{
assertTrue(ade.getMessage().contains("Frozen nodes can not be deleted."));
assertTrue(pde.getMessage().contains("Frozen nodes can not be deleted."));
}
}
});
@@ -130,11 +131,11 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
try
{
fileFolderService.move(dmDocument, dmFolder1, null);
fail("Expected AccessDeniedException to be thrown");
fail("Expected PermissionDeniedException to be thrown");
}
catch (AccessDeniedException ade)
catch (PermissionDeniedException pde)
{
assertTrue(ade.getMessage().contains("Frozen nodes can not be moved."));
assertTrue(pde.getMessage().contains("Frozen nodes can not be moved."));
}
}
});
@@ -164,11 +165,11 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
try
{
nodeService.setProperty(dmDocument, ContentModel.PROP_DESCRIPTION, "description");
fail("Expected AccessDeniedException to be thrown");
fail("Expected PermissionDeniedException to be thrown");
}
catch (AccessDeniedException ade)
catch (PermissionDeniedException pde)
{
assertTrue(ade.getMessage().contains("Frozen nodes can not be updated."));
assertTrue(pde.getMessage().contains("Frozen nodes can not be updated."));
}
}
});
@@ -199,11 +200,11 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
ContentData content = (ContentData) nodeService.getProperty(dmDocument, PROP_CONTENT);
nodeService.setProperty(dmDocument, PROP_CONTENT, ContentData.setMimetype(content,
MimetypeMap.MIMETYPE_TEXT_PLAIN));
fail("Expected AccessDeniedException to be thrown");
fail("Expected PermissionDeniedException to be thrown");
}
catch (AccessDeniedException ade)
catch (PermissionDeniedException pde)
{
assertTrue(ade.getMessage().contains("Frozen nodes can not be updated."));
assertTrue(pde.getMessage().contains("Frozen nodes can not be updated."));
}
}
});

View File

@@ -44,6 +44,7 @@ import org.alfresco.module.org_alfresco_module_rm.freeze.FreezeService;
import org.alfresco.module.org_alfresco_module_rm.util.NodeTypeUtility;
import org.alfresco.module.org_alfresco_module_rm.util.TransactionalResourceHelper;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.rest.framework.core.exceptions.PermissionDeniedException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -166,7 +167,7 @@ public class FrozenAspectUnitTest
/**
* Test before delete throws an error if a node is frozen
*/
@Test(expected = AccessDeniedException.class)
@Test(expected = PermissionDeniedException.class)
public void testBeforeDeleteNodeThrowsExceptionIfNodeFrozen()
{
when(mockFreezeService.isFrozen(content)).thenReturn(true);
@@ -187,7 +188,7 @@ public class FrozenAspectUnitTest
/**
* Test before delete throws an error for a node with frozen children
*/
@Test (expected = AccessDeniedException.class)
@Test (expected = PermissionDeniedException.class)
public void testBeforeDeleteThrowsExceptionForFrozenChild()
{
when(mockChildRef.getChildRef()).thenReturn(child);
@@ -217,31 +218,33 @@ public class FrozenAspectUnitTest
public void testOnAddAspectForContent()
{
when(mockNodeService.getType(record)).thenReturn(ContentModel.TYPE_CONTENT);
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(record), ContentModel.TYPE_CONTENT)).thenReturn(true);
when(mockNodeService.getPrimaryParent(record)).thenReturn(mockParentRef);
when(mockParentRef.getParentRef()).thenReturn(parent);
when(mockNodeService.hasAspect(parent, ASPECT_HELD_CHILDREN)).thenReturn(false);
when(mockNodeService.getType(parent)).thenReturn(ContentModel.TYPE_FOLDER);
when(mockedNodeTypeUtility.instanceOf(mockNodeService.getType(parent), ContentModel.TYPE_FOLDER)).thenReturn(true);
frozenAspect.onAddAspect(record, null);
verify(mockNodeService, times(1)).addAspect(any(NodeRef.class), any(QName.class), anyMap());
}
/**
* Test on move throws an error for a frozen node
* Test before move throws an error for a frozen node
*/
@Test(expected = AccessDeniedException.class)
public void testOnMoveThrowsExceptionForFrozenNode()
@Test(expected = PermissionDeniedException.class)
public void testBeforeMoveThrowsExceptionForFrozenNode()
{
when(mockNewRef.getParentRef()).thenReturn(parent);
when(mockNewRef.getChildRef()).thenReturn(child);
when(mockNodeService.exists(parent)).thenReturn(true);
when(mockOldRef.getParentRef()).thenReturn(parent);
when(mockOldRef.getChildRef()).thenReturn(child);
when(mockNodeService.exists(child)).thenReturn(true);
frozenAspect.onMoveNode(mockOldRef, mockNewRef);
when(mockFreezeService.isFrozen(child)).thenReturn(true);
frozenAspect.beforeMoveNode(mockOldRef, null);
}
/**
* Test update properties throws an error for frozen nodes
*/
@Test(expected = AccessDeniedException.class)
@Test(expected = PermissionDeniedException.class)
public void testUpdatePropertiesThrowsExceptionForFrozenNode()
{
when(mockFreezeService.isFrozen(content)).thenReturn(true);
@@ -249,24 +252,4 @@ public class FrozenAspectUnitTest
when(mockSet.contains("frozen")).thenReturn(false);
frozenAspect.onUpdateProperties(content, null, null);
}
/**
* Test on content update throws an error for frozen nodes
*/
@Test(expected = AccessDeniedException.class)
public void testOnContentUpdateThrowsExceptionForFrozenNode()
{
when(mockFreezeService.isFrozen(content)).thenReturn(true);
frozenAspect.onContentUpdate(content, false);
}
/**
* Test before copy throws an error for frozen node
*/
@Test(expected = AccessDeniedException.class)
public void testBeforeCopyThrowsExceptionForFrozenNode()
{
when(mockFreezeService.isFrozen(content)).thenReturn(true);
frozenAspect.beforeCopy(null, content, null);
}
}