From 9dc34f0c98720bd144577d565eec75e55a09a80c Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 20 Jun 2017 18:38:31 +1000 Subject: [PATCH] Updating a bunch of start node checking logic to ensure that it takes the user and user group start nodes into account --- .../Models/Identity/BackOfficeIdentityUser.cs | 8 ++++++++ src/Umbraco.Web/Editors/EntityController.cs | 4 ++-- src/Umbraco.Web/Trees/ContentTreeController.cs | 12 +++++++----- src/Umbraco.Web/Trees/MediaTreeController.cs | 7 ++++--- .../Filters/FilterAllowedOutgoingContentAttribute.cs | 3 ++- src/umbraco.businesslogic/BasePages/BasePage.cs | 5 +++-- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs index 8657bc4c6c..ae046edce9 100644 --- a/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs +++ b/src/Umbraco.Core/Models/Identity/BackOfficeIdentityUser.cs @@ -33,7 +33,15 @@ namespace Umbraco.Core.Models.Identity /// Gets/sets the user's real name /// public string Name { get; set; } + + /// + /// Content start nodes assigned to the User (not ones assigned to the user's groups) + /// public int[] StartContentIds { get; set; } + + /// + /// Media start nodes assigned to the User (not ones assigned to the user's groups) + /// public int[] StartMediaIds { get; set; } public string[] AllowedSections { get; set; } public string[] Groups { get; set; } diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index e16d6da67a..4438a4d9dc 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -667,14 +667,14 @@ namespace Umbraco.Web.Editors type = "media"; AddExamineSearchFrom(searchFrom, sb); - AddExamineUserStartNode(Security.CurrentUser.StartMediaIds, sb); + AddExamineUserStartNode(Security.CurrentUser.GetCombinedStartMediaIds().ToArray(), sb); break; case UmbracoEntityTypes.Document: type = "content"; AddExamineSearchFrom(searchFrom, sb); - AddExamineUserStartNode(Security.CurrentUser.StartContentIds, sb); + AddExamineUserStartNode(Security.CurrentUser.GetCombinedStartContentIds().ToArray(), sb); break; default: diff --git a/src/Umbraco.Web/Trees/ContentTreeController.cs b/src/Umbraco.Web/Trees/ContentTreeController.cs index 076c7b093a..eb7f091a18 100644 --- a/src/Umbraco.Web/Trees/ContentTreeController.cs +++ b/src/Umbraco.Web/Trees/ContentTreeController.cs @@ -40,9 +40,10 @@ namespace Umbraco.Web.Trees protected override TreeNode CreateRootNode(FormDataCollection queryStrings) { - var node = base.CreateRootNode(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.StartContentIds.Length > 0 && Security.CurrentUser.StartContentIds.Contains(Constants.System.Root) == false) + if (UserStartNodes.Length > 0 && UserStartNodes.Contains(Constants.System.Root) == false) { node.MenuUrl = ""; } @@ -60,9 +61,10 @@ namespace Umbraco.Web.Trees get { return Services.ContentService.RecycleBinSmells(); } } + private int[] _userStartNodes; protected override int[] UserStartNodes { - get { return Security.CurrentUser.StartContentIds; } + get { return _userStartNodes ?? (_userStartNodes = Security.CurrentUser.GetCombinedStartContentIds().ToArray()); } } /// @@ -119,9 +121,9 @@ namespace Umbraco.Web.Trees if (id == Constants.System.Root.ToInvariantString()) { 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.StartContentIds.Length > 0 && Security.CurrentUser.StartContentIds.Contains(Constants.System.Root) == false) + if (UserStartNodes.Length > 0 && UserStartNodes.Contains(Constants.System.Root) == false) { return menu; } diff --git a/src/Umbraco.Web/Trees/MediaTreeController.cs b/src/Umbraco.Web/Trees/MediaTreeController.cs index 068d6641b0..5f36c3de20 100644 --- a/src/Umbraco.Web/Trees/MediaTreeController.cs +++ b/src/Umbraco.Web/Trees/MediaTreeController.cs @@ -35,7 +35,7 @@ namespace Umbraco.Web.Trees { 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.StartMediaIds.Length > 0 && Security.CurrentUser.StartMediaIds.Contains(Constants.System.Root) == false) + if (UserStartNodes.Length > 0 && UserStartNodes.Contains(Constants.System.Root) == false) { node.MenuUrl = ""; } @@ -53,9 +53,10 @@ namespace Umbraco.Web.Trees get { return Services.MediaService.RecycleBinSmells(); } } + private int[] _userStartNodes; protected override int[] UserStartNodes { - get { return Security.CurrentUser.StartMediaIds; } + get { return _userStartNodes ?? (_userStartNodes = Security.CurrentUser.GetCombinedStartMediaIds().ToArray()); } } /// @@ -100,7 +101,7 @@ 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.StartMediaIds.Length > 0 && Security.CurrentUser.StartMediaIds.Contains(Constants.System.Root) == false) + if (UserStartNodes.Length > 0 && UserStartNodes.Contains(Constants.System.Root) == false) { return menu; } diff --git a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs index 3ae70ac5e8..7429e52897 100644 --- a/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs +++ b/src/Umbraco.Web/WebApi/Filters/FilterAllowedOutgoingContentAttribute.cs @@ -8,6 +8,7 @@ using Umbraco.Core.Models.Membership; using Umbraco.Core.Services; using umbraco.BusinessLogic.Actions; using Umbraco.Core; +using Umbraco.Core.Models; namespace Umbraco.Web.WebApi.Filters { @@ -46,7 +47,7 @@ namespace Umbraco.Web.WebApi.Filters protected override int[] GetUserStartNodes(IUser user) { - return user.StartContentIds; + return user.GetCombinedStartContentIds().ToArray(); } protected override int RecycleBinId diff --git a/src/umbraco.businesslogic/BasePages/BasePage.cs b/src/umbraco.businesslogic/BasePages/BasePage.cs index eb43857b45..d708ce78a3 100644 --- a/src/umbraco.businesslogic/BasePages/BasePage.cs +++ b/src/umbraco.businesslogic/BasePages/BasePage.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Services; using umbraco.BusinessLogic; using umbraco.DataLayer; using Umbraco.Core; +using Umbraco.Core.Models; using Umbraco.Core.Security; namespace umbraco.BasePages @@ -294,8 +295,8 @@ namespace umbraco.BasePages RealName = u.Name, //currently we only have one user type! Roles = u.GetGroups(), - StartContentNodes = u.UserEntity.StartContentIds, - StartMediaNodes = u.UserEntity.StartMediaIds, + StartContentNodes = u.UserEntity.GetCombinedStartContentIds().ToArray(), + StartMediaNodes = u.UserEntity.GetCombinedStartMediaIds().ToArray(), Username = u.LoginName, Culture = ui.Culture(u)