use of org.alfresco.rest.api.model.NodePermissions in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionsPermissionDeniedUser.
/**
* Tests updating permissions on a node that user doesn't have permission for
*
* @throws Exception
*/
private void testUpdatePermissionsPermissionDeniedUser() throws Exception {
// create folder with an empty document
String postUrl = createFolder();
String dId = createDocument(postUrl);
// update permissions
Document dUpdate = new Document();
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
setRequestContext(user2);
// "Permission Denied" expected
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 403);
}
use of org.alfresco.rest.api.model.NodePermissions in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionMissingFields.
/**
* Tests updating permissions on a node without providing mandatory
* properties
*
* @throws Exception
*/
private void testUpdatePermissionMissingFields() throws Exception {
// create folder with an empty document
String postUrl = createFolder();
String dId = createDocument(postUrl);
// update permissions
Document dUpdate = new Document();
// Add same permission with different access status
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(null, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Authority Id is expected."
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
locallySetPermissions.clear();
locallySetPermissions.add(new NodePermissions.NodePermission("", PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
locallySetPermissions.clear();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, null, AccessStatus.ALLOWED.toString()));
// "Permission name is expected."
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
locallySetPermissions.clear();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, "", AccessStatus.ALLOWED.toString()));
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
}
use of org.alfresco.rest.api.model.NodePermissions in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionInvalidAuthority.
/**
* Test attempt to set permission with an invalid authority
*
* @throws Exception
*/
private void testUpdatePermissionInvalidAuthority() throws Exception {
// create folder containing an empty document
String postUrl = createFolder();
String dId = createDocument(postUrl);
// update permissions
Document dUpdate = new Document();
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission("NonExistingAuthority", PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Cannot set permissions on this node - unknown authority:
// NonExistingAuthority"
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
}
use of org.alfresco.rest.api.model.NodePermissions in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testRetrieveNodePermissions.
private void testRetrieveNodePermissions() throws Exception {
setRequestContext(user1);
// create folder with an empty document
String postUrl = createFolder();
String docId = createDocument(postUrl);
Map params = new HashMap<>();
params.put("include", "permissions");
// update permissions
Document dUpdate = new Document();
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupB, PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// update node
HttpResponse response = put(URL_NODES, docId, toJsonAsStringNonNull(dUpdate), null, 200);
Document documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check if permission are retrieved if 'include=permissions' is not
// sent in the request
response = getSingle(NodesEntityResource.class, documentResp.getId(), null, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
assertNull("Permissions should not be retrieved unless included!", documentResp.getPermissions());
// Call again with 'include=permissions'
response = getSingle(NodesEntityResource.class, documentResp.getId(), params, 200);
documentResp = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), Document.class);
// Check that all permissions are retrieved
assertNotNull(documentResp.getPermissions());
assertTrue("Locally set permissions were not set properly!", documentResp.getPermissions().getLocallySet().size() == 2);
// Check inherit default true
assertTrue("Inheritance flag was not retrieved!", documentResp.getPermissions().getIsInheritanceEnabled());
// Check inherited permissions (for ROLE_OWNER and user1)
assertNotNull(documentResp.getPermissions().getInherited());
assertTrue(documentResp.getPermissions().getInherited().size() == 2);
assertNotNull(documentResp.getPermissions().getSettable());
assertTrue(documentResp.getPermissions().getSettable().size() == 5);
Set<String> expectedSettable = new HashSet<>(Arrays.asList("Coordinator", "Collaborator", "Contributor", "Consumer", "Editor"));
assertTrue("Incorrect list of settable permissions returned!", documentResp.getPermissions().getSettable().containsAll(expectedSettable));
}
use of org.alfresco.rest.api.model.NodePermissions in project alfresco-remote-api by Alfresco.
the class NodeApiTest method testUpdatePermissionAddDuplicate.
/**
* Test add duplicate permissions
*
* @throws Exception
*/
private void testUpdatePermissionAddDuplicate() throws Exception {
// create folder with an empty document
String postUrl = createFolder();
String dId = createDocument(postUrl);
// update permissions
Document dUpdate = new Document();
// Add same permission with different access status
NodePermissions nodePermissions = new NodePermissions();
List<NodePermissions.NodePermission> locallySetPermissions = new ArrayList<>();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.DENIED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Duplicate node permissions, there is more than one permission with
// the same authority and name!"
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
// Add the same permission with same access status
locallySetPermissions.clear();
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
locallySetPermissions.add(new NodePermissions.NodePermission(groupA, PermissionService.CONSUMER, AccessStatus.ALLOWED.toString()));
nodePermissions.setLocallySet(locallySetPermissions);
dUpdate.setPermissions(nodePermissions);
// "Duplicate node permissions, there is more than one permission with
// the same authority and name!"
put(URL_NODES, dId, toJsonAsStringNonNull(dUpdate), null, 400);
}
Aggregations