Search in sources :

Example 6 with UpdateNodeParams

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

the class GetActiveNodeVersionsCommandTest method updateNode.

private void updateNode(final Node node, Context context) {
    UpdateNodeParams updateNodeParams = UpdateNodeParams.create().id(node.id()).editor(toBeEdited -> toBeEdited.data.setString("myString", "edit")).build();
    context.runWith(() -> UpdateNodeCommand.create().params(updateNodeParams).indexServiceInternal(this.indexServiceInternal).binaryService(this.binaryService).storageService(this.storageService).searchService(this.searchService).build().execute());
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CreateNodeParams(com.enonic.xp.node.CreateNodeParams) Node(com.enonic.xp.node.Node) NodePath(com.enonic.xp.node.NodePath) Branches(com.enonic.xp.branch.Branches) GetActiveNodeVersionsResult(com.enonic.xp.node.GetActiveNodeVersionsResult) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) NodeVersionMetadata(com.enonic.xp.node.NodeVersionMetadata) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Context(com.enonic.xp.context.Context) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeIds(com.enonic.xp.node.NodeIds) PropertyTree(com.enonic.xp.data.PropertyTree) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 7 with UpdateNodeParams

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

the class SecurityServiceImpl method updateGroup.

@Override
public Group updateGroup(final UpdateGroupParams updateGroupParams) {
    return callWithContext(() -> {
        final Node node = this.nodeService.getByPath(updateGroupParams.getKey().toPath());
        if (node == null) {
            throw new PrincipalNotFoundException(updateGroupParams.getKey());
        }
        final Group existingGroup = PrincipalNodeTranslator.groupFromNode(node);
        final Group groupToUpdate = updateGroupParams.update(existingGroup);
        final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.toUpdateNodeParams(groupToUpdate);
        final Node updatedNode = nodeService.update(updateNodeParams);
        this.nodeService.refresh(RefreshMode.SEARCH);
        return PrincipalNodeTranslator.groupFromNode(updatedNode);
    });
}
Also used : Group(com.enonic.xp.security.Group) Node(com.enonic.xp.node.Node) PrincipalNotFoundException(com.enonic.xp.security.PrincipalNotFoundException) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 8 with UpdateNodeParams

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

the class SecurityServiceImpl method doRemoveRelationships.

private void doRemoveRelationships(final PrincipalKey from) {
    final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.removeAllRelationshipsToUpdateNodeParams(from);
    nodeService.update(updateNodeParams);
}
Also used : UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams)

Example 9 with UpdateNodeParams

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

the class SecurityServiceImpl method updateIdProvider.

@Override
public IdProvider updateIdProvider(final UpdateIdProviderParams updateIdProviderParams) {
    return callWithContext(() -> {
        final NodePath idProviderNodePath = IdProviderNodeTranslator.toIdProviderNodePath(updateIdProviderParams.getKey());
        final Node node = this.nodeService.getByPath(idProviderNodePath);
        if (node == null) {
            return null;
        }
        final IdProvider existingIdProvider = IdProviderNodeTranslator.fromNode(node);
        final IdProvider idProviderToUpdate = updateIdProviderParams.update(existingIdProvider);
        final UpdateNodeParams updateNodeParams = IdProviderNodeTranslator.toUpdateNodeParams(idProviderToUpdate, node.id());
        final Node idProviderNode = nodeService.update(updateNodeParams);
        if (updateIdProviderParams.getIdProviderPermissions() != null) {
            final Node usersNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderUsersNodePath(updateIdProviderParams.getKey()));
            final Node groupsNode = nodeService.getByPath(IdProviderNodeTranslator.toIdProviderGroupsNodePath(updateIdProviderParams.getKey()));
            final IdProviderAccessControlList permissions = updateIdProviderParams.getIdProviderPermissions();
            AccessControlList idProviderNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToIdProviderNodePermissions(permissions);
            AccessControlList usersNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToUsersNodePermissions(permissions);
            AccessControlList groupsNodePermissions = IdProviderNodeTranslator.idProviderPermissionsToGroupsNodePermissions(permissions);
            final Node rootNode = nodeService.getRoot();
            idProviderNodePermissions = mergeWithRootPermissions(idProviderNodePermissions, rootNode.getPermissions());
            usersNodePermissions = mergeWithRootPermissions(usersNodePermissions, rootNode.getPermissions());
            groupsNodePermissions = mergeWithRootPermissions(groupsNodePermissions, rootNode.getPermissions());
            setNodePermissions(idProviderNode.id(), idProviderNodePermissions);
            setNodePermissions(usersNode.id(), usersNodePermissions);
            setNodePermissions(groupsNode.id(), groupsNodePermissions);
            final ApplyNodePermissionsParams applyPermissions = ApplyNodePermissionsParams.create().nodeId(idProviderNode.id()).overwriteChildPermissions(false).build();
            nodeService.applyPermissions(applyPermissions);
        }
        this.nodeService.refresh(RefreshMode.SEARCH);
        return IdProviderNodeTranslator.fromNode(idProviderNode);
    });
}
Also used : AccessControlList(com.enonic.xp.security.acl.AccessControlList) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) ApplyNodePermissionsParams(com.enonic.xp.node.ApplyNodePermissionsParams) Node(com.enonic.xp.node.Node) IdProvider(com.enonic.xp.security.IdProvider) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) IdProviderAccessControlList(com.enonic.xp.security.acl.IdProviderAccessControlList) NodePath(com.enonic.xp.node.NodePath)

Example 10 with UpdateNodeParams

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

the class SecurityServiceImpl method doRemoveMemberships.

private void doRemoveMemberships(final PrincipalKey member) {
    final PrincipalKeys memberships = queryDirectMemberships(member);
    if (memberships.isEmpty()) {
        return;
    }
    for (PrincipalKey from : memberships) {
        final PrincipalRelationship relationship = PrincipalRelationship.from(from).to(member);
        final UpdateNodeParams updateNodeParams = PrincipalNodeTranslator.removeRelationshipToUpdateNodeParams(relationship);
        nodeService.update(updateNodeParams);
    }
}
Also used : PrincipalKeys(com.enonic.xp.security.PrincipalKeys) PrincipalRelationship(com.enonic.xp.security.PrincipalRelationship) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) PrincipalKey(com.enonic.xp.security.PrincipalKey)

Aggregations

UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)31 Node (com.enonic.xp.node.Node)24 PropertyTree (com.enonic.xp.data.PropertyTree)13 CreateNodeParams (com.enonic.xp.node.CreateNodeParams)11 Test (org.junit.jupiter.api.Test)11 BinaryReference (com.enonic.xp.util.BinaryReference)10 NodePath (com.enonic.xp.node.NodePath)8 ByteSource (com.google.common.io.ByteSource)6 NodeIds (com.enonic.xp.node.NodeIds)4 User (com.enonic.xp.security.User)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Content (com.enonic.xp.content.Content)3 Context (com.enonic.xp.context.Context)3 NodeBinaryReferenceException (com.enonic.xp.node.NodeBinaryReferenceException)3 NodeId (com.enonic.xp.node.NodeId)3 NodeNotFoundException (com.enonic.xp.node.NodeNotFoundException)3 PrincipalKey (com.enonic.xp.security.PrincipalKey)3 PrincipalNotFoundException (com.enonic.xp.security.PrincipalNotFoundException)3