Skip to content

Commit 499e4f0

Browse files
Merge pull request #9999 from umbraco/v8/feature/AB10891-content-dashboard-config
Granting access to the content dashboard for all user groups
2 parents bfc3068 + f68d4d6 commit 499e4f0

File tree

9 files changed

+105
-9
lines changed

9 files changed

+105
-9
lines changed

src/Umbraco.Core/ConfigsExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.IO;
22
using Umbraco.Core.Cache;
3-
using Umbraco.Core.Composing;
43
using Umbraco.Core.Configuration;
54
using Umbraco.Core.Configuration.Grid;
65
using Umbraco.Core.Configuration.HealthChecks;
76
using Umbraco.Core.Configuration.UmbracoSettings;
7+
using Umbraco.Core.Dashboards;
88
using Umbraco.Core.IO;
99
using Umbraco.Core.Logging;
1010
using Umbraco.Core.Manifest;
@@ -48,6 +48,8 @@ public static void AddCoreConfigs(this Configs configs)
4848
configDir,
4949
factory.GetInstance<ManifestParser>(),
5050
factory.GetInstance<IRuntimeState>().Debug));
51+
52+
configs.Add<IContentDashboardSettings>(() => new ContentDashboardSettings());
5153
}
5254
}
5355
}

src/Umbraco.Core/Configuration/GlobalSettings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ public bool UseHttps
395395
}
396396
}
397397

398-
399398
/// <summary>
400399
/// An int value representing the time in milliseconds to lock the database for a write operation
401400
/// </summary>

src/Umbraco.Core/Constants-AppSettings.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ public static class AppSettings
110110
/// </summary>
111111
public const string UseHttps = "Umbraco.Core.UseHttps";
112112

113+
/// <summary>
114+
/// A true/false value indicating whether the content dashboard should be visible for all user groups.
115+
/// </summary>
116+
public const string AllowContentDashboardAccessToAllUsers = "Umbraco.Core.AllowContentDashboardAccessToAllUsers";
117+
113118
/// <summary>
114119
/// TODO: FILL ME IN
115120
/// </summary>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Configuration;
2+
3+
namespace Umbraco.Core.Dashboards
4+
{
5+
public class ContentDashboardSettings: IContentDashboardSettings
6+
{
7+
8+
/// <summary>
9+
/// Gets a value indicating whether the content dashboard should be available to all users.
10+
/// </summary>
11+
/// <value>
12+
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
13+
/// and the default access rules for that dashboard will be in use.
14+
/// </value>
15+
public bool AllowContentDashboardAccessToAllUsers
16+
{
17+
get
18+
{
19+
bool.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.AllowContentDashboardAccessToAllUsers], out var value);
20+
return value;
21+
}
22+
}
23+
}
24+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Umbraco.Core.Dashboards
2+
{
3+
public interface IContentDashboardSettings
4+
{
5+
/// <summary>
6+
/// Gets a value indicating whether the content dashboard should be available to all users.
7+
/// </summary>
8+
/// <value>
9+
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
10+
/// and the default access rules for that dashboard will be in use.
11+
/// </value>
12+
bool AllowContentDashboardAccessToAllUsers { get; }
13+
}
14+
}

src/Umbraco.Core/Umbraco.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@
131131
<Compile Include="Constants-CharArrays.cs" />
132132
<Compile Include="Collections\EventClearingObservableCollection.cs" />
133133
<Compile Include="Constants-SqlTemplates.cs" />
134+
<Compile Include="Dashboards\ContentDashboardSettings.cs" />
135+
<Compile Include="Dashboards\IContentDashboardSettings.cs" />
134136
<Compile Include="Exceptions\UnattendedInstallException.cs" />
135137
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\ContentTypeDto80.cs" />
136138
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyDataDto80.cs" />

src/Umbraco.Web.UI/web.Template.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<add key="Umbraco.Core.TimeOutInMinutes" value="20" />
3838
<add key="Umbraco.Core.DefaultUILanguage" value="en-US" />
3939
<add key="Umbraco.Core.UseHttps" value="false" />
40+
<add key="Umbraco.Core.AllowContentDashboardAccessToAllUsers" value="true"/>
4041

4142
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
4243
<add key="webpages:Enabled" value="false" />
Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,76 @@
1-
using Umbraco.Core;
1+
using System.Collections.Generic;
2+
using Umbraco.Core;
23
using Umbraco.Core.Composing;
34
using Umbraco.Core.Dashboards;
5+
using Umbraco.Core.Services;
46

57
namespace Umbraco.Web.Dashboards
68
{
79
[Weight(10)]
810
public class ContentDashboard : IDashboard
911
{
12+
private readonly IContentDashboardSettings _dashboardSettings;
13+
private readonly IUserService _userService;
14+
private IAccessRule[] _accessRulesFromConfig;
15+
1016
public string Alias => "contentIntro";
1117

12-
public string[] Sections => new [] { "content" };
18+
public string[] Sections => new[] { "content" };
1319

1420
public string View => "views/dashboard/default/startupdashboardintro.html";
1521

1622
public IAccessRule[] AccessRules
1723
{
1824
get
1925
{
20-
var rules = new IAccessRule[]
26+
var rules = AccessRulesFromConfig;
27+
28+
if (rules.Length == 0)
2129
{
22-
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
23-
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
24-
};
30+
rules = new IAccessRule[]
31+
{
32+
new AccessRule {Type = AccessRuleType.Deny, Value = Constants.Security.TranslatorGroupAlias},
33+
new AccessRule {Type = AccessRuleType.Grant, Value = Constants.Security.AdminGroupAlias}
34+
};
35+
}
36+
2537
return rules;
2638
}
2739
}
40+
41+
private IAccessRule[] AccessRulesFromConfig
42+
{
43+
get
44+
{
45+
if (_accessRulesFromConfig is null)
46+
{
47+
var rules = new List<IAccessRule>();
48+
49+
if (_dashboardSettings.AllowContentDashboardAccessToAllUsers)
50+
{
51+
var allUserGroups = _userService.GetAllUserGroups();
52+
53+
foreach (var userGroup in allUserGroups)
54+
{
55+
rules.Add(new AccessRule
56+
{
57+
Type = AccessRuleType.Grant,
58+
Value = userGroup.Alias
59+
});
60+
}
61+
}
62+
63+
_accessRulesFromConfig = rules.ToArray();
64+
}
65+
66+
return _accessRulesFromConfig;
67+
}
68+
}
69+
70+
public ContentDashboard(IContentDashboardSettings dashboardSettings, IUserService userService)
71+
{
72+
_dashboardSettings = dashboardSettings;
73+
_userService = userService;
74+
}
2875
}
2976
}

src/Umbraco.Web/Editors/DashboardController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Umbraco.Core.Persistence;
1818
using Umbraco.Core.Services;
1919
using Umbraco.Core.Dashboards;
20+
using Umbraco.Core.Models;
2021
using Umbraco.Web.Services;
2122

2223
namespace Umbraco.Web.Editors
@@ -52,8 +53,9 @@ public async Task<JObject> GetRemoteDashboardContent(string section, string base
5253
var allowedSections = string.Join(",", user.AllowedSections);
5354
var language = user.Language;
5455
var version = UmbracoVersion.SemanticVersion.ToSemanticString();
56+
var isAdmin = user.IsAdmin();
5557

56-
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}", section, allowedSections, language, version);
58+
var url = string.Format(baseUrl + "{0}?section={0}&allowed={1}&lang={2}&version={3}&admin={4}", section, allowedSections, language, version, isAdmin);
5759
var key = "umbraco-dynamic-dashboard-" + language + allowedSections.Replace(",", "-") + section;
5860

5961
var content = AppCaches.RuntimeCache.GetCacheItem<JObject>(key);

0 commit comments

Comments
 (0)