Copied to clipboard

Flag this post as spam?

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


  • Shaun 248 posts 475 karma points
    Nov 24, 2009 @ 19:15
    Shaun
    0

    Odd behaviour from umbraco.library.HasAccess

    I have a bit of xslt in a macro that spits out nodes if they match certain criteria

    <xsl:for-each select="$currentPage/node">
    <xsl:sort select="data [@alias = 'date']" order="descending" data-type="text"/>
    <!--only draw something if we have access to it -->       
    <xsl:if test="(umbraco.library:IsProtected(@id, @path) = false) or (umbraco.library:HasAccess(@id, @path) = true)">
    protected=<xsl:value-of select="umbraco.library:IsProtected(@id, @path)"/><br/>
    access=<xsl:value-of select="umbraco.library:HasAccess(@id, @path)"/>
    </xsl:if>
    </xsl:for-each>

    If it hits a node that is not protected it returns the following

    protected=false

    access=true

    so far so good. If it hits a node that is protected, but to which my member does not have the correct group access it still displays the information

    protected=true

    access=false

    which is wrong, why does it display that?

    Also, if it hits a node which IS protected, but my member DOES have access, it doesn't display anything at all. Could this be something to do with my sort command?

  • Shaun 248 posts 475 karma points
    Nov 24, 2009 @ 21:07
    Shaun
    0

    Sussed it, although I have no idea why.

    I amended

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

    to

    <xsl:if test="(umbraco.library:IsProtected(@id, @path) = false) or (umbraco.library:HasAccess(@id, @path) = !=false)">

    and it worked. I'd love to know why that is though. Any ideas?

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Nov 24, 2009 @ 21:38
    Chriztian Steinmeier
    2

    Hi Shaun,

    You have to be very careful with true and false in XSLT - when used like that, the Processor will look for an element named <false> or <true> in the source tree - not what you want :-). You can use false() and true() instead, but a common idiom in XSLT is to use the not() function when testing for "something equals false()" - so something like this:

    <xsl:if test="not(umbraco.library:IsProtected(@id, @path)) or umbraco.library:HasAccess(@id, @path)">
    ...
    </xsl:if>

    (Of course, the reason they come out as "false" and/or "true" when using value-of is due to string-conversion)

    Hope this helps,

    /Chriztian

  • Shaun 248 posts 475 karma points
    Nov 25, 2009 @ 17:43
    Shaun
    0

    Hi Chriztian

    Thanks for explaining that for me. It makes perfect sense now :) I'll remember this next time I'm working with Booleans in xslt.

  • 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