mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Throw PermissionDeniedException instead of AccessDeniedException and internationalized the messages.
This commit is contained in:
@@ -2,3 +2,7 @@ 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 \
|
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.
|
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-archived-node=Archived 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.
|
@@ -45,10 +45,11 @@ import org.alfresco.repo.policy.annotation.BehaviourBean;
|
|||||||
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
import org.alfresco.repo.policy.annotation.BehaviourKind;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
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.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.namespace.QName;
|
import org.alfresco.service.namespace.QName;
|
||||||
|
import org.springframework.extensions.surf.util.I18NUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rma:frozen behaviour bean
|
* rma:frozen behaviour bean
|
||||||
@@ -95,7 +96,7 @@ public class FrozenAspect extends BaseBehaviourBean
|
|||||||
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef))
|
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef))
|
||||||
{
|
{
|
||||||
// never allow to delete a frozen node
|
// 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
|
// check children
|
||||||
@@ -121,7 +122,7 @@ public class FrozenAspect extends BaseBehaviourBean
|
|||||||
if (freezeService.isFrozen(nodeRef))
|
if (freezeService.isFrozen(nodeRef))
|
||||||
{
|
{
|
||||||
// never allow to delete a node with a frozen child
|
// 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
|
// check children
|
||||||
@@ -214,7 +215,7 @@ public class FrozenAspect extends BaseBehaviourBean
|
|||||||
if (nodeService.exists(oldChildAssocRef.getChildRef()) &&
|
if (nodeService.exists(oldChildAssocRef.getChildRef()) &&
|
||||||
freezeService.isFrozen(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;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -232,14 +233,13 @@ public class FrozenAspect extends BaseBehaviourBean
|
|||||||
notificationFrequency = NotificationFrequency.FIRST_EVENT
|
notificationFrequency = NotificationFrequency.FIRST_EVENT
|
||||||
)
|
)
|
||||||
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
|
public void onUpdateProperties(NodeRef nodeRef, Map<QName, Serializable> before, Map<QName, Serializable> after)
|
||||||
|
|
||||||
{
|
{
|
||||||
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
|
AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
|
||||||
// check to not throw exception when the aspect is being added
|
// check to not throw exception when the aspect is being added
|
||||||
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef) &&
|
if (nodeService.exists(nodeRef) && freezeService.isFrozen(nodeRef) &&
|
||||||
!transactionalResourceHelper.getSet("frozen").contains(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;
|
return null;
|
||||||
});
|
});
|
||||||
|
@@ -30,6 +30,7 @@ import org.alfresco.model.ContentModel;
|
|||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
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.model.FileNotFoundException;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
@@ -56,7 +57,7 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
*/
|
*/
|
||||||
public void testDeleteHeldDocument()
|
public void testDeleteHeldDocument()
|
||||||
{
|
{
|
||||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
doBehaviourDrivenTest(new BehaviourDrivenTest(PermissionDeniedException.class)
|
||||||
{
|
{
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
@@ -68,16 +69,8 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void when()
|
public void when()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
fileFolderService.delete(dmDocument);
|
fileFolderService.delete(dmDocument);
|
||||||
fail("Expected AccessDeniedException to be thrown");
|
|
||||||
}
|
|
||||||
catch (AccessDeniedException ade)
|
|
||||||
{
|
|
||||||
assertTrue(ade.getMessage().contains("Frozen nodes can not be deleted."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -114,7 +107,7 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
*/
|
*/
|
||||||
public void testMoveHeldDocument()
|
public void testMoveHeldDocument()
|
||||||
{
|
{
|
||||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
doBehaviourDrivenTest(new BehaviourDrivenTest(PermissionDeniedException.class)
|
||||||
{
|
{
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
@@ -126,16 +119,8 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void when() throws FileNotFoundException
|
public void when() throws FileNotFoundException
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
fileFolderService.move(dmDocument, dmFolder1, null);
|
fileFolderService.move(dmDocument, dmFolder1, null);
|
||||||
fail("Expected AccessDeniedException to be thrown");
|
|
||||||
}
|
|
||||||
catch (AccessDeniedException ade)
|
|
||||||
{
|
|
||||||
assertTrue(ade.getMessage().contains("Frozen nodes can not be moved."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -148,7 +133,7 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
*/
|
*/
|
||||||
public void testUpdateHeldDocumentProperties()
|
public void testUpdateHeldDocumentProperties()
|
||||||
{
|
{
|
||||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
doBehaviourDrivenTest(new BehaviourDrivenTest(PermissionDeniedException.class)
|
||||||
{
|
{
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
@@ -160,16 +145,8 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void when()
|
public void when()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
nodeService.setProperty(dmDocument, ContentModel.PROP_DESCRIPTION, "description");
|
nodeService.setProperty(dmDocument, ContentModel.PROP_DESCRIPTION, "description");
|
||||||
fail("Expected AccessDeniedException to be thrown");
|
|
||||||
}
|
|
||||||
catch (AccessDeniedException ade)
|
|
||||||
{
|
|
||||||
assertTrue(ade.getMessage().contains("Frozen nodes can not be updated."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -181,7 +158,7 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
*/
|
*/
|
||||||
public void testUpdateHeldDocumentContent()
|
public void testUpdateHeldDocumentContent()
|
||||||
{
|
{
|
||||||
doBehaviourDrivenTest(new BehaviourDrivenTest()
|
doBehaviourDrivenTest(new BehaviourDrivenTest(PermissionDeniedException.class)
|
||||||
{
|
{
|
||||||
public void given()
|
public void given()
|
||||||
{
|
{
|
||||||
@@ -193,18 +170,10 @@ public class UpdateHeldActiveContentTest extends BaseRMTestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void when()
|
public void when()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
ContentData content = (ContentData) nodeService.getProperty(dmDocument, PROP_CONTENT);
|
ContentData content = (ContentData) nodeService.getProperty(dmDocument, PROP_CONTENT);
|
||||||
nodeService.setProperty(dmDocument, PROP_CONTENT, ContentData.setMimetype(content,
|
nodeService.setProperty(dmDocument, PROP_CONTENT, ContentData.setMimetype(content,
|
||||||
MimetypeMap.MIMETYPE_TEXT_PLAIN));
|
MimetypeMap.MIMETYPE_TEXT_PLAIN));
|
||||||
fail("Expected AccessDeniedException to be thrown");
|
|
||||||
}
|
|
||||||
catch (AccessDeniedException ade)
|
|
||||||
{
|
|
||||||
assertTrue(ade.getMessage().contains("Frozen nodes can not be updated."));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user