Search in sources :

Example 11 with NodeAccessException

use of com.enonic.xp.node.NodeAccessException in project xp by enonic.

the class MoveNodeCommandTest method move_without_permissions.

@Test
public void move_without_permissions() throws Exception {
    final Node deleteUngrantedNode = createNode(CreateNodeParams.create().name("mynode").parent(NodePath.ROOT).setNodeId(NodeId.from("mynode")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.MODIFY).build())).build());
    final Node deleteGrantedNode = createNode(CreateNodeParams.create().name("mynode2").parent(NodePath.ROOT).setNodeId(NodeId.from("mynode2")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build())).build());
    final Node createUngrantedNewParent = createNode(CreateNodeParams.create().name("new-parent").parent(NodePath.ROOT).setNodeId(NodeId.from("newparent")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.CREATE).build())).build());
    final Node createGrantedNewParent = createNode(CreateNodeParams.create().name("new-parent2").parent(NodePath.ROOT).setNodeId(NodeId.from("newparent2")).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build())).build());
    // Tests the check of the DELETE right on the moved node
    boolean deleteRightChecked = false;
    try {
        MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteUngrantedNode.id()).newParent(createGrantedNewParent.path()).build().execute();
    } catch (NodeAccessException e) {
        deleteRightChecked = true;
    }
    assertTrue(deleteRightChecked);
    // Tests the check of the CREATE right on the new parent
    boolean createRightChecked = false;
    try {
        MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteGrantedNode.id()).newParent(createUngrantedNewParent.path()).build().execute();
    } catch (NodeAccessException e) {
        createRightChecked = true;
    }
    assertTrue(createRightChecked);
    // Tests the correct behaviour if both rights are granted
    MoveNodeCommand.create().indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).id(deleteGrantedNode.id()).newParent(createGrantedNewParent.path()).build().execute();
    final Node movedNode = getNodeById(deleteGrantedNode.id());
    assertEquals(createGrantedNewParent.path(), movedNode.parentPath());
    assertEquals("mynode2", movedNode.name().toString());
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Aggregations

NodeAccessException (com.enonic.xp.node.NodeAccessException)11 ContentAccessException (com.enonic.xp.content.ContentAccessException)7 Node (com.enonic.xp.node.Node)5 MoveNodeException (com.enonic.xp.node.MoveNodeException)3 ContentAlreadyExistsException (com.enonic.xp.content.ContentAlreadyExistsException)2 NodeAlreadyExistAtPathException (com.enonic.xp.node.NodeAlreadyExistAtPathException)2 Test (org.junit.jupiter.api.Test)2 ArchiveContentException (com.enonic.xp.archive.ArchiveContentException)1 ArchiveContentsResult (com.enonic.xp.archive.ArchiveContentsResult)1 RestoreContentException (com.enonic.xp.archive.RestoreContentException)1 RestoreContentsResult (com.enonic.xp.archive.RestoreContentsResult)1 Content (com.enonic.xp.content.Content)1 CreateContentParams (com.enonic.xp.content.CreateContentParams)1 CreateContentTranslatorParams (com.enonic.xp.content.CreateContentTranslatorParams)1 DeleteContentsResult (com.enonic.xp.content.DeleteContentsResult)1 MoveContentException (com.enonic.xp.content.MoveContentException)1 MoveContentsResult (com.enonic.xp.content.MoveContentsResult)1 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)1 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)1 NodeId (com.enonic.xp.node.NodeId)1