Copied to clipboard

Flag this post as spam?

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


  • curlybub 133 posts 107 karma points
    Sep 09, 2009 @ 04:08
    curlybub
    0

    Display only the pages that members have access to

    Hi again,

    I encountered another challenge with umbraco, which is to display only the pages that members are allowed to access.
    Please see this link, http://i59.photobucket.com/albums/g294/Curlybub26/forums-question.jpg. I'll be referring to that image with this question.

    First I have a structure showed on Fig 1.0, The Members Area can only be accessed by the Website-User member group however the Video section cannot be accessed by the Website-User group but can be accessed by the Website-Video-User. So inorder to access the video page you need to have the Website-User and Website-Video-User groups. Under the videos folder I have several videos listed. I'll be assigning different member groups to access a certain video. on Fig 1.0 Test Video Entry 1 can only be accessed by members that are on the Video Access 1 member group, Test Video Entry 2 will be accessed by Video Access 2 member group and Video Access 3 will be for the test Video Entry 3.

    I assigned member01 to have access to Test Video Entry 2 and 3 by giving it the Video Access 2 and 3 member group as shown on Fig 3.0. What I want to happen is that when member01 clicks on the Video link on the actual website, it will only display Test Video Entry 2 and test Video Entry 3 since those are the only pages that he/she has access to instead of displaying all of the nodes under the video folder. Right now Im using this xsl with paging from nibble.be to display all the nodes under the videos folder. How can I filter the display of nodes?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library"
      exclude-result-prefixes="msxml umbraco.library"> 
     
      <xsl:output method="xml" omit-xml-declaration="yes"/>
     
      <xsl:param name="currentPage"/>
     
      <xsl:template match="/">
        <xsl:variable name="recordsPerPage" select="5"/>
        <xsl:variable name="pageNumber" >
          <xsl:choose>
            <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">0</xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable> &nbsp;
       
        <xsl:variable name="numberOfRecords" select="count($currentPage/node)"/>
    <div class="paging-nodes">
        <ul>
          <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) +$recordsPerPage )">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
              </li>
            </xsl:if>
          </xsl:for-each>
        </ul>
    </div>
    <div class="paging">
    <ul>
        <xsl:if test="$pageNumber &gt; 0">
          <a href="?page{$pageNumber -1}">&nbsp;Previous&nbsp;&nbsp;</a>
        </xsl:if>
       
        <xsl:call-template name="for.loop">
          <xsl:with-param name="i">1</xsl:with-param>
          <xsl:with-param name="page" select="$pageNumber +1"></xsl:with-param>
          <xsl:with-param name="count" select="ceiling(count($currentPage/node)div $recordsPerPage)"></xsl:with-param>
        </xsl:call-template>
       
        <xsl:if test="(($pageNumber +1 ) * $recordsPerPage) &lt; ($numberOfRecords)">
          <a href="?page={$pageNumber +1}">&nbsp;&nbsp;Next&nbsp;</a>
        </xsl:if>
    </ul>
    </div>
      </xsl:template>
     
      <xsl:template name="for.loop">
        <xsl:param name="i"/>
        <xsl:param name="count"/>
        <xsl:param name="page"/>
      
           <xsl:if test="$i &lt;= $count">
          <xsl:if test="$page != $i">
            <a href="{umbraco.library:NiceUrl($currentPage/@id)}?page={$i - 1}" >&nbsp;|&nbsp;<xsl:value-of select="$i" />&nbsp;|&nbsp;</a>
          </xsl:if>
          <xsl:if test="$page = $i"><xsl:value-of select="$i" />
          </xsl:if> 
        </xsl:if>
        <xsl:if test="$i &lt;= $count">
          <xsl:call-template name="for.loop">
            <xsl:with-param name="i"><xsl:value-of select="$i + 1"/></xsl:with-param>
            <xsl:with-param name="count"><xsl:value-of select="$count"/></xsl:with-param>
            <xsl:with-param name="page"><xsl:value-of select="$page"/></xsl:with-param>
          </xsl:call-template>
        </xsl:if>
      </xsl:template>
    </xsl:stylesheet>
  • Mikael Mørup 297 posts 326 karma points
    Sep 09, 2009 @ 08:15
    Mikael Mørup
    1

    You can use umbraco.library:hasaccess() and umbraco.library:isprotected()

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 09, 2009 @ 08:16
    Dirk De Grave
    0

    Hi curlybub, umbraco has some methods for you to do exactly what you're asking for and those areavailable as xslt extensions, so no additional coding required.

    If you need to check whether a user is logged in and has access to a page, use

    <xsl:for-each select="$currentPage/node">
      <xsl:if test="umbraco.library:IsLoggedOn() and umbraco.library:HasAccess(@id, @path)">
        <xsl:value-of select="@nodeName"/>
      </xsl:if>
    </xsl:for-each>

     

    Hope this helps.

    Regards,

    /Dirk

  • curlybub 133 posts 107 karma points
    Sep 09, 2009 @ 08:39
    curlybub
    0

    Hi Dirk,

    Pardon my ignorance but where will I place that code statement that you've made? What part of the xslt that i'm currently using will i replace?

    I tried to replace

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1']">
            <xsl:if test="position() &gt; $recordsPerPage * number($pageNumber) and position() &lt;= number($recordsPerPage * number($pageNumber) +$recordsPerPage )">
              <li>
                <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a>
              </li>
            </xsl:if>
          </xsl:for-each>

    With the code that you've placed but I get an error saying:

    System.NullReferenceException: Object reference not set to an instance of an object. 
    at umbraco.BusinessLogic.StateHelper.GetCookieValue(HttpContext context, String key)
    at umbraco.BusinessLogic.StateHelper.HasCookieValue(String key)
    at umbraco.cms.businesslogic.member.Member.CurrentMemberId()
    at umbraco.cms.businesslogic.member.Member.IsLoggedOn()
    at umbraco.library.IsLoggedOn()


    Thank you.


    Regards,
    Harry

  • Ron Brouwer 273 posts 768 karma points
    Sep 09, 2009 @ 08:42
    Ron Brouwer
    0

    <xsl:for-each select="$currentPage/node [string(data [@alias='umbracoNaviHide']) != '1'
    umbraco.library:IsLoggedOn() and umbraco.library:HasAccess(@id, @path)]">

    Ron

  • curlybub 133 posts 107 karma points
    Sep 09, 2009 @ 08:59
    curlybub
    0

    A Big THANK YOU too all of you guys! :D

Please Sign in or register to post replies

Write your reply to:

Draft