Esempio n. 1
0
        private static ISiteMapNode GetNextNode(ISiteMapNode startingNode, IDictionary <string, object> sourceMetadata)
        {
            ISiteMapNode nextNode = null;

            if (startingNode.HasChildNodes)
            {
                // Get the first child node
                nextNode = startingNode.ChildNodes[0];
            }
            else if (startingNode.ParentNode != null)
            {
                // Get the next sibling node
                nextNode = startingNode.NextSibling;
                if (nextNode == null)
                {
                    // If there are no more siblings, the next position
                    // should be the parent's next sibling
                    var parent = startingNode.ParentNode;
                    if (parent != null)
                    {
                        nextNode = parent.NextSibling;
                    }
                }
            }

            // If the node is not visible or accessible, run the operation recursively until a visible node is found
            if (nextNode != null && !(nextNode.IsVisible(sourceMetadata) || nextNode.IsAccessibleToUser()))
            {
                nextNode = GetNextNode(nextNode, sourceMetadata);
            }

            return(nextNode);
        }
Esempio n. 2
0
        private static ISiteMapNode GetPreviousNode(ISiteMapNode startingNode, IDictionary <string, object> sourceMetadata)
        {
            ISiteMapNode previousNode = null;

            // Get the previous sibling
            var previousSibling = startingNode.PreviousSibling;

            if (previousSibling != null)
            {
                // If there are any children, go to the last descendant
                if (previousSibling.HasChildNodes)
                {
                    previousNode = previousSibling.Descendants.Last();
                }
                else
                {
                    // If there are no children, return the sibling.
                    previousNode = previousSibling;
                }
            }
            else
            {
                // If there are no more siblings before this one, go to the parent node
                previousNode = startingNode.ParentNode;
            }

            // If the node is not visible or accessible, run the operation recursively until a visible node is found
            if (previousNode != null && !(previousNode.IsVisible(sourceMetadata) || previousNode.IsAccessibleToUser()))
            {
                previousNode = GetPreviousNode(previousNode, sourceMetadata);
            }

            return(previousNode);
        }
Esempio n. 3
0
 protected virtual ISiteMapNode ReturnNodeIfAccessible(ISiteMapNode node)
 {
     if ((node != null) && node.IsAccessibleToUser())
     {
         return(node);
     }
     return(null);
 }
Esempio n. 4
0
 public bool IsAccessibleToUser(ISiteMapNode node)
 {
     if (!SecurityTrimmingEnabled)
     {
         return(true);
     }
     return(node.IsAccessibleToUser());
 }
        /// <summary>
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public bool IsAccessibleToUser(ISiteMapNode node)
        {
            string operatorExpress = node.Attributes.ContainsKey("permission")
                ? (string) node.Attributes["permission"]
                : null;
            if (String.IsNullOrEmpty(operatorExpress))
            {
                return node.IsAccessibleToUser();
            }
            var permission = new MenuPermission(operatorExpress, _memberShipContext);

            return permission.HasRight(OrnamentContext.MemberShip.CurrentUser());
        }
        /// <summary>
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public bool IsAccessibleToUser(ISiteMapNode node)
        {
            string operatorExpress = node.Attributes.ContainsKey("permission")
                ? (string)node.Attributes["permission"]
                : null;

            if (String.IsNullOrEmpty(operatorExpress))
            {
                return(node.IsAccessibleToUser());
            }
            var permission = new MenuPermission(operatorExpress, _memberShipContext);

            return(permission.HasRight(OrnamentContext.MemberShip.CurrentUser()));
        }
 /// <summary>
 /// Generates flat list of SiteMapNode from SiteMap hierarchy.
 /// </summary>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="context">The controller context.</param>
 /// <param name="visibilityAffectsDescendants">A boolean indicating whether visibility of the current node should affect the visibility of descendant nodes.</param>
 /// <returns>A flat list of SiteMapNode.</returns>
 protected virtual IEnumerable <ISiteMapNode> FlattenHierarchy(ISiteMapNode startingNode, ControllerContext context, bool visibilityAffectsDescendants)
 {
     // Inaccessible - don't process current node or any descendant nodes.
     if (startingNode.IsAccessibleToUser() && (visibilityAffectsDescendants ? startingNode.IsVisible(SourceMetadata) : true))
     {
         if (this.ShouldNodeRender(startingNode, context))
         {
             yield return(startingNode);
         }
         if (startingNode.HasChildNodes)
         {
             // Make sure all child nodes are accessible prior to rendering them...
             foreach (ISiteMapNode node in startingNode.ChildNodes)
             {
                 foreach (var childNode in FlattenHierarchy(node, context, visibilityAffectsDescendants))
                 {
                     yield return(childNode);
                 }
             }
         }
     }
 }
Esempio n. 8
0
 protected virtual ISiteMapNode ReturnNodeIfAccessible(ISiteMapNode node)
 {
     if ((node != null) && node.IsAccessibleToUser())
     {
         return node;
     }
     return null;
 }
 /// <summary>
 /// Generates flat list of SiteMapNode from SiteMap hierarchy.
 /// </summary>
 /// <param name="startingNode">The starting node.</param>
 /// <param name="context">The controller context.</param>
 /// <param name="visibilityAffectsDescendants">A boolean indicating whether visibility of the current node should affect the visibility of descendant nodes.</param>
 /// <returns>A flat list of SiteMapNode.</returns>
 protected virtual IEnumerable<ISiteMapNode> FlattenHierarchy(ISiteMapNode startingNode, ControllerContext context, bool visibilityAffectsDescendants)
 {
     // Inaccessible - don't process current node or any descendant nodes.
     if (startingNode.IsAccessibleToUser() && (visibilityAffectsDescendants ? startingNode.IsVisible(SourceMetadata) : true))
     {
         if (this.ShouldNodeRender(startingNode, context))
         {
             yield return startingNode;
         }
         if (startingNode.HasChildNodes)
         {
             // Make sure all child nodes are accessible prior to rendering them...
             foreach (ISiteMapNode node in startingNode.ChildNodes)
             {
                 foreach (var childNode in FlattenHierarchy(node, context, visibilityAffectsDescendants))
                 {
                     yield return childNode;
                 }
             }
         }
     }
 }