Search in sources :

Example 6 with NodeAccessException

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

the class SetRootPermissionsCommand method execute.

public Node execute() {
    final Node rootNode = doGetById(Node.ROOT_UUID);
    if (rootNode == null) {
        throw new NodeAccessException(ContextAccessor.current().getAuthInfo().getUser(), NodePath.ROOT, Permission.READ);
    }
    requireContextUserPermissionOrAdmin(Permission.WRITE_PERMISSIONS, rootNode);
    return StoreNodeCommand.create(this).node(Node.create(rootNode).permissions(this.permissions).inheritPermissions(this.inheritPermissions).timestamp(Instant.now(CLOCK)).build()).build().execute();
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) Node(com.enonic.xp.node.Node)

Example 7 with NodeAccessException

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

the class SetNodeChildOrderCommandTest method order_without_permission.

@Test
public void order_without_permission() throws Exception {
    final Node createUngrantedNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(AccessControlList.of(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().deny(Permission.CREATE).build())).build());
    final Node createGrantedNode = createNode(CreateNodeParams.create().name("my-node2").parent(NodePath.ROOT).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 createRightChecked = false;
    try {
        setChildOrder(createUngrantedNode, ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC)).build());
    } catch (NodeAccessException e) {
        createRightChecked = true;
    }
    assertTrue(createRightChecked);
    // Tests the correct behaviour if the right is granted
    setChildOrder(createGrantedNode, ChildOrder.create().add(FieldOrderExpr.create(NodeIndexPath.MANUAL_ORDER_VALUE, OrderExpr.Direction.ASC)).build());
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 8 with NodeAccessException

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

the class DeleteContentCommand method execute.

DeleteContentsResult execute() {
    params.validate();
    try {
        final DeleteContentsResult deletedContents = doExecute();
        nodeService.refresh(RefreshMode.SEARCH);
        return deletedContents;
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : NodeAccessException(com.enonic.xp.node.NodeAccessException) DeleteContentsResult(com.enonic.xp.content.DeleteContentsResult) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 9 with NodeAccessException

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

the class CreateContentCommand method doExecute.

private Content doExecute() {
    final ContentType contentType = contentTypeService.getByName(new GetContentTypeParams().contentTypeName(params.getType()));
    validateContentType(contentType);
    formDefaultValuesProcessor.setDefaultValues(contentType.getForm(), params.getData());
    // TODO apply default values to xData
    CreateContentParams processedParams = runContentProcessors(this.params, contentType);
    validateBlockingChecks(processedParams);
    final CreateContentTranslatorParams createContentTranslatorParams = createContentTranslatorParams(processedParams);
    final CreateNodeParams createNodeParams = CreateNodeParamsFactory.create(createContentTranslatorParams).contentTypeService(this.contentTypeService).pageDescriptorService(this.pageDescriptorService).xDataService(this.xDataService).partDescriptorService(this.partDescriptorService).layoutDescriptorService(this.layoutDescriptorService).contentDataSerializer(this.contentDataSerializer).siteService(this.siteService).build().produce();
    try {
        final Node createdNode = nodeService.create(createNodeParams);
        if (params.isRefresh()) {
            nodeService.refresh(RefreshMode.SEARCH);
        }
        return translator.fromNode(createdNode, false);
    } catch (NodeAlreadyExistAtPathException e) {
        throw new ContentAlreadyExistsException(ContentPath.from(createContentTranslatorParams.getParent(), createContentTranslatorParams.getName().toString()), e.getRepositoryId(), e.getBranch());
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : GetContentTypeParams(com.enonic.xp.schema.content.GetContentTypeParams) NodeAccessException(com.enonic.xp.node.NodeAccessException) ContentType(com.enonic.xp.schema.content.ContentType) CreateContentTranslatorParams(com.enonic.xp.content.CreateContentTranslatorParams) CreateContentParams(com.enonic.xp.content.CreateContentParams) Node(com.enonic.xp.node.Node) ContentAlreadyExistsException(com.enonic.xp.content.ContentAlreadyExistsException) NodeAlreadyExistAtPathException(com.enonic.xp.node.NodeAlreadyExistAtPathException) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) ContentAccessException(com.enonic.xp.content.ContentAccessException)

Example 10 with NodeAccessException

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

the class RestoreContentCommand method execute.

RestoreContentsResult execute() {
    params.validate();
    try {
        final RestoreContentsResult restoredContents = doExecute();
        this.nodeService.refresh(RefreshMode.ALL);
        return restoredContents;
    } catch (MoveNodeException e) {
        throw new RestoreContentException(e.getMessage(), ContentNodeHelper.translateNodePathToContentPath(e.getPath()));
    } catch (NodeAccessException e) {
        throw new ContentAccessException(e);
    }
}
Also used : RestoreContentsResult(com.enonic.xp.archive.RestoreContentsResult) MoveNodeException(com.enonic.xp.node.MoveNodeException) NodeAccessException(com.enonic.xp.node.NodeAccessException) RestoreContentException(com.enonic.xp.archive.RestoreContentException) ContentAccessException(com.enonic.xp.content.ContentAccessException)

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