Merge pull request #9999 from umbraco/v8/feature/AB10891-content-dashboard-config

Granting access to the content dashboard for all user groups
This commit is contained in:
Mole
2021-03-25 12:03:33 +01:00
committed by GitHub
9 changed files with 105 additions and 9 deletions

View File

@@ -1,10 +1,10 @@
using System.IO;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
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;
@@ -48,6 +48,8 @@ namespace Umbraco.Core
configDir,
factory.GetInstance<ManifestParser>(),
factory.GetInstance<IRuntimeState>().Debug));
configs.Add<IContentDashboardSettings>(() => new ContentDashboardSettings());
}
}
}

View File

@@ -395,7 +395,6 @@ namespace Umbraco.Core.Configuration
}
}
/// <summary>
/// An int value representing the time in milliseconds to lock the database for a write operation
/// </summary>

View File

@@ -110,6 +110,11 @@ namespace Umbraco.Core
/// </summary>
public const string UseHttps = "Umbraco.Core.UseHttps";
/// <summary>
/// A true/false value indicating whether the content dashboard should be visible for all user groups.
/// </summary>
public const string AllowContentDashboardAccessToAllUsers = "Umbraco.Core.AllowContentDashboardAccessToAllUsers";
/// <summary>
/// TODO: FILL ME IN
/// </summary>

View File

@@ -0,0 +1,24 @@
using System.Configuration;
namespace Umbraco.Core.Dashboards
{
public class ContentDashboardSettings: IContentDashboardSettings
{
/// <summary>
/// Gets a value indicating whether the content dashboard should be available to all users.
/// </summary>
/// <value>
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
/// and the default access rules for that dashboard will be in use.
/// </value>
public bool AllowContentDashboardAccessToAllUsers
{
get
{
bool.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.AllowContentDashboardAccessToAllUsers], out var value);
return value;
}
}
}
}

View File

@@ -0,0 +1,14 @@
namespace Umbraco.Core.Dashboards
{
public interface IContentDashboardSettings
{
/// <summary>
/// Gets a value indicating whether the content dashboard should be available to all users.
/// </summary>
/// <value>
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
/// and the default access rules for that dashboard will be in use.
/// </value>
bool AllowContentDashboardAccessToAllUsers { get; }
}
}

View File

@@ -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" />

View File

@@ -37,6 +37,7 @@
<add key="Umbraco.Core.TimeOutInMinutes" value="20" />
<add key="Umbraco.Core.DefaultUILanguage" value="en-US" />
<add key="Umbraco.Core.UseHttps" value="false" />
<add key="Umbraco.Core.AllowContentDashboardAccessToAllUsers" value="true"/>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
<add key="webpages:Enabled" value="false" />

View File

@@ -1,15 +1,21 @@
using Umbraco.Core;
using System.Collections.Generic;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Services;
namespace Umbraco.Web.Dashboards
{
[Weight(10)]
public class ContentDashboard : IDashboard
{
private readonly IContentDashboardSettings _dashboardSettings;
private readonly IUserService _userService;
private IAccessRule[] _accessRulesFromConfig;
public string Alias => "contentIntro";
public string[] Sections => new [] { "content" };
public string[] Sections => new[] { "content" };
public string View => "views/dashboard/default/startupdashboardintro.html";
@@ -17,13 +23,54 @@ namespace Umbraco.Web.Dashboards
{
get
{
var rules = new IAccessRule[]
var rules = AccessRulesFromConfig;
if (rules.Length == 0)
{
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
};
rules = new IAccessRule[]
{
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
};
}
return rules;
}
}
private IAccessRule[] AccessRulesFromConfig
{
get
{
if (_accessRulesFromConfig is null)
{
var rules = new List<IAccessRule>();
if (_dashboardSettings.AllowContentDashboardAccessToAllUsers)
{
var allUserGroups = _userService.GetAllUserGroups();
foreach (var userGroup in allUserGroups)
{
rules.Add(new AccessRule
{
Type = AccessRuleType.Grant,
Value = userGroup.Alias
});
}
}
_accessRulesFromConfig = rules.ToArray();
}
return _accessRulesFromConfig;
}
}
public ContentDashboard(IContentDashboardSettings dashboardSettings, IUserService userService)
{
_dashboardSettings = dashboardSettings;
_userService = userService;
}
}
}

View File

@@ -17,6 +17,7 @@ using Umbraco.Core.Logging;
using Umbraco.Core.Persistence;
using Umbraco.Core.Services;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Models;
using Umbraco.Web.Services;
namespace Umbraco.Web.Editors
@@ -52,8 +53,9 @@ namespace Umbraco.Web.Editors
var allowedSections = string.Join(",", user.AllowedSections);
var language = user.Language;
var version = UmbracoVersion.SemanticVersion.ToSemanticString();
var isAdmin = user.IsAdmin();
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}", section, allowedSections, language, version);
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}&admin={4}", section, allowedSections, language, version, isAdmin);
var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section;
var content = AppCaches.RuntimeCache.GetCacheItem<JObject>(key);