diff --git a/src/Umbraco.Core/ConfigsExtensions.cs b/src/Umbraco.Core/ConfigsExtensions.cs index d1672c6c7f..17dc63943a 100644 --- a/src/Umbraco.Core/ConfigsExtensions.cs +++ b/src/Umbraco.Core/ConfigsExtensions.cs @@ -5,9 +5,11 @@ using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.Grid; using Umbraco.Core.Configuration.HealthChecks; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.Dashboards; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Manifest; +using Umbraco.Core.Services; namespace Umbraco.Core { @@ -48,6 +50,10 @@ namespace Umbraco.Core configDir, factory.GetInstance(), factory.GetInstance().Debug)); + + configs.Add(factory => + new ContentDashboardSettings(factory.GetInstance(), + factory.GetInstance())); } } } diff --git a/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs b/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs new file mode 100644 index 0000000000..3db808fe02 --- /dev/null +++ b/src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Umbraco.Core.Configuration; +using Umbraco.Core.Services; + +namespace Umbraco.Core.Dashboards +{ + public class ContentDashboardSettings: IContentDashboardSettings + { + private readonly IGlobalSettings _globalSettings; + private readonly IUserService _userService; + + public ContentDashboardSettings(IGlobalSettings globalSettings, IUserService userService) + { + _globalSettings = globalSettings; + _userService = userService; + } + + public IAccessRule[] GetAccessRulesFromConfig() + { + var rules = new List(); + + if (_globalSettings.AllowContentDashboardAccessToAllUsers) + { + var allUserGroups = _userService.GetAllUserGroups(); + + foreach (var userGroup in allUserGroups) + { + rules.Add(new AccessRule + { + Type = AccessRuleType.Grant, + Value = userGroup.Alias + }); + } + } + + return rules.ToArray(); + } + } +} diff --git a/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs b/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs new file mode 100644 index 0000000000..9b5ea7d7dd --- /dev/null +++ b/src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Umbraco.Core.Dashboards +{ + public interface IContentDashboardSettings + { + IAccessRule[] GetAccessRulesFromConfig(); + } +} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 832b8a5801..63c7ac178d 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -131,6 +131,8 @@ + + diff --git a/src/Umbraco.Web/Dashboards/ContentDashboard.cs b/src/Umbraco.Web/Dashboards/ContentDashboard.cs index 3dbc0cb693..4b17bcf7ff 100644 --- a/src/Umbraco.Web/Dashboards/ContentDashboard.cs +++ b/src/Umbraco.Web/Dashboards/ContentDashboard.cs @@ -10,6 +10,7 @@ namespace Umbraco.Web.Dashboards [Weight(10)] public class ContentDashboard : IDashboard { + private readonly IContentDashboardSettings _dashboardSettings; public string Alias => "contentIntro"; public string[] Sections => new[] { "content" }; @@ -20,15 +21,9 @@ namespace Umbraco.Web.Dashboards { get { - IAccessRule[] rules; - var dashboardConfig = Path.Combine(IOHelper.MapPath(SystemDirectories.Config), "content.dashboard.access.config.js"); + var rules = _dashboardSettings.GetAccessRulesFromConfig(); - if (File.Exists(dashboardConfig)) - { - var rawJson = File.ReadAllText(dashboardConfig); - rules = JsonConvert.DeserializeObject(rawJson); - } - else + if (rules.Length == 0) { rules = new IAccessRule[] { @@ -36,8 +31,14 @@ namespace Umbraco.Web.Dashboards new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias} }; } + return rules; } } + + public ContentDashboard(IContentDashboardSettings dashboardSettings) + { + _dashboardSettings = dashboardSettings; + } } }