Copied to clipboard

Flag this post as spam?

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


  • Taras 30 posts 151 karma points
    Jan 22, 2014 @ 21:28
    Taras
    0

    Show only nodes to which user has Access

    I need to show only nodes to which user  has access.

    Same question is there:

    http://our.umbraco.org/forum/developers/extending-umbraco/4001-Display-only-the-pages-that-members-have-access-to-

    but can I do it in code?

    Example: 

    1) Get root:

        DynamicNode root = new DynamicNode(new Node(-1));

    2) Get all visiable children:

        var menuItems = root.Children.Where(n => n.Visible == true).First().Children.Where(n => n.Visible == true);  

    3) In cycle I want to checking if user has access to node:

    check if the user belongs to the member group to which this page is available.

      @foreach (var item in menuItems)

      {

    if(CHECK)

      }

     

    Is it posible?

     

    Thanks.

  • Funka! 398 posts 661 karma points
    Jan 22, 2014 @ 23:26
    Funka!
    100

    There used to be a property in v4 on the DynamicNode that you could check called HasAccess, which you'd do just like you check IsVisible. Since it looks like this property no longer exists on the IPublishedContent I'm not sure what exactly the recommended practice is now, but I do see after a quick glance at the codebase something on the UmbracoHelper which looks like might do what you want:

    public bool MemberHasAccess(int nodeId, string path);

    So maybe something like if (Umbraco.MemberHasAccess(item.Id, "/whatever/")) { ... } ??? (Not sure why you would need path if you are giving it the node ID...) But hopefully this is enough to get you started and know what further you need to search on/experiment with.

    Good luck!

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 23, 2014 @ 05:47
    Fuji Kusaka
    1

    Hi Taras,

    Yes its possible to do this in umbraco but you will also need to set up some roles under the Member section where you will have to create a Member Group.

    Based on those Group you will give public access to the nodes you want a member to have access to.

    Here is an example of how your razor

    List<DynamicNode> nodes = @Model.AncestorOrSelf(1).Descendants("docType").Where("Visible && HasAccess").ToList;
    @foreach(var n in nodes){
      @n.Name
    }

    Hope this helps

    //Fuji

  • Taras 30 posts 151 karma points
    Jan 23, 2014 @ 13:47
    Taras
    1

    In my case best solution is: 

    if (Umbraco.MemberHasAccess(item.Id, item.Path))

     

    thank you  Funka! & Fuji Kusaka.

  • Balvvant 5 posts 25 karma points
    Mar 13, 2014 @ 05:34
    Balvvant
    0

    Hi Guys, I have a requirement where I would like to do reverse of what you are doing. I need to do a for loop through all memebrs and check which memebers have access to a particular node/document. I tried couple of options but nothing is working. My code block is attached. Can any one guide me through.

    try { string _emailD = string.Empty; string _emailBody = string.Empty; string _docsHit = string.Empty; string _docsDetails = string.Empty; string _memID = string.Empty;

                foreach (var doc in e.PublishedEntities)
                {
                    _docsHit += doc.Id + ",";
                    foreach (Member m in Member.GetAll)
                    {
                        _memID += m.Id + ",";
                        //umbraco.library.HasAccess(doc.Id, doc.Path);
                        //if (Access.HasAccces(doc.Id, m.Id))
                        if (Access.HasAccces(doc.Id, (object) m.Id) == true)
                        {
                            //doc.has
    
                            if (_emailD != string.Empty)
                            {
                                _emailD = _emailD + "; ";
                            }
                            _emailD += m.Email + m.User.GetPermissions(doc.Path) + ";";
                        }
                        {
                            _emailD += " permission not found for: " + m.LoginName + ";";
                        }
                        // m.Text <= name of member
    
                        // m.Email <= Well, you know
    
                        // m.GetProperty("phoneNo").Value.ToString() <= a custom property with the alias of "phoneNo"
    
    
                    }
                    _docsDetails += doc.Id +  doc.Name +  doc.GetType().Name;
                }
    
    
                Log.AddLocally(LogTypes.Save, User.GetUser(100), 100, "user email id's are: "  + _emailD);
    
                Log.AddLocally(LogTypes.Save, User.GetUser(100), 100, "document published are : " +  _docsHit);
    
                Log.AddLocally(LogTypes.Save, User.GetUser(100), 100, "Memebrs are : " + _memID);
    
                Log.AddLocally(LogTypes.Save, User.GetUser(100), 100, "document details are : " + _docsDetails);
    
            }
            catch (Exception ex)
            {
                Log.AddLocally(LogTypes.Save, User.GetUser(100), 100, ex.Message);
            }
    
  • pnr 131 posts 226 karma points
    Jul 02, 2015 @ 05:32
    pnr
    0

    Hi Balvvant

    Did you ever find a solution to your problem? I am having a simular problem right now :-)

Please Sign in or register to post replies

Write your reply to:

Draft