Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 25, 2012 @ 13:18
    Fuji Kusaka
    0

    List of Protected and Has:Access to

    Hi everyone,

    I have a list of nodes, some of which are public and others are private where admin will give access to it.  My question is how do i get to display those list. Both list should be available when user is login.

    So when am on a particular node i will display the subpages where some are private/some public.

    The issue here is when am not LoggedIn am getting both Private/Public

    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.cms.businesslogic.member
    @using System.Web.Security
    @{
      var parent = Model.AncestorOrSelf(2);    
    var currentUser = Member.GetCurrentMember();
        
      if(parent !=null){        
             <ul>
                  @foreach(var item in parent.Children.Where("Visible")){
                  
                                 if(currentUser !=null || item.HasAccess()){
                                           <li>@item.Name - Private user</li> 
                                  }                              
                                   else{
                                     <li><a href="@item.Url">@item.Name - Public user</a></li>
                                  }    
                    }
              </ul>  
                        
           }
    }

  • Ian Robinson 79 posts 143 karma points
    Sep 25, 2012 @ 14:05
    Ian Robinson
    0

    That looks correct to me.  I would have thought it would work for you.

    Have you tried outputting the currentUser and item.HasAccess() property to check what they are returning?

    e.g.

     <li>user - @currentUser, has access - @item.HasAccess()</li> 
    
  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 25, 2012 @ 14:12
    Fuji Kusaka
    0

    Yes i did everything turns out to be True! 

  • Ian Robinson 79 posts 143 karma points
    Sep 25, 2012 @ 14:22
    Ian Robinson
    0

    What's the contents of @currentUser, or @currentUser.Name when you're not logged in?

  • Fuji Kusaka 2203 posts 4220 karma points
    Sep 25, 2012 @ 14:26
    Fuji Kusaka
    0

    I instead did something like this 

    @using umbraco.MacroEngines;
    @inherits umbraco.MacroEngines.DynamicNodeContext
    @using umbraco.cms.businesslogic.member
    @using System.Web.Security
     
    @{ 
    dynamic nodes = Model.AncestorOrSelf(2).Children.Where("Visible && HasAccess");  
    <div>   
    @foreach(var node in nodes){         
    <li><a href="@node.Url">@node.Name</a></li>  
    }
    </div>  
     }
  • Ian Robinson 79 posts 143 karma points
    Sep 25, 2012 @ 14:42
    Ian Robinson
    0

    I'm glad you got it working but it's strange that the .HasAccess() property wasn't working.

Please Sign in or register to post replies

Write your reply to:

Draft