Search in sources :

Example 11 with NodePermissions

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);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) ArrayList(java.util.ArrayList) Document(org.alfresco.rest.api.tests.client.data.Document)

Example 12 with NodePermissions

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);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) ArrayList(java.util.ArrayList) Document(org.alfresco.rest.api.tests.client.data.Document)

Example 13 with NodePermissions

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);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) ArrayList(java.util.ArrayList) Document(org.alfresco.rest.api.tests.client.data.Document)

Example 14 with NodePermissions

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));
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) HttpResponse(org.alfresco.rest.api.tests.client.HttpResponse) NodesEntityResource(org.alfresco.rest.api.nodes.NodesEntityResource) Document(org.alfresco.rest.api.tests.client.data.Document) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 15 with NodePermissions

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);
}
Also used : NodePermissions(org.alfresco.rest.api.model.NodePermissions) ArrayList(java.util.ArrayList) Document(org.alfresco.rest.api.tests.client.data.Document)

Aggregations

NodePermissions (org.alfresco.rest.api.model.NodePermissions)15 ArrayList (java.util.ArrayList)13 Document (org.alfresco.rest.api.tests.client.data.Document)12 HttpResponse (org.alfresco.rest.api.tests.client.HttpResponse)7 HashMap (java.util.HashMap)6 NodesEntityResource (org.alfresco.rest.api.nodes.NodesEntityResource)5 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 MimetypeMap (org.alfresco.repo.content.MimetypeMap)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PathInfo (org.alfresco.rest.api.model.PathInfo)2 Folder (org.alfresco.rest.api.tests.client.data.Folder)2 Node (org.alfresco.rest.api.tests.client.data.Node)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)2 QName (org.alfresco.service.namespace.QName)2 Test (org.junit.Test)2 File (java.io.File)1