Copied to clipboard

Flag this post as spam?

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


  • Daniel Larsen 116 posts 381 karma points
    Mar 01, 2015 @ 11:56
    Daniel Larsen
    0

    Trying to list protected nodes but fails

    Hi

    I am trying to list the nodes under "Documents". The shared one is for all members and the other ones, are only for the individual user. Eg. Ryan wont see Sophies documents.

    Here is the structure of the nodes.

    Home - access for all members
    - News
    - Images
    - Calendar
    - Documents
    --- Shared - no protection other than from the top level node
    ----- node
    ----- node
    ----- node
    --- Ryan - Added protection for first group
    ----- node
    ----- node
    ----- node
    --- Sophie  - Added protection for second group
    ----- node
    ----- node
    ----- node
    

    My partial view rendes fine, when the "if(childPage.HasAccess())" is not there, but fails when there. It i my first time playing with .HasAccess so I am learning! :-)

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @if (CurrentPage.Children.Where("Visible").Any())
    {
        <ul>            
            @foreach (var childPage in CurrentPage.Children.Where("Visible"))
            {
                if(childPage.HasAccess())
                {
                    <li>
                        <a href="@childPage.Url">@childPage.Name</a>
                    </li>
    
                    foreach (var item in childPage.Children.Where("Visible")) 
                    {
                        <a href="@item.Url">@item.Name</a><br>
                    }
                }
            }
        </ul>
    }
    

    Can you guys see, where I am going wrong?

    Thank you for your help! :-)

    Daniel

  • Daniel Larsen 116 posts 381 karma points
    Mar 02, 2015 @ 10:08
    Daniel Larsen
    101

    I found the solution! :-)

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
    
        if (CurrentPage.Children.Where("Visible").Any())
        {
    
            foreach (var childPage in CurrentPage.Children.Where("Visible"))
            {
                if (umbraco.library.HasAccess(childPage.Id, childPage.Path))
                {
                    <h3 class="heading">@childPage.Name<span>Udvid</span></h3>
    
                    <span class="files">
    
                        @foreach (var item in childPage.Children.Where("Visible"))
                        {
                            <span class="">
                                <a href="@item.Url" title="Klik for at downloade" target="_blank">@item.Name</a>
    
                            </span>
                        }
                    </span>
                }
            }
    
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft