Skip to content

Commit f68d4d6

Browse files
committed
Taking AllowContentDashboardAccessToAllUsers prop from GlobalSettings to ContentDashboardSettings and saving AccessRulesFromConfig into a backing field
1 parent 56d5704 commit f68d4d6

File tree

6 files changed

+59
-74
lines changed

6 files changed

+59
-74
lines changed

src/Umbraco.Core/ConfigsExtensions.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Umbraco.Core.IO;
99
using Umbraco.Core.Logging;
1010
using Umbraco.Core.Manifest;
11-
using Umbraco.Core.Services;
1211

1312
namespace Umbraco.Core
1413
{
@@ -50,9 +49,7 @@ public static void AddCoreConfigs(this Configs configs)
5049
factory.GetInstance<ManifestParser>(),
5150
factory.GetInstance<IRuntimeState>().Debug));
5251

53-
configs.Add<IContentDashboardSettings>(factory =>
54-
new ContentDashboardSettings(factory.GetInstance<IGlobalSettings>(),
55-
factory.GetInstance<IUserService>()));
52+
configs.Add<IContentDashboardSettings>(() => new ContentDashboardSettings());
5653
}
5754
}
5855
}

src/Umbraco.Core/Configuration/GlobalSettings.cs

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

398-
/// <summary>
399-
/// Gets a value indicating whether the content dashboard should be available to all users.
400-
/// </summary>
401-
/// <value>
402-
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
403-
/// and the default access rules for that dashboard will be in use.
404-
/// </value>
405-
public bool AllowContentDashboardAccessToAllUsers
406-
{
407-
get
408-
{
409-
bool.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.AllowContentDashboardAccessToAllUsers], out var value);
410-
return value;
411-
}
412-
}
413-
414-
415398
/// <summary>
416399
/// An int value representing the time in milliseconds to lock the database for a write operation
417400
/// </summary>

src/Umbraco.Core/Configuration/IGlobalSettings.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ public interface IGlobalSettings
5757
/// </summary>
5858
bool UseHttps { get; }
5959

60-
/// <summary>
61-
/// Gets a value indicating whether the content dashboard should be available to all users.
62-
/// </summary>
63-
/// <value>
64-
/// <c>true</c> if the dashboard is visible for all user groups; otherwise, <c>false</c>
65-
/// and the default access rules for that dashboard will be in use.
66-
/// </value>
67-
bool AllowContentDashboardAccessToAllUsers { get; }
68-
6960
/// <summary>
7061
/// Returns a string value to determine if umbraco should skip version-checking.
7162
/// </summary>
Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,24 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Umbraco.Core.Configuration;
7-
using Umbraco.Core.Services;
1+
using System.Configuration;
82

93
namespace Umbraco.Core.Dashboards
104
{
115
public class ContentDashboardSettings: IContentDashboardSettings
126
{
13-
private readonly IGlobalSettings _globalSettings;
14-
private readonly IUserService _userService;
157

16-
public ContentDashboardSettings(IGlobalSettings globalSettings, IUserService userService)
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
1716
{
18-
_globalSettings = globalSettings;
19-
_userService = userService;
20-
}
21-
22-
public IAccessRule[] GetAccessRulesFromConfig()
23-
{
24-
var rules = new List<IAccessRule>();
25-
26-
if (_globalSettings.AllowContentDashboardAccessToAllUsers)
17+
get
2718
{
28-
var allUserGroups = _userService.GetAllUserGroups();
29-
30-
foreach (var userGroup in allUserGroups)
31-
{
32-
rules.Add(new AccessRule
33-
{
34-
Type = AccessRuleType.Grant,
35-
Value = userGroup.Alias
36-
});
37-
}
19+
bool.TryParse(ConfigurationManager.AppSettings[Constants.AppSettings.AllowContentDashboardAccessToAllUsers], out var value);
20+
return value;
3821
}
39-
40-
return rules.ToArray();
4122
}
4223
}
4324
}
Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
7-
namespace Umbraco.Core.Dashboards
1+
namespace Umbraco.Core.Dashboards
82
{
93
public interface IContentDashboardSettings
104
{
11-
IAccessRule[] GetAccessRulesFromConfig();
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; }
1213
}
1314
}

src/Umbraco.Web/Dashboards/ContentDashboard.cs

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
using System.IO;
2-
using Newtonsoft.Json;
1+
using System.Collections.Generic;
32
using Umbraco.Core;
43
using Umbraco.Core.Composing;
54
using Umbraco.Core.Dashboards;
6-
using Umbraco.Core.IO;
5+
using Umbraco.Core.Services;
76

87
namespace Umbraco.Web.Dashboards
98
{
109
[Weight(10)]
1110
public class ContentDashboard : IDashboard
1211
{
1312
private readonly IContentDashboardSettings _dashboardSettings;
13+
private readonly IUserService _userService;
14+
private IAccessRule[] _accessRulesFromConfig;
15+
1416
public string Alias => "contentIntro";
1517

1618
public string[] Sections => new[] { "content" };
@@ -21,7 +23,7 @@ public IAccessRule[] AccessRules
2123
{
2224
get
2325
{
24-
var rules = _dashboardSettings.GetAccessRulesFromConfig();
26+
var rules = AccessRulesFromConfig;
2527

2628
if (rules.Length == 0)
2729
{
@@ -36,9 +38,39 @@ public IAccessRule[] AccessRules
3638
}
3739
}
3840

39-
public ContentDashboard(IContentDashboardSettings dashboardSettings)
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)
4071
{
4172
_dashboardSettings = dashboardSettings;
73+
_userService = userService;
4274
}
4375
}
4476
}

0 commit comments

Comments
 (0)