How can one hook up to the AfterNodeRender in Umbraco 7?
I see the "old" way of doing this is through BaseTree.AfterNodeRender not possible anymore, and I can't find any documentation that confirms the deprecation of it, nor describes the new way of doing this.
It was a handy feature for hiding nodes from a given group of users, as the user control panel can't handle this.
In Umbraco 7 everything works with AngularJS so it works completly different. I'm not sure, but I don't think that BaseTree.AfterNodeRender is used anymore. There might not be an alternative yet. There are other topics with the same question, but no answer yet.
Dave, I'm building a multisite solution (~2000 sites) with more than a thousand backend editors. Each editor should only see a few ( < 5 ) of the sites.
If I give each editor a "Start Node in Content", which would be the front page of each site, they won't be able to browse nor edit the front page.
I can't set explicit Browse access for each editor, for each site (too many sites & editors); so I thought hooking up to the tree in stead would a better solution. Maybe looking into the way the "Start Node in Content" works could be an option...
Thanks guys. It looks like I need the Microsoft.AspNet.WebApi.WebHost package (got it from nuget) to get this code to work; but it screws up the backend in my Umbraco 7.1.6. I'm totally out of luck with this one.
Right, here we go - I finally got the time to modify Jeroens code. The following will hide all nodes that do not have the Browse permission set explicitly. Do not install the webhost package from nuget; in stead, make sure you have included a reference to System.Net.Http.Formatting.
publicclassMyApiHandler : System.Net.Http.DelegatingHandler
{
protectedoverrideTask<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var user = UmbracoContext.Current.Security.CurrentUser;
// If current user is not adminif (user != null && user.Name != "admin")
{
// Catch content tree load eventsswitch (request.RequestUri.AbsolutePath.ToLower())
{
case"/umbraco/backoffice/umbracotrees/applicationtree/getapplicationtrees":
return FilterAllowedNodes(request, cancellationToken, user);
case"/umbraco/backoffice/umbracotrees/contenttree/getnodes":
return FilterAllowedChildren(request, cancellationToken, user);
default:
returnbase.SendAsync(request, cancellationToken);
}
}
returnbase.SendAsync(request, cancellationToken);
}
privateTask<HttpResponseMessage> FilterAllowedNodes(HttpRequestMessage request, CancellationToken cancellationToken, Umbraco.Core.Models.Membership.IUser user)
{
returnbase.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
var response = task.Result;
try
{
var data = response.Content;
var parent = (SectionRootNode)((ObjectContent<SectionRootNode>)(data)).Value;
foreach (var node in parent.Children)
{
var nodeId = Convert.ToInt32(node.Id);
if (nodeId != -1)
{
var cmsNode = newCMSNode(Convert.ToInt32(nodeId));
var permissions = umbraco.BusinessLogic.Permission.GetNodePermissions(cmsNode);
// Check browse permissionif (!permissions.Where(p => p.PermissionId == 'F').Any())
{
node.CssClasses.Add("hide");
}
}
}
}
catch (Exception ex)
{
// Log
}
return response;
});
}
privateTask<HttpResponseMessage> FilterAllowedChildren(HttpRequestMessage request, CancellationToken cancellationToken, Umbraco.Core.Models.Membership.IUser user)
{
returnbase.SendAsync(request, cancellationToken)
.ContinueWith(task =>
{
var response = task.Result;
try
{
var data = response.Content;
var nodes = ((ObjectContent)(data)).Value asList<TreeNode>;
// Check if we're at the root - if we are do not show siblings when reloading the treevar firstNodeParentId = Convert.ToInt32(nodes.FirstOrDefault().ParentId);
if (firstNodeParentId == NodeHelper.RootNodeId)
{
foreach (var node in nodes)
{
var cmsNode = newCMSNode(Convert.ToInt32(node.Id));
var permissions = umbraco.BusinessLogic.Permission.GetNodePermissions(cmsNode);
// Check browse permissionif (!permissions.Where(p => p.PermissionId == 'F').Any())
{
node.CssClasses.Add("hide");
}
}
}
}
catch (Exception ex)
{
// Log
}
return response;
});
BaseTree.AfterNodeRender deprecated?
How can one hook up to the AfterNodeRender in Umbraco 7?
I see the "old" way of doing this is through BaseTree.AfterNodeRender not possible anymore, and I can't find any documentation that confirms the deprecation of it, nor describes the new way of doing this.
It was a handy feature for hiding nodes from a given group of users, as the user control panel can't handle this.
Hello,
In Umbraco 7 everything works with AngularJS so it works completly different. I'm not sure, but I don't think that BaseTree.AfterNodeRender is used anymore. There might not be an alternative yet. There are other topics with the same question, but no answer yet.
Jeroen
What are you trying to achieve with this method. Maybe there is a way to achieve this in the V7 way.
Dave
Thanks Jeroen!
Dave, I'm building a multisite solution (~2000 sites) with more than a thousand backend editors. Each editor should only see a few ( < 5 ) of the sites.
If I give each editor a "Start Node in Content", which would be the front page of each site, they won't be able to browse nor edit the front page.
I can't set explicit Browse access for each editor, for each site (too many sites & editors); so I thought hooking up to the tree in stead would a better solution. Maybe looking into the way the "Start Node in Content" works could be an option...
There might an event where you can change the tree nodes which are returned. See an example in here: http://issues.umbraco.org/issue/U4-2670#comment=67-15418
Jeroen
Jeroen has a piece of code that handles setting the start node of the media picker. Maybe you can do something similar :
https://github.com/jbreuer/Hybrid-Framework-for-Umbraco-v7-Best-Practises/blob/master/Umbraco.Extensions/Utilities/WebApiHandler.cs
jeroen can explain this better than me :-)
Dave
Thanks guys. It looks like I need the Microsoft.AspNet.WebApi.WebHost package (got it from nuget) to get this code to work; but it screws up the backend in my Umbraco 7.1.6. I'm totally out of luck with this one.
Right, here we go - I finally got the time to modify Jeroens code. The following will hide all nodes that do not have the Browse permission set explicitly. Do not install the webhost package from nuget; in stead, make sure you have included a reference to System.Net.Http.Formatting.
}
is working on a reply...