Copied to clipboard

Flag this post as spam?

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


  • Michael 2 posts 52 karma points
    Jul 04, 2014 @ 18:12
    Michael
    0

    Hide menu items based on permission

    Hi

    I'm trying to create a simple menu which will only show items that a user has access to.

    For example, we have a website with a home page (public) and then two private sections A and B.

    When the user is not logged in, I want to show the link to "home" only. When the user is logged in and has permission to access "section A" the menu should display "Section A".

    I've seen a post about the function "WhereHasAccess()" from Umbraco 5, but can't seem to find anything about 6 or 7.

    At the moment all I have is:

       var menuItems = homePage.Children;
    

    I thought I could have something like this:

    var menuItems = homePage.Children.WhereHasAccess();
    

    or:

    var menuItems = homePage.Children.Where(x => x.WhereHasAccess());
    

    But neither option works at all.

    Please can someone point me in the right direction?

    The above two incorrect statements give the error:

    Cannot use a lambda expression as an argument to a dynamically dispatched operation without first casting it to a delegate or expression tree type

  • Michael 2 posts 52 karma points
    Jul 09, 2014 @ 12:58
    Michael
    100

    Just in case anyone else comes across this, I have managed to find the answer.

    I was using item.HasAccess() and item.IsProtected() to try to determine whether a node is protected and, if so, whether the user has access permissions.

    However, what I should have used is umbraco.library.HasAccess(item.id, item.path), where item is a valid node.

    Hopefully this will help someone else in the future looking for how to do this.

  • Ben Marte 13 posts 34 karma points
    Oct 01, 2014 @ 05:54
    Ben Marte
    0

    Could you post your whole code to see how you implemented his?

    Thanks.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies