From 4e56d88eb5f09b5bd9b5fd036734636aa773aa83 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 1 Oct 2013 16:38:10 +1000 Subject: [PATCH] Fixes: U4-2672 Fix how trees are rendered when a start node is applied, the Content/Media titles must always be visible --- .../Trees/ContentTreeController.cs | 41 +++++++------------ .../Trees/ContentTreeControllerBase.cs | 13 ++++-- src/Umbraco.Web/Trees/MediaTreeController.cs | 22 ++++++++++ src/Umbraco.Web/Trees/TreeNode.cs | 7 ---- 4 files changed, 47 insertions(+), 36 deletions(-) diff --git a/src/Umbraco.Web/Trees/ContentTreeController.cs b/src/Umbraco.Web/Trees/ContentTreeController.cs index 0136510628..20b17babf9 100644 --- a/src/Umbraco.Web/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTreeController.cs @@ -26,36 +26,13 @@ namespace Umbraco.Web.Trees { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { - TreeNode node; - - //if the user's start node is not default, then return their start node as the root node. + var node = base.CreateRootNode(queryStrings); + //if the user's start node is not default, then ensure the root doesn't have a menu if (Security.CurrentUser.StartContentId != Constants.System.Root) { - var currApp = queryStrings.GetValue(TreeQueryStringParameters.Application); - var userRoot = Services.EntityService.Get(Security.CurrentUser.StartContentId, UmbracoObjectTypes.Document); - if (userRoot == null) - { - throw new HttpResponseException(HttpStatusCode.NotFound); - } - - node = new TreeNode( - userRoot.Id.ToInvariantString(), - "", //root nodes aren't expandable, no need to lookup the child nodes url - Url.GetMenuUrl(GetType(), userRoot.Id.ToInvariantString(), queryStrings)) - { - HasChildren = true, - RoutePath = currApp, - Title = userRoot.Name - }; - - - } - else - { - node = base.CreateRootNode(queryStrings); + node.MenuUrl = ""; } return node; - } protected override int RecycleBinId @@ -68,6 +45,11 @@ namespace Umbraco.Web.Trees get { return Services.ContentService.RecycleBinSmells(); } } + protected override int UserStartNode + { + get { return Security.CurrentUser.StartContentId; } + } + protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings) { var entities = GetChildEntities(id); @@ -111,10 +93,17 @@ namespace Umbraco.Web.Trees { var menu = new MenuItemCollection(); + //if the user's start node is not the root then ensure the root menu is empty/doesn't exist + if (Security.CurrentUser.StartContentId != Constants.System.Root) + { + return menu; + } + //set the default to create menu.DefaultMenuAlias = ActionNew.Instance.Alias; // we need to get the default permissions as you can't set permissions on the very root node + //TODO: Use the new services to get permissions var nodeActions = global::umbraco.BusinessLogic.Actions.Action.FromString( UmbracoUser.GetPermissions(Constants.System.Root.ToInvariantString())) .Select(x => new MenuItem(x)); diff --git a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs index b3ebabb0f9..a1e646e70a 100644 --- a/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/ContentTreeControllerBase.cs @@ -23,6 +23,11 @@ namespace Umbraco.Web.Trees /// protected abstract bool RecycleBinSmells { get; } + /// + /// Returns the user's start node for this tree + /// + protected abstract int UserStartNode { get; } + protected abstract TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings); protected abstract MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings); @@ -39,9 +44,11 @@ namespace Umbraco.Web.Trees //if a request is made for the root node data but the user's start node is not the default, then // we need to return their start node data - if (iid == Constants.System.Root && UmbracoUser.StartNodeId != Constants.System.Root) + if (iid == Constants.System.Root && UserStartNode != Constants.System.Root) { - return Services.EntityService.GetChildren(UmbracoUser.StartNodeId, UmbracoObjectType).ToArray(); + //just return their single start node, it will show up under the 'Content' label + var startNode = Services.EntityService.Get(UserStartNode, UmbracoObjectType); + return new[] {startNode}; } return Services.EntityService.GetChildren(iid, UmbracoObjectType).ToArray(); @@ -56,7 +63,7 @@ namespace Umbraco.Web.Trees /// protected sealed override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) { - if (id == Constants.System.Root.ToInvariantString()) + if (id == Constants.System.Root.ToInvariantString() && UserStartNode == Constants.System.Root) { //we need to append the recycle bin to the end (if not in dialog mode) var nodes = PerformGetTreeNodes(id, queryStrings); diff --git a/src/Umbraco.Web/Trees/MediaTreeController.cs b/src/Umbraco.Web/Trees/MediaTreeController.cs index fac1e5386b..3df864cbd7 100644 --- a/src/Umbraco.Web/Trees/MediaTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTreeController.cs @@ -20,6 +20,17 @@ namespace Umbraco.Web.Trees [PluginController("UmbracoTrees")] public class MediaTreeController : ContentTreeControllerBase { + protected override TreeNode CreateRootNode(FormDataCollection queryStrings) + { + var node = base.CreateRootNode(queryStrings); + //if the user's start node is not default, then ensure the root doesn't have a menu + if (Security.CurrentUser.StartMediaId != Constants.System.Root) + { + node.MenuUrl = ""; + } + return node; + } + protected override int RecycleBinId { get { return Constants.System.RecycleBinContent; } @@ -30,6 +41,11 @@ namespace Umbraco.Web.Trees get { return Services.MediaService.RecycleBinSmells(); } } + protected override int UserStartNode + { + get { return Security.CurrentUser.StartMediaId; } + } + protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings) { var entities = GetChildEntities(id); @@ -53,6 +69,12 @@ namespace Umbraco.Web.Trees if (id == Constants.System.Root.ToInvariantString()) { + //if the user's start node is not the root then ensure the root menu is empty/doesn't exist + if (Security.CurrentUser.StartMediaId != Constants.System.Root) + { + return menu; + } + // root actions menu.AddMenuItem(); menu.AddMenuItem(true); diff --git a/src/Umbraco.Web/Trees/TreeNode.cs b/src/Umbraco.Web/Trees/TreeNode.cs index fd62dff815..fefd5e6f80 100644 --- a/src/Umbraco.Web/Trees/TreeNode.cs +++ b/src/Umbraco.Web/Trees/TreeNode.cs @@ -53,13 +53,6 @@ namespace Umbraco.Web.Trees [DataMember(Name = "name")] public string Title { get; set; } - //TODO: This doesn't seem to be used by anything! - /// - /// Gets or sets the node path. - /// - [DataMember(Name = "nodePath")] - public string NodePath { get; set; } - /// /// The icon to use for the node, this can be either a path to an image or a Css class. /// If a '/' is found in the string then it will be considered a path to an image.