Table of Contents

Getting the function tree by server side code

This guide is only useful if you want to understand the internal permissions mechanism between the Framework and the UserPermissions module or if you want to develop your own permissions module in case you do not use the UserPermissions module.

In Neos Studio, the tree of functions is conceptualized.

On the generated application side, it is necessary to have the same function tree to be able to associate permissions (by role for example).

To do this, in a server method, it is possible to get the function tree with the IFunctionLoader interface :

public class GetFunctionTree : IGetFunctionTree
{
    private readonly IFunctionLoader _functionLoader;

    public GetFunctionTree(IFunctionLoader functionLoader)
    {
        _functionLoader = functionLoader;
    }

    public FunctionTreeNode[] Execute()
    {
        IFunction[] functions = _functionLoader.GetFunctions();

        return functions.Select(MapToFunctionTreeNode);
    }

    private static FunctionTreeNode MapToFunctionTreeNode(IFunction function)
    {
        return new()
        {
            Name = function.Name,
            Caption = function.Caption,
            PermissionType = function.PermissionType,
            Children = function.Children?.Select(MapToFunctionTreeNode).ToArray(),
            AuthorizationCondition = function.AuthorizationCondition,
            Documentation = function.Documentation,
        };
    }
}

The above code retrieves the function tree, converts it to a FunctionTreeNode tree that is a data object and then returns it. The conversion to a data object is necessary to manipulate the objects on the client side.

On the client side

On a UI view, you can add a FunctionTreeNodes field and an Initialized event rule that feeds the field by calling the GetFunctionTree server method :

Fields.FunctionTreeNodes = await ServerMethods.GetFunctionTree.ExecuteAsync();

In the template, you can add a tree view :

<tree-view source="@Fields.FunctionTreeNodes" children-property="Children" node-hover-background="neutral-200" active-node-background="neutral-200" active-node-hover-background="neutral-200">
    <tree-view-node item="Node">
        <text>
            $Node.Caption
        </text>
    </tree-view-node>
</tree-view>