From ad026e25d71218a624a356ea06d8bda35394bf68 Mon Sep 17 00:00:00 2001 From: Stephan Date: Tue, 22 Jan 2019 09:31:47 +0100 Subject: [PATCH] Cleanup trees --- .../Editors/BackOfficeServerVariables.cs | 70 ++++++++-------- .../Mvc/PluginControllerAttribute.cs | 20 +++-- src/Umbraco.Web/Runtime/WebRuntimeComposer.cs | 12 +-- .../Search/SearchableTreeCollection.cs | 2 +- src/Umbraco.Web/Services/ITreeService.cs | 33 +++----- src/Umbraco.Web/Services/TreeService.cs | 57 ++++--------- .../Trees/ApplicationTreeController.cs | 2 +- .../Trees/ContentBlueprintTreeController.cs | 4 +- .../Trees/ContentTypeTreeController.cs | 4 +- src/Umbraco.Web/Trees/CoreTreeAttribute.cs | 13 +-- .../Trees/DataTypeTreeController.cs | 6 +- .../Trees/DictionaryTreeController.cs | 4 +- src/Umbraco.Web/Trees/FilesTreeController.cs | 9 +- src/Umbraco.Web/Trees/ITree.cs | 9 +- .../Trees/LanguageTreeController.cs | 4 +- src/Umbraco.Web/Trees/MacrosTreeController.cs | 4 +- .../Trees/MediaTypeTreeController.cs | 4 +- .../Trees/MemberGroupTreeController.cs | 2 +- src/Umbraco.Web/Trees/MemberTreeController.cs | 2 +- .../Trees/MemberTypeTreeController.cs | 4 +- .../Trees/PackagesTreeController.cs | 2 +- .../Trees/PartialViewMacrosTreeController.cs | 4 +- .../Trees/PartialViewsTreeController.cs | 4 +- .../Trees/RelationTypeTreeController.cs | 4 +- .../Trees/ScriptsTreeController.cs | 4 +- .../Trees/StylesheetsTreeController.cs | 4 +- .../Trees/TemplatesTreeController.cs | 4 +- src/Umbraco.Web/Trees/Tree.cs | 31 ++++--- src/Umbraco.Web/Trees/TreeAttribute.cs | 83 +++++++++---------- src/Umbraco.Web/Trees/TreeCollection.cs | 12 +-- .../Trees/TreeCollectionBuilder.cs | 50 +++++++++-- src/Umbraco.Web/Trees/TreeController.cs | 52 ++++++------ src/Umbraco.Web/Trees/TreeControllerBase.cs | 23 ++--- src/Umbraco.Web/Trees/UserTreeController.cs | 2 +- src/Umbraco.Web/TypeLoaderExtensions.cs | 29 ++----- .../UI/Pages/UmbracoEnsuredPage.cs | 2 +- .../Filters/UmbracoTreeAuthorizeAttribute.cs | 2 +- 37 files changed, 277 insertions(+), 300 deletions(-) diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 40891efe9e..d8d580dcd0 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Configuration; using System.Linq; +using System.Runtime.Serialization; using System.Web; using System.Web.Configuration; using System.Web.Mvc; @@ -348,7 +349,10 @@ namespace Umbraco.Web.Editors { "umbracoPlugins", new Dictionary { - {"trees", GetTreePluginsMetaData()} + // for each tree that is [PluginController], get + // alias -> areaName + // so that routing (route.js) can look for views + { "trees", GetPluginTrees().ToArray() } } }, { @@ -389,43 +393,41 @@ namespace Umbraco.Web.Editors return defaultVals; } - private IEnumerable> GetTreePluginsMetaData() + private class PluginTree { - var treeTypes = TreeControllerTypes.Value; - //get all plugin trees with their attributes - var treesWithAttributes = treeTypes.Select(x => new - { - tree = x, - attributes = - x.GetCustomAttributes(false) - }).ToArray(); - - var pluginTreesWithAttributes = treesWithAttributes - //don't resolve any tree decorated with CoreTreeAttribute - .Where(x => x.attributes.All(a => (a is CoreTreeAttribute) == false)) - //we only care about trees with the PluginControllerAttribute - .Where(x => x.attributes.Any(a => a is PluginControllerAttribute)) - .ToArray(); - - return (from p in pluginTreesWithAttributes - let treeAttr = p.attributes.OfType().Single() - let pluginAttr = p.attributes.OfType().Single() - select new Dictionary - { - {"alias", treeAttr.TreeAlias}, {"packageFolder", pluginAttr.AreaName} - }).ToArray(); + [DataMember(Name = "alias")] + public string Alias { get; set; } + [DataMember(Name = "packageFolder")] + public string PackageFolder { get; set; } } - /// - /// A lazy reference to all tree controller types - /// - /// - /// We are doing this because if we constantly resolve the tree controller types from the PluginManager it will re-scan and also re-log that - /// it's resolving which is unecessary and annoying. - /// - private static readonly Lazy> TreeControllerTypes - = new Lazy>(() => Current.TypeLoader.GetAttributedTreeControllers().ToArray()); // todo inject + private IEnumerable GetPluginTrees() + { + // used to be (cached) + //var treeTypes = Current.TypeLoader.GetAttributedTreeControllers(); + // + // ie inheriting from TreeController and marked with TreeAttribute + // + // do this instead + // inheriting from TreeControllerBase and marked with TreeAttribute + var trees = Current.Factory.GetInstance(); + + foreach (var tree in trees) + { + var treeType = tree.TreeControllerType; + + // exclude anything marked with CoreTreeAttribute + var coreTree = treeType.GetCustomAttribute(false); + if (coreTree != null) continue; + + // exclude anything not marked with PluginControllerAttribute + var pluginController = treeType.GetCustomAttribute(false); + if (pluginController == null) continue; + + yield return new PluginTree { Alias = tree.TreeAlias, PackageFolder = pluginController.AreaName }; + } + } /// /// Returns the server variables regarding the application state diff --git a/src/Umbraco.Web/Mvc/PluginControllerAttribute.cs b/src/Umbraco.Web/Mvc/PluginControllerAttribute.cs index 6c8b8f19ee..332f1fd2a9 100644 --- a/src/Umbraco.Web/Mvc/PluginControllerAttribute.cs +++ b/src/Umbraco.Web/Mvc/PluginControllerAttribute.cs @@ -4,23 +4,27 @@ using System.Linq; namespace Umbraco.Web.Mvc { /// - /// An attribute applied to a plugin controller that requires that it is routed to its own area + /// Indicates that a controller is a plugin tree controller and should be routed to its own area. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class PluginControllerAttribute : Attribute { - public string AreaName { get; private set; } - + /// + /// Initializes a new instance of the class. + /// + /// public PluginControllerAttribute(string areaName) { - //validate this, only letters and digits allowed. - if (areaName.Any(c => !Char.IsLetterOrDigit(c))) - { - throw new FormatException("The areaName specified " + areaName + " can only contains letters and digits"); - } + // validate this, only letters and digits allowed. + if (areaName.Any(c => !char.IsLetterOrDigit(c))) + throw new FormatException($"Invalid area name \"{areaName}\": the area name can only contains letters and digits."); AreaName = areaName; } + /// + /// Gets the name of the area. + /// + public string AreaName { get; } } } diff --git a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs index 1a0bf8d1b0..2dda1a793c 100644 --- a/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs +++ b/src/Umbraco.Web/Runtime/WebRuntimeComposer.cs @@ -203,14 +203,10 @@ namespace Umbraco.Web.Runtime .Append(); // register back office trees - foreach (var treeControllerType in umbracoApiControllerTypes - .Where(x => typeof(TreeControllerBase).IsAssignableFrom(x))) - { - var attribute = treeControllerType.GetCustomAttribute(false); - if (attribute == null) continue; - var tree = new Tree(attribute.SortOrder, attribute.ApplicationAlias, attribute.TreeAlias, attribute.TreeTitle, treeControllerType, attribute.IsSingleNodeTree); - composition.WithCollectionBuilder().Trees.Add(tree); - } + // the collection builder only accepts types inheriting from TreeControllerBase + // and will filter out those that are not attributed with TreeAttribute + composition.WithCollectionBuilder() + .AddTreeControllers(umbracoApiControllerTypes.Where(x => typeof(TreeControllerBase).IsAssignableFrom(x))); } } } diff --git a/src/Umbraco.Web/Search/SearchableTreeCollection.cs b/src/Umbraco.Web/Search/SearchableTreeCollection.cs index 032782b466..8f7c6ece0b 100644 --- a/src/Umbraco.Web/Search/SearchableTreeCollection.cs +++ b/src/Umbraco.Web/Search/SearchableTreeCollection.cs @@ -32,7 +32,7 @@ namespace Umbraco.Web.Search var found = searchableTrees.FirstOrDefault(x => x.TreeAlias.InvariantEquals(appTree.TreeAlias)); if (found != null) { - dictionary[found.TreeAlias] = new SearchableApplicationTree(appTree.ApplicationAlias, appTree.TreeAlias, found); + dictionary[found.TreeAlias] = new SearchableApplicationTree(appTree.SectionAlias, appTree.TreeAlias, found); } } return dictionary; diff --git a/src/Umbraco.Web/Services/ITreeService.cs b/src/Umbraco.Web/Services/ITreeService.cs index 96787086c6..691e5a6370 100644 --- a/src/Umbraco.Web/Services/ITreeService.cs +++ b/src/Umbraco.Web/Services/ITreeService.cs @@ -1,41 +1,32 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Umbraco.Core.Models; -using Umbraco.Core.Models.ContentEditing; -using Umbraco.Web.Models.ContentEditing; +using System.Collections.Generic; using Umbraco.Web.Trees; namespace Umbraco.Web.Services { + /// + /// Represents a service which manages section trees. + /// public interface ITreeService { /// - /// Gets an ApplicationTree by it's tree alias. + /// Gets a tree. /// /// The tree alias. - /// An ApplicationTree instance Tree GetByAlias(string treeAlias); /// - /// Gets all applicationTrees registered in umbraco from the umbracoAppTree table.. + /// Gets all trees. /// - /// Returns a ApplicationTree Array IEnumerable GetAll(); - + /// - /// Gets the application tree for the applcation with the specified alias + /// Gets all trees for a section. /// - /// The application alias. - /// Returns a ApplicationTree Array - IEnumerable GetTrees(string sectionAlias); - + IEnumerable GetBySection(string sectionAlias); + /// - /// Gets the grouped application trees for the application with the specified alias + /// Gets all trees for a section, grouped. /// - /// - /// - IDictionary> GetGroupedTrees(string sectionAlias); + IDictionary> GetBySectionGrouped(string sectionAlias); } - } diff --git a/src/Umbraco.Web/Services/TreeService.cs b/src/Umbraco.Web/Services/TreeService.cs index f58dce59bc..c697a89a62 100644 --- a/src/Umbraco.Web/Services/TreeService.cs +++ b/src/Umbraco.Web/Services/TreeService.cs @@ -6,65 +6,38 @@ using Umbraco.Web.Trees; namespace Umbraco.Web.Services { + /// + /// Implements . + /// internal class TreeService : ITreeService { private readonly TreeCollection _treeCollection; - private readonly Lazy>> _groupedTrees; + /// + /// Initializes a new instance of the class. + /// + /// public TreeService(TreeCollection treeCollection) { _treeCollection = treeCollection; - _groupedTrees = new Lazy>>(InitGroupedTrees); } /// - public Tree GetByAlias(string treeAlias) => _treeCollection.FirstOrDefault(t => t.TreeAlias == treeAlias); + public Tree GetByAlias(string treeAlias) => _treeCollection.FirstOrDefault(x => x.TreeAlias == treeAlias); /// public IEnumerable GetAll() => _treeCollection; /// - public IEnumerable GetTrees(string sectionAlias) - => GetAll().Where(x => x.ApplicationAlias.InvariantEquals(sectionAlias)).OrderBy(x => x.SortOrder).ToList(); + public IEnumerable GetBySection(string sectionAlias) + => _treeCollection.Where(x => x.SectionAlias.InvariantEquals(sectionAlias)).OrderBy(x => x.SortOrder).ToList(); - public IDictionary> GetGroupedTrees(string sectionAlias) + /// + public IDictionary> GetBySectionGrouped(string sectionAlias) { - var result = new Dictionary>(); - var foundTrees = GetTrees(sectionAlias).ToList(); - foreach(var treeGroup in _groupedTrees.Value) - { - List resultGroup = null; - foreach(var tree in foundTrees) - { - foreach(var treeAliasInGroup in treeGroup) - { - if (tree.TreeAlias != treeAliasInGroup) continue; - - if (resultGroup == null) resultGroup = new List(); - resultGroup.Add(tree); - } - } - if (resultGroup != null) - result[treeGroup.Key ?? string.Empty] = resultGroup; //key cannot be null so make empty string - } - return result; + return GetBySection(sectionAlias).GroupBy(x => x.TreeGroup).ToDictionary( + x => x.Key ?? "", + x => (IEnumerable) x.ToArray()); } - - /// - /// Creates a group of all tree groups and their tree aliases - /// - /// - /// - /// Used to initialize the field - /// - private IReadOnlyCollection> InitGroupedTrees() - { - var result = GetAll() - .Select(x => (treeAlias: x.TreeAlias, treeGroup: x.TreeControllerType.GetCustomAttribute(false)?.TreeGroup)) - .GroupBy(x => x.treeGroup, x => x.treeAlias) - .ToList(); - return result; - } - } } diff --git a/src/Umbraco.Web/Trees/ApplicationTreeController.cs b/src/Umbraco.Web/Trees/ApplicationTreeController.cs index 2541221537..75ae623580 100644 --- a/src/Umbraco.Web/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web/Trees/ApplicationTreeController.cs @@ -60,7 +60,7 @@ namespace Umbraco.Web.Trees if (string.IsNullOrEmpty(application)) throw new HttpResponseException(HttpStatusCode.NotFound); //find all tree definitions that have the current application alias - var groupedTrees = _treeService.GetGroupedTrees(application); + var groupedTrees = _treeService.GetBySectionGrouped(application); var allTrees = groupedTrees.Values.SelectMany(x => x).ToList(); if (string.IsNullOrEmpty(tree) == false || allTrees.Count == 1) diff --git a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs index cce40eb047..e3ecef2a0d 100644 --- a/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentBlueprintTreeController.cs @@ -18,9 +18,9 @@ namespace Umbraco.Web.Trees /// This authorizes based on access to the content section even though it exists in the settings /// [UmbracoApplicationAuthorize(Constants.Applications.Content)] - [Tree(Constants.Applications.Settings, Constants.Trees.ContentBlueprints, null, sortOrder: 12)] + [Tree(Constants.Applications.Settings, Constants.Trees.ContentBlueprints, SortOrder = 12, TreeGroup = Constants.Trees.Groups.Settings)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class ContentBlueprintTreeController : TreeController { diff --git a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs index 3c6b9c782c..a7544f71d2 100644 --- a/src/Umbraco.Web/Trees/ContentTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTypeTreeController.cs @@ -15,9 +15,9 @@ using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.DocumentTypes)] - [Tree(Constants.Applications.Settings, Constants.Trees.DocumentTypes, null, sortOrder: 0)] + [Tree(Constants.Applications.Settings, Constants.Trees.DocumentTypes, SortOrder = 0, TreeGroup = Constants.Trees.Groups.Settings)] [Mvc.PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class ContentTypeTreeController : TreeController, ISearchableTree { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/CoreTreeAttribute.cs b/src/Umbraco.Web/Trees/CoreTreeAttribute.cs index 1b485aea6a..2d6ffe6a15 100644 --- a/src/Umbraco.Web/Trees/CoreTreeAttribute.cs +++ b/src/Umbraco.Web/Trees/CoreTreeAttribute.cs @@ -3,19 +3,12 @@ namespace Umbraco.Web.Trees { /// - /// Indicates that a tree is a core tree and shouldn't be treated as a plugin tree + /// Indicates that a tree is a core tree and should not be treated as a plugin tree. /// /// - /// This ensures that umbraco will look in the umbraco folders for views for this tree + /// This ensures that umbraco will look in the umbraco folders for views for this tree. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] internal class CoreTreeAttribute : Attribute - { - public string TreeGroup { get; set; } - - public CoreTreeAttribute() - { - - } - } + { } } diff --git a/src/Umbraco.Web/Trees/DataTypeTreeController.cs b/src/Umbraco.Web/Trees/DataTypeTreeController.cs index 8b38bee865..c3b2fd631e 100644 --- a/src/Umbraco.Web/Trees/DataTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/DataTypeTreeController.cs @@ -17,9 +17,9 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.DataTypes)] - [Tree(Constants.Applications.Settings, Constants.Trees.DataTypes, null, sortOrder:3)] + [Tree(Constants.Applications.Settings, Constants.Trees.DataTypes, SortOrder = 3, TreeGroup = Constants.Trees.Groups.Settings)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class DataTypeTreeController : TreeController, ISearchableTree { protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) @@ -121,7 +121,7 @@ namespace Umbraco.Web.Trees }); if (container.HasChildren == false) - { + { //can delete data type menu.Items.Add(Services.TextService, opensDialog: true); } diff --git a/src/Umbraco.Web/Trees/DictionaryTreeController.cs b/src/Umbraco.Web/Trees/DictionaryTreeController.cs index 6c8f576732..6f8d4f547d 100644 --- a/src/Umbraco.Web/Trees/DictionaryTreeController.cs +++ b/src/Umbraco.Web/Trees/DictionaryTreeController.cs @@ -17,8 +17,8 @@ namespace Umbraco.Web.Trees // dictionary items in templates, even when we dont have authorization to manage the dictionary items )] [Mvc.PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] - [Tree(Constants.Applications.Translation, Constants.Trees.Dictionary, null)] + [CoreTree] + [Tree(Constants.Applications.Translation, Constants.Trees.Dictionary, TreeGroup = Constants.Trees.Groups.Settings)] public class DictionaryTreeController : TreeController { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/FilesTreeController.cs b/src/Umbraco.Web/Trees/FilesTreeController.cs index 947522747d..7e326870e3 100644 --- a/src/Umbraco.Web/Trees/FilesTreeController.cs +++ b/src/Umbraco.Web/Trees/FilesTreeController.cs @@ -1,14 +1,13 @@ -using Umbraco.Core; -using Umbraco.Core.IO; +using Umbraco.Core.IO; using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees { - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] - [Tree(Constants.Applications.Settings, "files", "Files", "icon-folder", "icon-folder", sortOrder: 13, initialize: false)] + // this is not a section tree - do not mark with [Tree] + [CoreTree] public class FilesTreeController : FileSystemTreeController { - protected override IFileSystem FileSystem => new PhysicalFileSystem("~/"); // fixme inject + protected override IFileSystem FileSystem => new PhysicalFileSystem("~/"); private static readonly string[] ExtensionsStatic = { "*" }; diff --git a/src/Umbraco.Web/Trees/ITree.cs b/src/Umbraco.Web/Trees/ITree.cs index 867beda20e..3427e4c40e 100644 --- a/src/Umbraco.Web/Trees/ITree.cs +++ b/src/Umbraco.Web/Trees/ITree.cs @@ -1,7 +1,7 @@ namespace Umbraco.Web.Trees { //fixme - we don't really use this, it is nice to have the treecontroller, attribute and ApplicationTree streamlined to implement this but it's not used - //leave as internal for now, maybe we'll use in the future, means we could pass around ITree + //leave as internal for now, maybe we'll use in the future, means we could pass around ITree internal interface ITree { /// @@ -13,7 +13,12 @@ /// /// Gets the section alias. /// - string ApplicationAlias { get; } + string SectionAlias { get; } + + /// + /// Gets the tree group. + /// + string TreeGroup { get; } /// /// Gets the tree alias. diff --git a/src/Umbraco.Web/Trees/LanguageTreeController.cs b/src/Umbraco.Web/Trees/LanguageTreeController.cs index 5b0ed8701f..ac2c0571e0 100644 --- a/src/Umbraco.Web/Trees/LanguageTreeController.cs +++ b/src/Umbraco.Web/Trees/LanguageTreeController.cs @@ -7,9 +7,9 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.Languages)] - [Tree(Constants.Applications.Settings, Constants.Trees.Languages, null, sortOrder: 11)] + [Tree(Constants.Applications.Settings, Constants.Trees.Languages, SortOrder = 11, TreeGroup = Constants.Trees.Groups.Settings)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class LanguageTreeController : TreeController { protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/MacrosTreeController.cs b/src/Umbraco.Web/Trees/MacrosTreeController.cs index 0300dbd6c6..77b13416ff 100644 --- a/src/Umbraco.Web/Trees/MacrosTreeController.cs +++ b/src/Umbraco.Web/Trees/MacrosTreeController.cs @@ -12,9 +12,9 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.Macros)] - [Tree(Constants.Applications.Settings, Constants.Trees.Macros, "Macros", sortOrder: 4)] + [Tree(Constants.Applications.Settings, Constants.Trees.Macros, TreeTitle = "Macros", SortOrder = 4, TreeGroup = Constants.Trees.Groups.Settings)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class MacrosTreeController : TreeController { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs index b93c1ac9e3..4a5ace0aeb 100644 --- a/src/Umbraco.Web/Trees/MediaTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTypeTreeController.cs @@ -16,9 +16,9 @@ using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.MediaTypes)] - [Tree(Constants.Applications.Settings, Constants.Trees.MediaTypes, null, sortOrder:1)] + [Tree(Constants.Applications.Settings, Constants.Trees.MediaTypes, SortOrder = 1, TreeGroup = Constants.Trees.Groups.Settings)] [Mvc.PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class MediaTypeTreeController : TreeController, ISearchableTree { protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/MemberGroupTreeController.cs b/src/Umbraco.Web/Trees/MemberGroupTreeController.cs index 9c8c8ea4e0..ea2412e4bd 100644 --- a/src/Umbraco.Web/Trees/MemberGroupTreeController.cs +++ b/src/Umbraco.Web/Trees/MemberGroupTreeController.cs @@ -8,7 +8,7 @@ using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.MemberGroups)] - [Tree(Constants.Applications.Members, Constants.Trees.MemberGroups, null, sortOrder: 1)] + [Tree(Constants.Applications.Members, Constants.Trees.MemberGroups, SortOrder = 1)] [Mvc.PluginController("UmbracoTrees")] [CoreTree] public class MemberGroupTreeController : MemberTypeAndGroupTreeControllerBase diff --git a/src/Umbraco.Web/Trees/MemberTreeController.cs b/src/Umbraco.Web/Trees/MemberTreeController.cs index d1219da466..03c68dd67a 100644 --- a/src/Umbraco.Web/Trees/MemberTreeController.cs +++ b/src/Umbraco.Web/Trees/MemberTreeController.cs @@ -26,7 +26,7 @@ namespace Umbraco.Web.Trees Constants.Applications.Content, Constants.Applications.Media, Constants.Applications.Members)] - [Tree(Constants.Applications.Members, Constants.Trees.Members, null, sortOrder: 0)] + [Tree(Constants.Applications.Members, Constants.Trees.Members, SortOrder = 0)] [PluginController("UmbracoTrees")] [CoreTree] [SearchableTree("searchResultFormatter", "configureMemberResult")] diff --git a/src/Umbraco.Web/Trees/MemberTypeTreeController.cs b/src/Umbraco.Web/Trees/MemberTypeTreeController.cs index 7bf04010f2..3a72460963 100644 --- a/src/Umbraco.Web/Trees/MemberTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/MemberTypeTreeController.cs @@ -7,9 +7,9 @@ using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Trees { - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] [UmbracoTreeAuthorize(Constants.Trees.MemberTypes)] - [Tree(Constants.Applications.Settings, Constants.Trees.MemberTypes, null, sortOrder: 2)] + [Tree(Constants.Applications.Settings, Constants.Trees.MemberTypes, SortOrder = 2, TreeGroup = Constants.Trees.Groups.Settings)] public class MemberTypeTreeController : MemberTypeAndGroupTreeControllerBase { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/PackagesTreeController.cs b/src/Umbraco.Web/Trees/PackagesTreeController.cs index 68b67f9fe2..9b1bf98823 100644 --- a/src/Umbraco.Web/Trees/PackagesTreeController.cs +++ b/src/Umbraco.Web/Trees/PackagesTreeController.cs @@ -8,7 +8,7 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.Packages)] - [Tree(Constants.Applications.Packages, Constants.Trees.Packages, null, sortOrder: 0, isSingleNodeTree: true)] + [Tree(Constants.Applications.Packages, Constants.Trees.Packages, SortOrder = 0, IsSingleNodeTree = true)] [PluginController("UmbracoTrees")] [CoreTree] public class PackagesTreeController : TreeController diff --git a/src/Umbraco.Web/Trees/PartialViewMacrosTreeController.cs b/src/Umbraco.Web/Trees/PartialViewMacrosTreeController.cs index c874b01244..dc107ad303 100644 --- a/src/Umbraco.Web/Trees/PartialViewMacrosTreeController.cs +++ b/src/Umbraco.Web/Trees/PartialViewMacrosTreeController.cs @@ -10,10 +10,10 @@ namespace Umbraco.Web.Trees /// /// Tree for displaying partial view macros in the developer app /// - [Tree(Constants.Applications.Settings, Constants.Trees.PartialViewMacros, null, sortOrder: 8)] + [Tree(Constants.Applications.Settings, Constants.Trees.PartialViewMacros, SortOrder = 8, TreeGroup = Constants.Trees.Groups.Templating)] [UmbracoTreeAuthorize(Constants.Trees.PartialViewMacros)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] + [CoreTree] public class PartialViewMacrosTreeController : PartialViewsTreeController { protected override IFileSystem FileSystem => Current.FileSystems.MacroPartialsFileSystem; diff --git a/src/Umbraco.Web/Trees/PartialViewsTreeController.cs b/src/Umbraco.Web/Trees/PartialViewsTreeController.cs index a7aa8f134e..60805d4dac 100644 --- a/src/Umbraco.Web/Trees/PartialViewsTreeController.cs +++ b/src/Umbraco.Web/Trees/PartialViewsTreeController.cs @@ -10,10 +10,10 @@ namespace Umbraco.Web.Trees /// /// Tree for displaying partial views in the settings app /// - [Tree(Constants.Applications.Settings, Constants.Trees.PartialViews, null, sortOrder: 7)] + [Tree(Constants.Applications.Settings, Constants.Trees.PartialViews, SortOrder = 7, TreeGroup = Constants.Trees.Groups.Templating)] [UmbracoTreeAuthorize(Constants.Trees.PartialViews)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] + [CoreTree] public class PartialViewsTreeController : FileSystemTreeController { protected override IFileSystem FileSystem => Current.FileSystems.PartialViewsFileSystem; diff --git a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs index 1888044d8d..82e07c5226 100644 --- a/src/Umbraco.Web/Trees/RelationTypeTreeController.cs +++ b/src/Umbraco.Web/Trees/RelationTypeTreeController.cs @@ -9,9 +9,9 @@ using Umbraco.Web.Actions; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.RelationTypes)] - [Tree(Constants.Applications.Settings, Constants.Trees.RelationTypes, null, sortOrder: 5)] + [Tree(Constants.Applications.Settings, Constants.Trees.RelationTypes, SortOrder = 5, TreeGroup = Constants.Trees.Groups.Settings)] [Mvc.PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Settings)] + [CoreTree] public class RelationTypeTreeController : TreeController { protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/ScriptsTreeController.cs b/src/Umbraco.Web/Trees/ScriptsTreeController.cs index cd56cc4790..bb002c7dda 100644 --- a/src/Umbraco.Web/Trees/ScriptsTreeController.cs +++ b/src/Umbraco.Web/Trees/ScriptsTreeController.cs @@ -5,8 +5,8 @@ using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees { - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] - [Tree(Constants.Applications.Settings, Constants.Trees.Scripts, "Scripts", "icon-folder", "icon-folder", sortOrder: 10)] + [CoreTree] + [Tree(Constants.Applications.Settings, Constants.Trees.Scripts, TreeTitle = "Scripts", IconOpen = "icon-folder", IconClosed = "icon-folder", SortOrder = 10, TreeGroup = Constants.Trees.Groups.Templating)] public class ScriptsTreeController : FileSystemTreeController { protected override IFileSystem FileSystem => Current.FileSystems.ScriptsFileSystem; // fixme inject diff --git a/src/Umbraco.Web/Trees/StylesheetsTreeController.cs b/src/Umbraco.Web/Trees/StylesheetsTreeController.cs index 548e8ae928..b47c225b2f 100644 --- a/src/Umbraco.Web/Trees/StylesheetsTreeController.cs +++ b/src/Umbraco.Web/Trees/StylesheetsTreeController.cs @@ -4,8 +4,8 @@ using Umbraco.Web.Composing; namespace Umbraco.Web.Trees { - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] - [Tree(Constants.Applications.Settings, Constants.Trees.Stylesheets, "Stylesheets", "icon-folder", "icon-folder", sortOrder: 9)] + [CoreTree] + [Tree(Constants.Applications.Settings, Constants.Trees.Stylesheets, TreeTitle = "Stylesheets", IconOpen = "icon-folder", IconClosed = "icon-folder", SortOrder = 9, TreeGroup = Constants.Trees.Groups.Templating)] public class StylesheetsTreeController : FileSystemTreeController { protected override IFileSystem FileSystem => Current.FileSystems.StylesheetsFileSystem; // fixme inject diff --git a/src/Umbraco.Web/Trees/TemplatesTreeController.cs b/src/Umbraco.Web/Trees/TemplatesTreeController.cs index c074f828d4..5db8c4b7cb 100644 --- a/src/Umbraco.Web/Trees/TemplatesTreeController.cs +++ b/src/Umbraco.Web/Trees/TemplatesTreeController.cs @@ -16,9 +16,9 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.Templates)] - [Tree(Constants.Applications.Settings, Constants.Trees.Templates, null, sortOrder:6)] + [Tree(Constants.Applications.Settings, Constants.Trees.Templates, SortOrder = 6, TreeGroup = Constants.Trees.Groups.Templating)] [PluginController("UmbracoTrees")] - [CoreTree(TreeGroup = Constants.Trees.Groups.Templating)] + [CoreTree] public class TemplatesTreeController : TreeController, ISearchableTree { protected override TreeNode CreateRootNode(FormDataCollection queryStrings) diff --git a/src/Umbraco.Web/Trees/Tree.cs b/src/Umbraco.Web/Trees/Tree.cs index 39f5cec1eb..b0a24e3b2b 100644 --- a/src/Umbraco.Web/Trees/Tree.cs +++ b/src/Umbraco.Web/Trees/Tree.cs @@ -1,46 +1,44 @@ using System; using System.Diagnostics; using Umbraco.Core.Services; -using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees { - [DebuggerDisplay("Tree - {TreeAlias} ({ApplicationAlias})")] + [DebuggerDisplay("Tree - {TreeAlias} ({SectionAlias})")] public class Tree : ITree { - public Tree(int sortOrder, string applicationAlias, string alias, string title, Type treeControllerType, bool isSingleNodeTree) + public Tree(int sortOrder, string applicationAlias, string group, string alias, string title, Type treeControllerType, bool isSingleNodeTree) { SortOrder = sortOrder; - ApplicationAlias = applicationAlias; + SectionAlias = applicationAlias; + TreeGroup = group; TreeAlias = alias; TreeTitle = title; TreeControllerType = treeControllerType; IsSingleNodeTree = isSingleNodeTree; } - + /// - /// - /// Gets or sets the sort order. - /// public int SortOrder { get; set; } - /// - /// Gets the application alias. - /// - public string ApplicationAlias { get; set; } + /// + public string SectionAlias { get; set; } + + /// + public string TreeGroup { get; } /// public string TreeAlias { get; } /// - /// - /// Gets or sets the tree title (fallback if the tree alias isn't localized) - /// - /// The title. public string TreeTitle { get; set; } + /// public bool IsSingleNodeTree { get; } + /// + /// Gets the tree controller type. + /// public Type TreeControllerType { get; } internal static string GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService) @@ -64,6 +62,5 @@ namespace Umbraco.Web.Trees return label; } - } } diff --git a/src/Umbraco.Web/Trees/TreeAttribute.cs b/src/Umbraco.Web/Trees/TreeAttribute.cs index dd63f8c172..bfd7b53f4a 100644 --- a/src/Umbraco.Web/Trees/TreeAttribute.cs +++ b/src/Umbraco.Web/Trees/TreeAttribute.cs @@ -1,10 +1,9 @@ using System; -using Umbraco.Web.Models.Trees; namespace Umbraco.Web.Trees { /// - /// Identifies an application tree + /// Identifies a section tree. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class TreeAttribute : Attribute, ITree @@ -12,54 +11,50 @@ namespace Umbraco.Web.Trees /// /// Initializes a new instance of the class. /// - /// The app alias. - /// - public TreeAttribute(string appAlias, - string treeAlias) : this(appAlias, treeAlias, null) + public TreeAttribute(string sectionAlias, string treeAlias) { - } - - /// - /// Initializes a new instance of the class. - /// - /// The app alias. - /// - /// - /// The icon closed. - /// The icon open. - /// if set to true [initialize]. - /// The sort order. - /// Flag to define if this tree is a single node tree (will never contain child nodes, full screen app) - public TreeAttribute(string appAlias, - string treeAlias, - string treeTitle, - string iconClosed = "icon-folder", - string iconOpen = "icon-folder-open", - bool initialize = true, - int sortOrder = 0, - bool isSingleNodeTree = false) - { - ApplicationAlias = appAlias; + SectionAlias = sectionAlias; TreeAlias = treeAlias; - TreeTitle = treeTitle; - IconClosed = iconClosed; - IconOpen = iconOpen; - Initialize = initialize; - SortOrder = sortOrder; - IsSingleNodeTree = isSingleNodeTree; } - public string ApplicationAlias { get; } - public string TreeAlias { get; } - public string TreeTitle { get; } - public string IconClosed { get; } - public string IconOpen { get; } - public bool Initialize { get; } - public int SortOrder { get; } + /// + /// Gets the section alias. + /// + public string SectionAlias { get; } /// - /// Flag to define if this tree is a single node tree (will never contain child nodes, full screen app) + /// Gets the tree alias. /// - public bool IsSingleNodeTree { get; } + public string TreeAlias { get; } + + /// + /// Gets or sets the tree title. + /// + public string TreeTitle { get; set; } + + /// + /// Gets or sets the group of the tree. + /// + public string TreeGroup { get; set; } + + /// + /// Gets or sets the tree icon when closed. + /// + public string IconClosed { get; set; } = "icon-folder"; + + /// + /// Gets or sets the tree icon when open. + /// + public string IconOpen { get; set; } = "icon-folder-open"; + + /// + /// Gets or sets the tree sort order. + /// + public int SortOrder { get; set; } + + /// + /// Gets or sets a value indicating whether the tree is a single-node tree (no child nodes, full screen app). + /// + public bool IsSingleNodeTree { get; set; } } } diff --git a/src/Umbraco.Web/Trees/TreeCollection.cs b/src/Umbraco.Web/Trees/TreeCollection.cs index a7bfe52295..76404d4ac5 100644 --- a/src/Umbraco.Web/Trees/TreeCollection.cs +++ b/src/Umbraco.Web/Trees/TreeCollection.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; using Umbraco.Core.Composing; -using Umbraco.Core.Models; -using Umbraco.Core.Models.ContentEditing; -using Umbraco.Web.Models.ContentEditing; namespace Umbraco.Web.Trees { + /// + /// Represents the collection of section trees. + /// public class TreeCollection : BuilderCollectionBase { public TreeCollection(IEnumerable items) diff --git a/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs b/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs index ae2675bac9..ad2a99a6c7 100644 --- a/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs +++ b/src/Umbraco.Web/Trees/TreeCollectionBuilder.cs @@ -1,17 +1,55 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using Umbraco.Core; using Umbraco.Core.Composing; namespace Umbraco.Web.Trees { + // todo + // this is a weird collection builder because it actually contains trees, not types + // and it does not really rely on DI to instantiate anything - but meh + // can we have trees that don't have a controller, or something? looks like, no + // and then, we should not register trees here, and only create them when creating + // the collection! + + /// + /// Builds a . + /// public class TreeCollectionBuilder : ICollectionBuilder { - /// - /// expose the list of trees which developers can manipulate before the collection is created - /// - public List Trees { get; } = new List(); + private readonly List _trees = new List(); - public TreeCollection CreateCollection(IFactory factory) => new TreeCollection(Trees); + public TreeCollection CreateCollection(IFactory factory) => new TreeCollection(_trees); public void RegisterWith(IRegister register) => register.Register(CreateCollection, Lifetime.Singleton); + + public void AddTreeController() + where TController : TreeControllerBase + => AddTreeController(typeof(TController)); + + public void AddTreeController(Type controllerType) + { + if (!typeof(TreeControllerBase).IsAssignableFrom(controllerType)) + throw new ArgumentException($"Type {controllerType} does not inherit from {typeof(TreeControllerBase).FullName}."); + + var attribute = controllerType.GetCustomAttribute(false); + if (attribute == null) return; // todo - shouldn't we throw or at least log? + var tree = new Tree(attribute.SortOrder, attribute.SectionAlias, attribute.TreeGroup, attribute.TreeAlias, attribute.TreeTitle, controllerType, attribute.IsSingleNodeTree); + _trees.Add(tree); + } + + public void AddTreeControllers(IEnumerable controllerTypes) + { + foreach (var controllerType in controllerTypes) + AddTreeController(controllerType); + } + + // todo - do we want to support this? + public void AddTree(Tree tree) + => _trees.Add(tree); + + // todo - do we want to support this? + public void AddTrees(IEnumerable tree) + => _trees.AddRange(tree); } } diff --git a/src/Umbraco.Web/Trees/TreeController.cs b/src/Umbraco.Web/Trees/TreeController.cs index 733c526331..bc9345eb1d 100644 --- a/src/Umbraco.Web/Trees/TreeController.cs +++ b/src/Umbraco.Web/Trees/TreeController.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Concurrent; -using System.Linq; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; @@ -15,53 +14,50 @@ namespace Umbraco.Web.Trees /// public abstract class TreeController : TreeControllerBase { - private TreeAttribute _attribute; + private static readonly ConcurrentDictionary TreeAttributeCache = new ConcurrentDictionary(); - protected TreeController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState) : base(globalSettings, umbracoContext, sqlContext, services, appCaches, logger, runtimeState) + private readonly TreeAttribute _treeAttribute; + + protected TreeController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState) + : base(globalSettings, umbracoContext, sqlContext, services, appCaches, logger, runtimeState) { - Initialize(); + _treeAttribute = GetTreeAttribute(); } protected TreeController() { - Initialize(); + _treeAttribute = GetTreeAttribute(); } /// public override string RootNodeDisplayName => Tree.GetRootNodeDisplayName(this, Services.TextService); /// - public override string TreeAlias => _attribute.TreeAlias; - /// - public override string TreeTitle => _attribute.TreeTitle; - /// - public override string ApplicationAlias => _attribute.ApplicationAlias; - /// - public override int SortOrder => _attribute.SortOrder; - /// - public override bool IsSingleNodeTree => _attribute.IsSingleNodeTree; + public override string TreeGroup => _treeAttribute.TreeGroup; - private void Initialize() - { - _attribute = GetTreeAttribute(); - } + /// + public override string TreeAlias => _treeAttribute.TreeAlias; - private static readonly ConcurrentDictionary TreeAttributeCache = new ConcurrentDictionary(); + /// + public override string TreeTitle => _treeAttribute.TreeTitle; + + /// + public override string SectionAlias => _treeAttribute.SectionAlias; + + /// + public override int SortOrder => _treeAttribute.SortOrder; + + /// + public override bool IsSingleNodeTree => _treeAttribute.IsSingleNodeTree; private TreeAttribute GetTreeAttribute() { return TreeAttributeCache.GetOrAdd(GetType(), type => { - //Locate the tree attribute - var treeAttributes = type - .GetCustomAttributes(false) - .ToArray(); - - if (treeAttributes.Length == 0) + var treeAttribute = type.GetCustomAttribute(false); + if (treeAttribute == null) throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute"); - - //assign the properties of this object to those of the metadata attribute - return treeAttributes[0]; + return treeAttribute; }); } } diff --git a/src/Umbraco.Web/Trees/TreeControllerBase.cs b/src/Umbraco.Web/Trees/TreeControllerBase.cs index d06d768f2d..e2e9c21c66 100644 --- a/src/Umbraco.Web/Trees/TreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/TreeControllerBase.cs @@ -2,7 +2,6 @@ using System.Globalization; using System.Linq; using System.Net.Http.Formatting; -using System.Web.Http.Routing; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration; @@ -19,7 +18,7 @@ using Umbraco.Web.WebApi.Filters; namespace Umbraco.Web.Trees { /// - /// A base controller reference for non-attributed trees (un-registered). + /// A base controller reference for non-attributed trees (un-registered). /// /// /// Developers should generally inherit from TreeController. @@ -28,13 +27,11 @@ namespace Umbraco.Web.Trees public abstract class TreeControllerBase : UmbracoAuthorizedApiController, ITree { protected TreeControllerBase() - { - } - - protected TreeControllerBase(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState) : base(globalSettings, umbracoContext, sqlContext, services, appCaches, logger, runtimeState) - { - } + { } + protected TreeControllerBase(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState) + : base(globalSettings, umbracoContext, sqlContext, services, appCaches, logger, runtimeState) + { } /// /// The method called to render the contents of the tree structure @@ -62,14 +59,21 @@ namespace Umbraco.Web.Trees /// public abstract string RootNodeDisplayName { get; } + /// + public abstract string TreeGroup { get; } + /// public abstract string TreeAlias { get; } + /// public abstract string TreeTitle { get; } + /// - public abstract string ApplicationAlias { get; } + public abstract string SectionAlias { get; } + /// public abstract int SortOrder { get; } + /// public abstract bool IsSingleNodeTree { get; } @@ -402,5 +406,4 @@ namespace Umbraco.Web.Trees handler?.Invoke(instance, e); } } - } diff --git a/src/Umbraco.Web/Trees/UserTreeController.cs b/src/Umbraco.Web/Trees/UserTreeController.cs index 95f041cac5..91078b2be8 100644 --- a/src/Umbraco.Web/Trees/UserTreeController.cs +++ b/src/Umbraco.Web/Trees/UserTreeController.cs @@ -7,7 +7,7 @@ using Constants = Umbraco.Core.Constants; namespace Umbraco.Web.Trees { [UmbracoTreeAuthorize(Constants.Trees.Users)] - [Tree(Constants.Applications.Users, Constants.Trees.Users, null, sortOrder: 0, isSingleNodeTree: true)] + [Tree(Constants.Applications.Users, Constants.Trees.Users, SortOrder = 0, IsSingleNodeTree = true)] [PluginController("UmbracoTrees")] [CoreTree] public class UserTreeController : TreeController diff --git a/src/Umbraco.Web/TypeLoaderExtensions.cs b/src/Umbraco.Web/TypeLoaderExtensions.cs index 4d09783ca9..1cf8bc124c 100644 --- a/src/Umbraco.Web/TypeLoaderExtensions.cs +++ b/src/Umbraco.Web/TypeLoaderExtensions.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; -using Umbraco.Core.Media; using Umbraco.Web.Mvc; -using Umbraco.Web.Trees; using Umbraco.Web.WebApi; using Umbraco.Core.Composing; @@ -10,29 +8,20 @@ using Umbraco.Core.Composing; namespace Umbraco.Web { /// - /// Extension methods for the PluginTypemgr + /// Provides extension methods for the class. /// public static class TypeLoaderExtensions { /// - /// Returns all available TreeApiController's in application that are attribute with TreeAttribute + /// Gets all types implementing . /// - /// - /// - internal static IEnumerable GetAttributedTreeControllers(this TypeLoader mgr) - { - return mgr.GetTypesWithAttribute(); - } + internal static IEnumerable GetSurfaceControllers(this TypeLoader typeLoader) + => typeLoader.GetTypes(); - internal static IEnumerable GetSurfaceControllers(this TypeLoader mgr) - { - return mgr.GetTypes(); - } - - internal static IEnumerable GetUmbracoApiControllers(this TypeLoader mgr) - { - return mgr.GetTypes(); - } - + /// + /// Gets all types implementing . + /// + internal static IEnumerable GetUmbracoApiControllers(this TypeLoader typeLoader) + => typeLoader.GetTypes(); } } diff --git a/src/Umbraco.Web/UI/Pages/UmbracoEnsuredPage.cs b/src/Umbraco.Web/UI/Pages/UmbracoEnsuredPage.cs index cafdfb0e04..f1b2cda368 100644 --- a/src/Umbraco.Web/UI/Pages/UmbracoEnsuredPage.cs +++ b/src/Umbraco.Web/UI/Pages/UmbracoEnsuredPage.cs @@ -33,7 +33,7 @@ namespace Umbraco.Web.UI.Pages .GetByAlias(treeAuth.TreeAlias); if (treeByAlias != null) { - CurrentApp = treeByAlias.ApplicationAlias; + CurrentApp = treeByAlias.SectionAlias; } } } diff --git a/src/Umbraco.Web/WebApi/Filters/UmbracoTreeAuthorizeAttribute.cs b/src/Umbraco.Web/WebApi/Filters/UmbracoTreeAuthorizeAttribute.cs index 5ad3da7f4d..1bea963ee1 100644 --- a/src/Umbraco.Web/WebApi/Filters/UmbracoTreeAuthorizeAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/UmbracoTreeAuthorizeAttribute.cs @@ -44,7 +44,7 @@ namespace Umbraco.Web.WebApi.Filters var apps = _treeAliases.Select(x => Current.TreeService .GetByAlias(x)) .WhereNotNull() - .Select(x => x.ApplicationAlias) + .Select(x => x.SectionAlias) .Distinct() .ToArray();