|
|
 Rank: Devotee
Joined: 10/31/2007 Posts: 94 Location: Birmingham (UK)
|
I've followed the various screen casts going and I still can't figure this one out, I'm setting up a file manager area on a site, the theory being I'm going to use the built in restrictions to restrict the access so the node looks like this: -File area (Logged in) -File Category -File 1 (Logged in) -File 2 (only group 1) -File Category (only group 1) -File 1 -File 2 -File Category (only group 2) -File 1 -File 2 The issue I'm finding however is that all files are listed regardless of the group the user is logged in as, does the XSLT need to be different? Tim Here's my XSLT Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
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:if test="count($currentPage/node [@nodeTypeAlias = 'tsdPartnersFileCategory' and string(data [@alias='umbracoNaviHide']) != '1']/node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0">
<xsl:call-template name="Category">
<xsl:with-param name="node" select="$currentPage/node [@nodeTypeAlias = 'tsdPartnersFileCategory' and string(data [@alias='umbracoNaviHide']) != '1']"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="count($currentPage/node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0">
<h6>Other Files</h6>
<xsl:call-template name="File">
<xsl:with-param name="node" select="$currentPage/node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1']"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="Category">
<xsl:param name="node"/>
<xsl:for-each select="$node[string(data [@alias='umbracoNaviHide']) != '1']">
<!-- Output the category name -->
<xsl:if test="count(./node [@nodeTypeAlias = 'tsdPartnersFileCategory' and string(data [@alias='umbracoNaviHide']) != '1']/node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0 or count(./node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0">
<h6><xsl:value-of select="data[@alias='categoryName']"/></h6>
</xsl:if>
<!-- Get the categories under the category -->
<xsl:if test="count(./node [@nodeTypeAlias = 'tsdPartnersFileCategory' and string(data [@alias='umbracoNaviHide']) != '1']/node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0">
<xsl:call-template name="Category">
<xsl:with-param name="node" select="./node [@nodeTypeAlias = 'tsdPartnersFileCategory' and string(data [@alias='umbracoNaviHide']) != '1']"/>
</xsl:call-template>
</xsl:if>
<!-- Get the Files under the category -->
<xsl:if test="count(./node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1' and string(data[@alias='documentFile']) != '']) > 0">
<xsl:call-template name="File">
<xsl:with-param name="node" select="./node [@nodeTypeAlias = 'tsdPartnersFile' and string(data [@alias='umbracoNaviHide']) != '1']"/>
</xsl:call-template>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="File">
<xsl:param name="node"/>
<ul class="fileList">
<xsl:for-each select="$node[string(data [@alias='umbracoNaviHide']) != '1']">
<xsl:if test="string(data[@alias='documentFile']) != ''">
<li>
<a href="{data[@alias='documentFile']}">
<xsl:attribute name="title">
<xsl:value-of select="data [@alias='documentTitle']" />
</xsl:attribute>
<xsl:value-of select="data[@alias='linkText']" />
</a><br />
<xsl:value-of select="data[@alias='linkDescription']" />
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,082 Location: KY, USA
|
Have a look at the umbraco.library:IsProtected, :IsLoggedOn, and (most importantly) :HasAccess functions that you can use in your xslt. cheers, doug.
MVP 2007/2008 - Official Umbraco Trainer for North America - Percipient Studios
|
|
Rank: Umbracoholic
Joined: 7/20/2006 Posts: 1,018 Location: Charleston, West Virginia, United States
|
Not to step on Doug's toes, but...
What Doug is trying to say is that the Public Access restriction does not stop XSLT from seeing the nodes, but does stop umbraco from serving the node as a page.
To stop the node from displaying in xslt, you must use the library methods he outlined above to check those permissions. Basically, you have to program in the restrictions.
Case
• 2007 - 2008 MVP • Charleston, WV, USA • umbracoholic since Dec. 2004 (v.2.0) • Achieved umbracoholic status on 2008-04-25
|
|
 Rank: Devotee
Joined: 10/31/2007 Posts: 94 Location: Birmingham (UK)
|
Great thanks guys, I've got that working but now I'm wondering whether there is any way to count the number of (child) nodes the user has access too -if there are none I want to hide the header menu and not loop through the "File" template.
Is that possible out of the box?
Tim
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,082 Location: KY, USA
|
Just do a count() on the child nodes that have HasAccess(). If greater than 0 you know you've got accessable nodes. cheers, doug.
MVP 2007/2008 - Official Umbraco Trainer for North America - Percipient Studios
|
|
Rank: Devotee
Joined: 10/25/2007 Posts: 52
|
Hi everybody, I'm trying to use the umbraco.library:HasAccess(@id, @path) method, but I get an exception when trying to save my XSLT in umbraco. The following is the exception I get: Code:System.Xml.XPath.XPathException: Function 'umbraco.library:HasAccess()' has failed. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> 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.HasAccess(Int32 NodeId, String Path) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext) at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) --- End of inner exception stack trace --- at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator) at MS.Internal.Xml.XPath.LogicalExpr.Evaluate(XPathNodeIterator nodeIterator) at MS.Internal.Xml.XPath.BooleanFunctions.toBoolean(XPathNodeIterator nodeIterator) at MS.Internal.Xml.XPath.BooleanFunctions.Evaluate(XPathNodeIterator nodeIterator) at System.Xml.Xsl.XsltOld.Processor.EvaluateBoolean(ActionFrame context, Int32 key) at System.Xml.Xsl.XsltOld.IfAction.Execute(Processor processor, ActionFrame frame) at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor) from the following XSLT-code: Code:<xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']"> <xsl:if test="umbraco.library:IsProtected(@id, @path) = 0"> <li> <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id"> <!-- we're under the item - you can do your own styling here --> <xsl:attribute name="id">current</xsl:attribute> </xsl:if> <xsl:if test="umbraco.library:IsProtected(@id, @path) = 1"> <xsl:attribute name="class">restricted</xsl:attribute> </xsl:if> <a href="{umbraco.library:NiceUrl(@id)}"> <xsl:value-of select="@nodeName"/> </a> </li> </xsl:if> </xsl:for-each> Can anybody out there help? Thanks a lot in advance :o) /Kim
|
|
 Rank: Umbracoholic
Joined: 9/8/2006 Posts: 1,082 Location: KY, USA
|
Hi, Kim, Check out my explanations in these two threads. They explain what's happening and how you can get around it. http://forum.umbraco.org/yaf_postst3101_If-member-is-logged-in.aspxhttp://forum.umbraco.org/yaf_postst3143_NiceUrl-failing-on-valid-node.aspxcheers, doug.
MVP 2007/2008 - Official Umbraco Trainer for North America - Percipient Studios
|
|
|
Guest |