Copied to clipboard

Flag this post as spam?

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


  • Profiterole 232 posts 264 karma points
    Mar 01, 2012 @ 21:41
    Profiterole
    0

    Protect a menu only for certain groups only

    Hi guys,

    On my site, there's teachers member group and students member group. I can protect nodes from students by allowing only teachers group with right-button context menu.

    What I'd like to do, is to protect only a menu on a template. So, every one (logged in or not) could see the webpage, but only the loggedin teacher could see the top menu.

    My menu is done by xslt, so I can verify if loggedIn, but how I verify if the member is in the right group? How I can tell this part of template or this macro that it's available only to teachers?

    Thank you for your help!

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 01, 2012 @ 21:50
    Tom Fulton
    0

    Hi,

    You can use the HasAccess extension method to check if a the currently logged in user has access to a given page.

    Ex:

    <xsl:if test="umbraco.library:HasAccess(@id,@path) = true()">

    So one way to handle this would be to add this check to your XSLT macro anywhere it renders pages, for example:

        <xsl:for-each select="$currentPage/* [@isDoc][string(umbracoNaviHide) != '1'][not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:HasAccess(@id, @path)]">

    (that would show pages that are not protected, or protected pages that the current user has access to)

    Or if you know where you're rendering these pages (for example if the protected menu is it's own macro), you can simply wrap the if tag around your normal menu XSLT.

    HTH,
    Tom

  • Profiterole 232 posts 264 karma points
    Mar 02, 2012 @ 00:47
    Profiterole
    0

    Ok, but how I can tell the menu that only a particular group hasaccess to it? I can only protect complete page? Not part of them?

  • Markus Johansson 1936 posts 5864 karma points MVP 2x c-trib
    Mar 02, 2012 @ 07:42
    Markus Johansson
    0

    The default implementation protects the whole page, and if you want to - hides it in the the menu.

  • Profiterole 232 posts 264 karma points
    Mar 02, 2012 @ 13:45
    Profiterole
    0

    Ok, after some tests, I succeed. When I say menu, I want to say the html element, not only the link in it. So, in my xslt, I request the member group and, with an if, I display the element if the member has the right group.

    Thank for your help guys!

Please Sign in or register to post replies

Write your reply to:

Draft