use of com.enonic.xp.node.ApplyNodePermissionsResult in project xp by enonic.
the class ApplyNodePermissionsCommandTest method applyPermissionsWithOverwrite.
private void applyPermissionsWithOverwrite() {
final PrincipalKey user1 = PrincipalKey.ofUser(USK, "user1");
final PrincipalKey user2 = PrincipalKey.ofUser(USK, "user2");
final PrincipalKey group1 = PrincipalKey.ofGroup(USK, "group1");
final AccessControlList permissions = AccessControlList.of(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(READ, WRITE_PERMISSIONS).build(), AccessControlEntry.create().principal(user1).allow(READ, MODIFY).build(), AccessControlEntry.create().principal(group1).allow(READ, CREATE, DELETE, MODIFY).build());
CreateRootNodeCommand.create().params(CreateRootNodeParams.create().permissions(AccessControlList.create().add(AccessControlEntry.create().principal(TEST_DEFAULT_USER.getKey()).allowAll().build()).build()).build()).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
final Node topNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(permissions).inheritPermissions(false).build());
final Node child1_1 = createNode(CreateNodeParams.create().name("child1_1").parent(topNode.path()).build());
final Node child1_2 = createNode(CreateNodeParams.create().name("child1_2").parent(topNode.path()).build());
final AccessControlList child1_1_1Permissions = AccessControlList.of(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(READ, WRITE_PERMISSIONS).build(), AccessControlEntry.create().principal(user1).allow(READ, MODIFY).build(), AccessControlEntry.create().principal(user2).allow(READ, CREATE, DELETE, MODIFY, PUBLISH).build());
final Node child1_1_1 = createNode(CreateNodeParams.create().name("child1_1_1").parent(child1_1.path()).permissions(child1_1_1Permissions).inheritPermissions(false).build());
final Node child1_2_1 = createNode(CreateNodeParams.create().name("child1_2_1").parent(child1_2.path()).build());
final Node child1_2_2 = createNode(CreateNodeParams.create().name("child1_2_2").parent(child1_2.path()).build());
refresh();
final ApplyNodePermissionsParams params = ApplyNodePermissionsParams.create().nodeId(topNode.id()).permissions(topNode.getPermissions()).overwriteChildPermissions(true).applyPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
final ApplyNodePermissionsResult updateNodes = ApplyNodePermissionsCommand.create().params(params).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
refresh();
assertEquals(6, updateNodes.getSucceedNodes().getSize());
final Node topNodeUpdated = getNodeById(topNode.id());
assertEquals(permissions, topNodeUpdated.getPermissions());
final Node child1_1Updated = getNodeById(child1_1.id());
assertEquals(permissions, child1_1Updated.getPermissions());
assertVersions(child1_1Updated);
assertTrue(child1_1.getTimestamp().isBefore(child1_1_1.getTimestamp()));
final Node child1_2Updated = getNodeById(child1_2.id());
assertEquals(permissions, child1_2Updated.getPermissions());
final Node child1_1_1Updated = getNodeById(child1_1_1.id());
assertEquals(permissions, child1_1_1Updated.getPermissions());
final Node child1_2_1Updated = getNodeById(child1_2_1.id());
assertEquals(permissions, child1_2_1Updated.getPermissions());
final Node child1_2_2Updated = getNodeById(child1_2_2.id());
assertEquals(permissions, child1_2_2Updated.getPermissions());
}
use of com.enonic.xp.node.ApplyNodePermissionsResult in project xp by enonic.
the class ApplyNodePermissionsCommandTest method applyPermissionsWithMerge.
private void applyPermissionsWithMerge() {
final PrincipalKey user1 = PrincipalKey.ofUser(USK, "user1");
final PrincipalKey user2 = PrincipalKey.ofUser(USK, "user2");
final PrincipalKey group1 = PrincipalKey.ofGroup(USK, "group1");
final AccessControlList permissions = AccessControlList.of(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(READ, WRITE_PERMISSIONS).build(), AccessControlEntry.create().principal(user1).allow(READ, MODIFY).build(), AccessControlEntry.create().principal(group1).allow(READ, CREATE, DELETE, MODIFY).build());
final AccessControlList initialChildPermissions = AccessControlList.of(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(READ).build());
final Node topNode = createNode(CreateNodeParams.create().name("my-node").parent(NodePath.ROOT).permissions(permissions).inheritPermissions(false).build());
final Node child1_1 = createNode(CreateNodeParams.create().name("child1_1").parent(topNode.path()).permissions(initialChildPermissions).inheritPermissions(true).build());
final Node child1_2 = createNode(CreateNodeParams.create().name("child1_2").parent(topNode.path()).permissions(initialChildPermissions).inheritPermissions(true).build());
final AccessControlList child1_1_1Permissions = AccessControlList.of(AccessControlEntry.create().principal(PrincipalKey.ofAnonymous()).allow(READ, WRITE_PERMISSIONS).build(), AccessControlEntry.create().principal(user1).allow(READ, MODIFY, DELETE).build(), AccessControlEntry.create().principal(user2).allow(READ, CREATE, DELETE, MODIFY, PUBLISH).build());
final Node child1_1_1 = createNode(CreateNodeParams.create().name("child1_1_1").parent(child1_1.path()).permissions(child1_1_1Permissions).inheritPermissions(false).build());
final Node child1_2_1 = createNode(CreateNodeParams.create().name("child1_2_1").parent(child1_2.path()).permissions(initialChildPermissions).inheritPermissions(true).build());
final Node child1_2_2 = createNode(CreateNodeParams.create().name("child1_2_2").parent(child1_2.path()).permissions(initialChildPermissions).inheritPermissions(true).build());
refresh();
final ApplyNodePermissionsParams params = ApplyNodePermissionsParams.create().nodeId(topNode.id()).overwriteChildPermissions(false).permissions(topNode.getPermissions()).applyPermissionsListener(Mockito.mock(ApplyPermissionsListener.class)).build();
final ApplyNodePermissionsResult updatedNodes = ApplyNodePermissionsCommand.create().params(params).indexServiceInternal(this.indexServiceInternal).storageService(this.storageService).searchService(this.searchService).build().execute();
refresh();
assertEquals(6, updatedNodes.getSucceedNodes().getSize());
final Node topNodeUpdated = getNodeById(topNode.id());
assertEquals(permissions, topNodeUpdated.getPermissions());
final Node child1_1Updated = getNodeById(child1_1.id());
assertEquals(permissions, child1_1Updated.getPermissions());
final Node child1_2Updated = getNodeById(child1_2.id());
assertEquals(permissions, child1_2Updated.getPermissions());
final Node child1_1_1Updated = getNodeById(child1_1_1.id());
assertEquals("[user:system:anonymous[+read, +write_permissions], " + "group:system:group1[+read, +create, +modify, +delete], " + "user:system:user1[+read, +modify, +delete], " + "user:system:user2[+read, +create, +modify, +delete, +publish]]", child1_1_1Updated.getPermissions().toString());
final Node child1_2_1Updated = getNodeById(child1_2_1.id());
assertEquals(permissions, child1_2_1Updated.getPermissions());
final Node child1_2_2Updated = getNodeById(child1_2_2.id());
assertEquals(permissions, child1_2_2Updated.getPermissions());
}
use of com.enonic.xp.node.ApplyNodePermissionsResult in project xp by enonic.
the class NodeServiceImpl method applyPermissions.
@Override
public ApplyNodePermissionsResult applyPermissions(final ApplyNodePermissionsParams params) {
verifyContext();
final ApplyNodePermissionsResult result = ApplyNodePermissionsCommand.create().params(params).indexServiceInternal(this.indexServiceInternal).searchService(this.nodeSearchService).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute();
for (final Node node : result.getSucceedNodes()) {
this.eventPublisher.publish(NodeEvents.permissionsUpdated(node));
}
return result;
}
use of com.enonic.xp.node.ApplyNodePermissionsResult in project xp by enonic.
the class ApplyContentPermissionsCommand method execute.
ApplyContentPermissionsResult execute() {
final NodeId nodeId = NodeId.from(params.getContentId().toString());
final ApplyNodePermissionsParams applyNodePermissionsParams = ApplyNodePermissionsParams.create().nodeId(nodeId).permissions(params.getPermissions()).inheritPermissions(params.isInheritPermissions()).overwriteChildPermissions(params.isOverwriteChildPermissions()).applyPermissionsListener(params.getListener()).build();
final ApplyNodePermissionsResult result = nodeService.applyPermissions(applyNodePermissionsParams);
return ApplyContentPermissionsResult.create().setSucceedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSucceedNodes().getPaths())).setSkippedContents(ContentNodeHelper.translateNodePathsToContentPaths(result.getSkippedNodes().getPaths())).build();
}
Aggregations