mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
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/BRANCHES/DEV/5.2.N/root@129791 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -2996,18 +2996,7 @@ public class NodesImpl implements Nodes
|
||||
unlockInfo.setAllowCheckedOut(false);
|
||||
}
|
||||
|
||||
// If there is no lock placed on the node skip the operation.
|
||||
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);
|
||||
}
|
||||
|
||||
|
@@ -3628,9 +3628,13 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
// Empty lock body, the default values are used
|
||||
post(getNodeOperationUrl(folderId, "lock"), EMPTY_BODY, null, 200);
|
||||
|
||||
// Test delete on a folder which contains a locked node - NodeLockedException
|
||||
deleteNode(folderId, true, HttpStatus.SC_CONFLICT);
|
||||
// Lock on already locked node
|
||||
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);
|
||||
|
||||
// Test lock children
|
||||
@@ -3643,23 +3647,6 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
createTextFile(folderAId, "content" + RUNID + "_A1", "A1 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.setIncludeChildren(true);
|
||||
lockInfo.setTimeToExpire(60);
|
||||
@@ -3670,15 +3657,9 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
||||
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");
|
||||
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.
|
||||
for (Node child : nodes)
|
||||
{
|
||||
@@ -3820,11 +3801,57 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
setRequestContext(networkAdmin);
|
||||
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);
|
||||
// -ve
|
||||
// Missing target node
|
||||
post(getNodeOperationUrl("fakeId", "unlock"), EMPTY_BODY, null, 404);
|
||||
|
||||
post(getNodeOperationUrl(folderId, "unlock"), EMPTY_BODY, null, 200);
|
||||
// Unlock by a user without permission
|
||||
lock(d1Id, EMPTY_BODY);
|
||||
setRequestContext(user2);
|
||||
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
|
||||
setRequestContext(user1);
|
||||
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
|
||||
String folderCId = folderC.getId();
|
||||
lock(folderCId, EMPTY_BODY);
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("includeChildren", "true123");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
|
||||
body = new HashMap<>();
|
||||
body.put("allowCheckedOut", "false123");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
|
||||
body = new HashMap<>();
|
||||
body.put("invalid_property", "true");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
|
||||
// clean up
|
||||
setRequestContext(user1); // all locks were made by user1
|
||||
|
||||
unlockInfo = new UnlockInfo();
|
||||
unlockInfo.setIncludeChildren(true);
|
||||
unlock(d1Id, toJsonAsStringNonNull(unlockInfo));
|
||||
deleteNode(folderId);
|
||||
unlock(folderCId, EMPTY_BODY);
|
||||
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);
|
||||
|
||||
// Test unlock children
|
||||
// create folder
|
||||
@@ -3840,20 +3867,16 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
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));
|
||||
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());
|
||||
|
||||
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");
|
||||
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.
|
||||
// Check children nodes are not locked.
|
||||
for (Node child : nodes)
|
||||
{
|
||||
assertNull(child.getProperties().get("cm:lockType"));
|
||||
@@ -3861,42 +3884,67 @@ public class NodeApiTest extends AbstractSingleNetworkSiteTest
|
||||
assertFalse(child.getIsLocked());
|
||||
}
|
||||
|
||||
// -ve
|
||||
// Missing target node
|
||||
post(getNodeOperationUrl("fakeId", "unlock"), EMPTY_BODY, null, 404);
|
||||
// Lock the folder and children
|
||||
LockInfo lockInfo = new LockInfo();
|
||||
lockInfo.setIncludeChildren(true);
|
||||
|
||||
// Unlock by a user without permission
|
||||
lock(d1Id, EMPTY_BODY);
|
||||
setRequestContext(user2);
|
||||
post(getNodeOperationUrl(d1Id, "unlock"), EMPTY_BODY, null, 403);
|
||||
response = post(getNodeOperationUrl(folderAId, "lock"), toJsonAsStringNonNull(lockInfo), null, 200);
|
||||
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
|
||||
|
||||
// Invalid lock body values
|
||||
setRequestContext(user1);
|
||||
Folder folderC = createFolder(Nodes.PATH_MY, "folder" + RUNID + "_C");
|
||||
String folderCId = folderC.getId();
|
||||
lock(folderCId, EMPTY_BODY);
|
||||
body = new HashMap<>();
|
||||
body.put("includeChildren", "true123");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
assertEquals(folderAId, documentResp.getId());
|
||||
assertNotNull(documentResp.getProperties().get("cm:lockType"));
|
||||
assertNotNull(documentResp.getProperties().get("cm:lockOwner"));
|
||||
assertNull(documentResp.getIsLocked());
|
||||
|
||||
body = new HashMap<>();
|
||||
body.put("allowCheckedOut", "false123");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
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());
|
||||
}
|
||||
|
||||
body = new HashMap<>();
|
||||
body.put("invalid_property", "true");
|
||||
post(getNodeOperationUrl(folderCId, "unlock"), toJsonAsStringNonNull(body), null, 400);
|
||||
|
||||
// clean up
|
||||
setRequestContext(user1); // all locks were made by user1
|
||||
unlockInfo = new UnlockInfo();
|
||||
// Unlock folder and children
|
||||
UnlockInfo unlockInfo = new UnlockInfo();
|
||||
unlockInfo.setIncludeChildren(true);
|
||||
unlock(folderId, toJsonAsStringNonNull(unlockInfo));
|
||||
deleteNode(folderId);
|
||||
unlock(folderAId, toJsonAsStringNonNull(unlockInfo));
|
||||
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);
|
||||
unlock(folderCId, EMPTY_BODY);
|
||||
deleteNode(folderCId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user