mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
129791 amorarasu: REPO-340 / REPO-1136 - V1 REST API: Unlock Node - Unlock with includeChildren=true - fixed + testcases git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@130231 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2996,18 +2996,7 @@ public class NodesImpl implements Nodes
|
|||||||
unlockInfo.setAllowCheckedOut(false);
|
unlockInfo.setAllowCheckedOut(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no lock placed on the node skip the operation.
|
lockService.unlock(nodeRef, unlockInfo.getIncludeChildren(), unlockInfo.getAllowCheckedOut());
|
||||||
if (lockService.getLockStatus(nodeRef) != LockStatus.NO_LOCK)
|
|
||||||
{
|
|
||||||
if (permissionService.hasPermission(nodeRef, PermissionService.UNLOCK).equals(AccessStatus.ALLOWED))
|
|
||||||
{
|
|
||||||
lockService.unlock(nodeRef, unlockInfo.getIncludeChildren(), unlockInfo.getAllowCheckedOut());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw new PermissionDeniedException("Current user doesn't have permission to unlock node " + nodeId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return getFolderOrDocument(nodeId, parameters);
|
return getFolderOrDocument(nodeId, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -3628,9 +3628,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
// Empty lock body, the default values are used
|
// Empty lock body, the default values are used
|
||||||
post(getNodeOperationUrl(folderId, "lock"), EMPTY_BODY, null, 200);
|
post(getNodeOperationUrl(folderId, "lock"), EMPTY_BODY, null, 200);
|
||||||
|
|
||||||
// Test delete on a folder which contains a locked node - NodeLockedException
|
// Lock on already locked node
|
||||||
deleteNode(folderId, true, HttpStatus.SC_CONFLICT);
|
post(getNodeOperationUrl(folderId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
||||||
|
|
||||||
|
// Test delete on a folder which contains a locked node - NodeLockedException
|
||||||
|
deleteNode(folderId, true, 409);
|
||||||
|
|
||||||
|
// Content update on a locked node
|
||||||
updateTextFile(d1Id, "Updated text", null, 409);
|
updateTextFile(d1Id, "Updated text", null, 409);
|
||||||
|
|
||||||
// Test lock children
|
// Test lock children
|
||||||
@@ -3643,23 +3647,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
createTextFile(folderAId, "content" + RUNID + "_A1", "A1 content");
|
createTextFile(folderAId, "content" + RUNID + "_A1", "A1 content");
|
||||||
createTextFile(folderAId, "content" + RUNID + "_A2", "A2 content");
|
createTextFile(folderAId, "content" + RUNID + "_A2", "A2 content");
|
||||||
|
|
||||||
params = Collections.singletonMap("include", "isLocked");
|
|
||||||
response = getSingle(URL_NODES, folderAId, params, null, 200);
|
|
||||||
node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
|
|
||||||
assertNull(node.getProperties());
|
|
||||||
assertFalse(node.getIsLocked());
|
|
||||||
|
|
||||||
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
|
||||||
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
|
||||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
|
||||||
// check children nodes are not locked.
|
|
||||||
for (Node child : nodes)
|
|
||||||
{
|
|
||||||
assertNull(child.getProperties().get("cm:lockType"));
|
|
||||||
assertNull(child.getProperties().get("cm:lockOwner"));
|
|
||||||
assertFalse(child.getIsLocked());
|
|
||||||
}
|
|
||||||
|
|
||||||
lockInfo = new LockInfo();
|
lockInfo = new LockInfo();
|
||||||
lockInfo.setIncludeChildren(true);
|
lockInfo.setIncludeChildren(true);
|
||||||
lockInfo.setTimeToExpire(60);
|
lockInfo.setTimeToExpire(60);
|
||||||
@@ -3669,16 +3656,10 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
// lock the folder
|
// lock the folder
|
||||||
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
||||||
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||||
|
|
||||||
assertEquals(folderAName, documentResp.getName());
|
|
||||||
assertEquals(folderAId, documentResp.getId());
|
|
||||||
assertNotNull(documentResp.getProperties().get("cm:lockType"));
|
|
||||||
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
|
|
||||||
assertNull(documentResp.getIsLocked());
|
|
||||||
|
|
||||||
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
||||||
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
||||||
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
// test if children nodes are locked as well.
|
// test if children nodes are locked as well.
|
||||||
for (Node child : nodes)
|
for (Node child : nodes)
|
||||||
{
|
{
|
||||||
@@ -3787,7 +3768,7 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
* <p>POST:</p>
|
* <p>POST:</p>
|
||||||
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/unlock}
|
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/unlock}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUnlock() throws Exception
|
public void testUnlock() throws Exception
|
||||||
{
|
{
|
||||||
setRequestContext(user1);
|
setRequestContext(user1);
|
||||||
@@ -3820,47 +3801,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
setRequestContext(networkAdmin);
|
setRequestContext(networkAdmin);
|
||||||
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 200);
|
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 200);
|
||||||
|
|
||||||
setRequestContext(user1);
|
|
||||||
//Unlock on a not locked node should do nothing
|
|
||||||
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 200);
|
|
||||||
|
|
||||||
post(getNodeOperationUrl(folderId, "unlock"), EMPTY_BODY, null, 200);
|
|
||||||
|
|
||||||
// Test unlock children
|
|
||||||
// create folder
|
|
||||||
Folder folderA = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_A");
|
|
||||||
String folderAId = folderA.getId();
|
|
||||||
|
|
||||||
// create 2 files in the folderA
|
|
||||||
String dA1Name = "content" + RUNID + "_A1";
|
|
||||||
Document dA1 = createTextFile(folderAId, dA1Name, "A1 content");
|
|
||||||
String dA1Id = dA1.getId();
|
|
||||||
|
|
||||||
String dA2Name = "content" + RUNID + "_A2";
|
|
||||||
Document dA2 = createTextFile(folderAId, dA2Name, "A2 content");
|
|
||||||
String dA2Id = dA2.getId();
|
|
||||||
|
|
||||||
// lock the folder and children
|
|
||||||
Map<String, String> body = new HashMap<>();
|
|
||||||
body.put("includeChildren", "true");
|
|
||||||
lock(folderAId, toJsonAsStringNonNull(body));
|
|
||||||
|
|
||||||
unlockInfo = new UnlockInfo();
|
|
||||||
unlockInfo.setIncludeChildren(true);
|
|
||||||
unlockInfo.setAllowCheckedOut(true);
|
|
||||||
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
|
|
||||||
|
|
||||||
Map<String, String> params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
|
||||||
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
|
||||||
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
|
||||||
// Test if children nodes are unlocked as well.
|
|
||||||
for (Node child : nodes)
|
|
||||||
{
|
|
||||||
assertNull(child.getProperties().get("cm:lockType"));
|
|
||||||
assertNull(child.getProperties().get("cm:lockOwner"));
|
|
||||||
assertFalse(child.getIsLocked());
|
|
||||||
}
|
|
||||||
|
|
||||||
// -ve
|
// -ve
|
||||||
// Missing target node
|
// Missing target node
|
||||||
post(getNodeOperationUrl("fakeId", "unlock"), EMPTY_BODY, null, 404);
|
post(getNodeOperationUrl("fakeId", "unlock"), EMPTY_BODY, null, 404);
|
||||||
@@ -3870,12 +3810,16 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
setRequestContext(user2);
|
setRequestContext(user2);
|
||||||
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 403);
|
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 403);
|
||||||
|
|
||||||
|
setRequestContext(user1);
|
||||||
|
//Unlock on a not locked node
|
||||||
|
post(getNodeOperationUrl(folderId, "unlock"), EMPTY_BODY, null, 403);
|
||||||
|
|
||||||
// Invalid lock body values
|
// Invalid lock body values
|
||||||
setRequestContext(user1);
|
setRequestContext(user1);
|
||||||
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
|
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
|
||||||
String folderCId = folderC.getId();
|
String folderCId = folderC.getId();
|
||||||
lock(folderCId, EMPTY_BODY);
|
lock(folderCId, EMPTY_BODY);
|
||||||
body = new HashMap<>();
|
Map<String, String> body = new HashMap<>();
|
||||||
body.put("includeChildren", "true123");
|
body.put("includeChildren", "true123");
|
||||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||||
|
|
||||||
@@ -3889,20 +3833,124 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
|||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
setRequestContext(user1); // all locks were made by user1
|
setRequestContext(user1); // all locks were made by user1
|
||||||
|
|
||||||
unlockInfo = new UnlockInfo();
|
unlockInfo = new UnlockInfo();
|
||||||
unlockInfo.setIncludeChildren(true);
|
unlockInfo.setIncludeChildren(true);
|
||||||
unlock(folderId, toJsonAsStringNonNull(unlockInfo));
|
unlock(d1Id, toJsonAsStringNonNull(unlockInfo));
|
||||||
deleteNode(folderId);
|
deleteNode(folderId);
|
||||||
unlock(folderAId, toJsonAsStringNonNull(unlockInfo));
|
|
||||||
deleteNode(folderAId);
|
|
||||||
unlock(folderCId, EMPTY_BODY);
|
unlock(folderCId, EMPTY_BODY);
|
||||||
deleteNode(folderCId);
|
deleteNode(folderCId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests lock and unlock with children
|
||||||
|
* <p>POST:</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/lock}</p>
|
||||||
|
* {@literal <host>:<port>/alfresco/api/-default-/public/alfresco/versions/1/nodes/<nodeId>/unlock}
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testLockUnlockWithChildren() throws Exception
|
||||||
|
{
|
||||||
|
setRequestContext(user1);
|
||||||
|
|
||||||
@Override
|
// Test unlock children
|
||||||
public String getScope()
|
// create folder
|
||||||
{
|
Folder folderA = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_A");
|
||||||
return "public";
|
String folderAId = folderA.getId();
|
||||||
}
|
|
||||||
|
// create 2 files in the folderA
|
||||||
|
String dA1Name = "content" + RUNID + "_A1";
|
||||||
|
Document dA1 = createTextFile(folderAId, dA1Name, "A1 content");
|
||||||
|
String dA1Id = dA1.getId();
|
||||||
|
|
||||||
|
String dA2Name = "content" + RUNID + "_A2";
|
||||||
|
Document dA2 = createTextFile(folderAId, dA2Name, "A2 content");
|
||||||
|
String dA2Id = dA2.getId();
|
||||||
|
|
||||||
|
Map<String, String> params = Collections.singletonMap("include", "isLocked");
|
||||||
|
HttpResponse response = getSingle(URL_NODES, folderAId, params, null, 200);
|
||||||
|
Node node = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Node.class);
|
||||||
|
assertNull(node.getProperties());
|
||||||
|
assertFalse(node.getIsLocked());
|
||||||
|
|
||||||
|
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
||||||
|
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
||||||
|
List<Node> nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
// Check children nodes are not locked.
|
||||||
|
for (Node child : nodes)
|
||||||
|
{
|
||||||
|
assertNull(child.getProperties().get("cm:lockType"));
|
||||||
|
assertNull(child.getProperties().get("cm:lockOwner"));
|
||||||
|
assertFalse(child.getIsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Lock the folder and children
|
||||||
|
LockInfo lockInfo = new LockInfo();
|
||||||
|
lockInfo.setIncludeChildren(true);
|
||||||
|
|
||||||
|
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
||||||
|
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||||
|
|
||||||
|
assertEquals(folderAId, documentResp.getId());
|
||||||
|
assertNotNull(documentResp.getProperties().get("cm:lockType"));
|
||||||
|
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
|
||||||
|
assertNull(documentResp.getIsLocked());
|
||||||
|
|
||||||
|
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
||||||
|
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
// Check if children nodes are locked as well.
|
||||||
|
for (Node child : nodes)
|
||||||
|
{
|
||||||
|
assertNotNull(child.getProperties().get("cm:lockType"));
|
||||||
|
assertNotNull(child.getProperties().get("cm:lockOwner"));
|
||||||
|
assertTrue(child.getIsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock folder and children
|
||||||
|
UnlockInfo unlockInfo = new UnlockInfo();
|
||||||
|
unlockInfo.setIncludeChildren(true);
|
||||||
|
unlockInfo.setAllowCheckedOut(true);
|
||||||
|
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
|
||||||
|
|
||||||
|
params = Collections.singletonMap("include", "aspectNames,properties,isLocked");
|
||||||
|
response = getAll(getNodeChildrenUrl(folderAId), null, params, 200);
|
||||||
|
nodes = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), Node.class);
|
||||||
|
// Check if children nodes are unlocked as well.
|
||||||
|
for (Node child : nodes)
|
||||||
|
{
|
||||||
|
assertNull(child.getProperties().get("cm:lockType"));
|
||||||
|
assertNull(child.getProperties().get("cm:lockOwner"));
|
||||||
|
assertFalse(child.getIsLocked());
|
||||||
|
}
|
||||||
|
|
||||||
|
// One of the children is not locked
|
||||||
|
// FolderA locked
|
||||||
|
// - dA1 locked
|
||||||
|
// - dA2 unlocked
|
||||||
|
lock(folderAId, EMPTY_BODY);
|
||||||
|
lock(dA1Id, EMPTY_BODY);
|
||||||
|
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 200);
|
||||||
|
|
||||||
|
// Parent unlocked, children locked
|
||||||
|
// FolderA unlocked
|
||||||
|
// - dA1 locked
|
||||||
|
// - dA2 locked
|
||||||
|
lock(dA2Id, EMPTY_BODY);
|
||||||
|
lock(dA1Id, EMPTY_BODY);
|
||||||
|
// Unlock on not locked parent
|
||||||
|
post(getNodeOperationUrl(folderAId, "unlock"), toJsonAsStringNonNull(unlockInfo), null, 403);
|
||||||
|
|
||||||
|
// Clean up
|
||||||
|
unlock(dA1Id, EMPTY_BODY);
|
||||||
|
unlock(dA2Id, EMPTY_BODY);
|
||||||
|
deleteNode(folderAId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getScope()
|
||||||
|
{
|
||||||
|
return "public";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user