I have created a custom section that I would like display only the nodes that are available to the backend user who is currently logged in.
(Basically, what I want is the nodes shown to a given backend user in the content section.)
I have implemented GetTreeNodes of my TreeController like this:
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection();
var rootNodeId = Constants.System.Root.ToInvariantString();
//check if we’re rendering the root node’s children
if (id == rootNodeId)
{
foreach (var node in Umbraco.ContentAtRoot().ToList())
{
var permissions = helper.GetCurrentUmbracoUser().GetPermissions(node.Path);
if (permissions == "-") continue;
var treeNode = CreateTreeNode(node.Id.ToString(), rootNodeId, queryStrings, node.Name, "icon-home", false);
nodes.Add(treeNode);
}
}
return nodes;
}
The method works as expected but I was hoping for more robust way to do this.
Pre-v7 code samples show code similar to this:
Umbraco.ContentAtRoot().Where("HasAccess").ToList()
However, they do not appear to work in current versions.
Does someone know of a better way to do the above in V7?
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/69628-filter-treenodecollection-based-on-backend-user-permissions