From d17fef60dcd29ef173986804f1e41f686672abe1 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Thu, 10 Nov 2016 17:00:11 +0000 Subject: [PATCH] Merged 5.2.N (5.2.1) to HEAD (5.2) 132551 rneamtu: SHA-1875 : Link cannot be deleted if the original node is locked - Removed aspect Lockable when the links are deleted - In case of the user try to create links for locked or checked out nodes, throw an error - Disabled audit when add marker aspect Linked - Added tests for case git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@132676 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/scripts/node/NodeWebScripTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/source/test-java/org/alfresco/repo/web/scripts/node/NodeWebScripTest.java b/source/test-java/org/alfresco/repo/web/scripts/node/NodeWebScripTest.java index 68b58a2cd3..3a9b0e3050 100644 --- a/source/test-java/org/alfresco/repo/web/scripts/node/NodeWebScripTest.java +++ b/source/test-java/org/alfresco/repo/web/scripts/node/NodeWebScripTest.java @@ -636,6 +636,77 @@ public class NodeWebScripTest extends BaseWebScriptTest assertEquals(false, nodeService.hasAspect(testFile4, ApplicationModel.ASPECT_LINKED)); AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE); + + //you should not be able to create links for locked nodes but you can delete links + final NodeRef testFile5 = createNode(testFolder1, "testingLinkCreationFileWithLock", ContentModel.TYPE_CONTENT, + AuthenticationUtil.getAdminUserName()); + + req = new Request("POST", CREATE_LINK_API + testFile5.getStoreRef().getProtocol() + "/" + + testFile5.getStoreRef().getIdentifier() + "/" + testFile5.getId()); + jsonReq = new JSONObject(); + jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString()); + + jsonArray = new JSONArray(); + jsonArray.add(testFile5.toString()); + jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray); + req.setBody(jsonReq.toString().getBytes()); + req.setType(MimetypeMap.MIMETYPE_JSON); + + json = asJSON(sendRequest(req, Status.STATUS_OK)); + jsonLinkNodes = (JSONArray) json.get("linkNodes"); + assertNotNull(jsonLinkNodes); + assertEquals(1, jsonLinkNodes.size()); + assertEquals("true", json.get("overallSuccess")); + assertEquals("1", json.get("successCount")); + assertEquals("0", json.get("failureCount")); + + jsonLinkNode = (JSONObject) jsonLinkNodes.get(0); + nodeRef = (String) jsonLinkNode.get("nodeRef"); + NodeRef file5Link = new NodeRef(nodeRef); + + assertEquals(true, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED)); + assertEquals(true, nodeService.exists(file5Link)); + + //checkout the node testFile5 + final NodeRef workingCopy = retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public NodeRef execute() throws Exception + { + return checkOutCheckInService.checkout(testFile5); + } + }); + assertNotNull(workingCopy); + + //try to create link for working copy + req = new Request("POST", CREATE_LINK_API + workingCopy.getStoreRef().getProtocol() + "/" + + workingCopy.getStoreRef().getIdentifier() + "/" + workingCopy.getId()); + jsonReq = new JSONObject(); + jsonReq.put(DESTINATION_NODE_REF_PARAM, testFolder1.toString()); + + jsonArray = new JSONArray(); + jsonArray.add(workingCopy.toString()); + jsonReq.put(MULTIPLE_FILES_PARAM, jsonArray); + req.setBody(jsonReq.toString().getBytes()); + req.setType(MimetypeMap.MIMETYPE_JSON); + + //should fail since source node is working copy + json = asJSON(sendRequest(req, Status.STATUS_BAD_REQUEST)); + + //delete the link when source node is locked + nodeService.deleteNode(file5Link); + assertEquals(false, nodeService.hasAspect(testFile5, ApplicationModel.ASPECT_LINKED)); + + //release the lock + retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback() + { + public Object execute() throws Exception + { + checkOutCheckInService.checkin(workingCopy, new HashMap()); + return null; + } + }); + + assertEquals(false, nodeService.hasAspect(testFile5, ContentModel.ASPECT_LOCKABLE)); } private NodeRef createNode(NodeRef parentNode, String nodeCmName, QName nodeType, String ownerUserName)