Implementation for IContentDashboardSettings
This commit is contained in:
@@ -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<ManifestParser>(),
|
||||
factory.GetInstance<IRuntimeState>().Debug));
|
||||
|
||||
configs.Add<IContentDashboardSettings>(factory =>
|
||||
new ContentDashboardSettings(factory.GetInstance<IGlobalSettings>(),
|
||||
factory.GetInstance<IUserService>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
43
src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs
Normal file
43
src/Umbraco.Core/Dashboards/ContentDashboardSettings.cs
Normal file
@@ -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<IAccessRule>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs
Normal file
13
src/Umbraco.Core/Dashboards/IContentDashboardSettings.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -131,6 +131,8 @@
|
||||
<Compile Include="Constants-CharArrays.cs" />
|
||||
<Compile Include="Collections\EventClearingObservableCollection.cs" />
|
||||
<Compile Include="Constants-SqlTemplates.cs" />
|
||||
<Compile Include="Dashboards\ContentDashboardSettings.cs" />
|
||||
<Compile Include="Dashboards\IContentDashboardSettings.cs" />
|
||||
<Compile Include="Exceptions\UnattendedInstallException.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\ContentTypeDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyDataDto80.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<AccessRule[]>(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user