Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dr. Sugus 26 posts 101 karma points
    Oct 07, 2014 @ 11:56
    Dr. Sugus
    0

    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.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 07, 2014 @ 12:10
    Jeroen Breuer
    0

    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

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 07, 2014 @ 12:23
    Dave Woestenborghs
    0

    What are you trying to achieve with this method. Maybe there is a way to achieve this in the V7 way.

    Dave

  • Dr. Sugus 26 posts 101 karma points
    Oct 07, 2014 @ 12:47
    Dr. Sugus
    0

    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...

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 07, 2014 @ 12:53
    Jeroen Breuer
    100

    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

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Oct 07, 2014 @ 12:54
    Dave Woestenborghs
    1

    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

  • Dr. Sugus 26 posts 101 karma points
    Oct 07, 2014 @ 14:34
    Dr. Sugus
    0

    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.

     

  • Dr. Sugus 26 posts 101 karma points
    Oct 20, 2014 @ 13:52
    Dr. Sugus
    2

    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.

    public class MyApiHandler : System.Net.Http.DelegatingHandler
      {
        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
          var user = UmbracoContext.Current.Security.CurrentUser;
    
          // If current user is not admin
          if (user != null && user.Name != "admin")
          { 
            // Catch content tree load events
            switch (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:
                return base.SendAsync(request, cancellationToken);
            }
          }
    
          return base.SendAsync(request, cancellationToken);
    
        }
    
        private Task<HttpResponseMessage> FilterAllowedNodes(HttpRequestMessage request, CancellationToken cancellationToken, Umbraco.Core.Models.Membership.IUser user)
        {
          return base.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 = new CMSNode(Convert.ToInt32(nodeId));
                          var permissions = umbraco.BusinessLogic.Permission.GetNodePermissions(cmsNode);
    
                          // Check browse permission
                          if (!permissions.Where(p => p.PermissionId == 'F').Any())
                          {
                            node.CssClasses.Add("hide");
                          }
                        }
                      }
    
                    }
                    catch (Exception ex)
                    {
                      // Log
                    }
    
                    return response;
                  });
        }
    
        private Task<HttpResponseMessage> FilterAllowedChildren(HttpRequestMessage request, CancellationToken cancellationToken, Umbraco.Core.Models.Membership.IUser user)
        {
          return base.SendAsync(request, cancellationToken)
                  .ContinueWith(task =>
                  {
                    var response = task.Result;
                    try
                    {
                      var data = response.Content;
                      var nodes = ((ObjectContent)(data)).Value as List<TreeNode>;
    
                      // Check if we're at the root - if we are do not show siblings when reloading the tree
                      var firstNodeParentId = Convert.ToInt32(nodes.FirstOrDefault().ParentId);
                      if (firstNodeParentId == NodeHelper.RootNodeId)
                      {
    
                        foreach (var node in nodes)
                        {
                          var cmsNode = new CMSNode(Convert.ToInt32(node.Id));
                          var permissions = umbraco.BusinessLogic.Permission.GetNodePermissions(cmsNode);
    
                          // Check browse permission
                          if (!permissions.Where(p => p.PermissionId == 'F').Any())
                          {
                            node.CssClasses.Add("hide");
                          }
                        }
    
                      }
    
                    }
                    catch (Exception ex)
                    {
                      // Log
                    }
    
                    return response;
                  }); 

        } 

Please Sign in or register to post replies

Write your reply to:

Draft