Skip to content

Commit 2d18572

Browse files
committed
Revert making GetCurrentServiceProvider public
Changed LoadPermissionDefinitions to accept the IPermissionService instead
1 parent 9a567a1 commit 2d18572

File tree

5 files changed

+43
-27
lines changed

5 files changed

+43
-27
lines changed

DNN Platform/Library/Common/Globals.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,13 +3444,6 @@ public static partial string PreventSQLInjection(string strSQL)
34443444
return PortalSecurity.Instance.InputFilter(strSQL, PortalSecurity.FilterFlag.NoSQL);
34453445
}
34463446

3447-
/// <summary>Gets an <see cref="IServiceProvider"/> for the current request, or the global provider if not available.</summary>
3448-
/// <returns>An <see cref="IServiceProvider"/> instance.</returns>
3449-
public static IServiceProvider GetCurrentServiceProvider()
3450-
{
3451-
return HttpContextSource.Current?.GetScope()?.ServiceProvider ?? DependencyProvider;
3452-
}
3453-
34543447
/// <summary>Looks at various file artifacts to determine if DotNetNuke has already been installed.</summary>
34553448
/// <returns>true if installed else false.</returns>
34563449
/// <remarks>
@@ -3502,6 +3495,13 @@ internal static IServiceScope GetOrCreateServiceScope()
35023495
DependencyProvider.CreateScope);
35033496
}
35043497

3498+
/// <summary>Gets an <see cref="IServiceProvider"/> for the current request, or the global provider if not available.</summary>
3499+
/// <returns>An <see cref="IServiceProvider"/> instance.</returns>
3500+
internal static IServiceProvider GetCurrentServiceProvider()
3501+
{
3502+
return HttpContextSource.Current?.GetScope()?.ServiceProvider ?? DependencyProvider;
3503+
}
3504+
35053505
/// <summary>Check whether the Filename matches extensions.</summary>
35063506
/// <param name="filename">The filename.</param>
35073507
/// <param name="strExtensions">The valid extensions.</param>

DNN Platform/Library/Security/Permissions/PermissionController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace DotNetNuke.Security.Permissions
66
using System;
77
using System.Collections;
88
using System.Collections.Generic;
9+
using System.ComponentModel;
910
using System.Linq;
1011
using System.Text;
1112

@@ -20,6 +21,8 @@ namespace DotNetNuke.Security.Permissions
2021
using DotNetNuke.Security.Roles;
2122
using DotNetNuke.Services.Log.EventLog;
2223

24+
using Microsoft.Extensions.DependencyInjection;
25+
2326
public partial class PermissionController : IPermissionService
2427
{
2528
private static readonly DataProvider Provider = DataProvider.Instance();

DNN Platform/Modules/ResourceManager/Services/Dto/FolderPermissions.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See the LICENSE file in the project root for more information
44
namespace Dnn.Modules.ResourceManager.Services.Dto
55
{
6+
using System;
67
using System.Linq;
78
using System.Web;
89

@@ -13,6 +14,7 @@ namespace Dnn.Modules.ResourceManager.Services.Dto
1314
using DotNetNuke.Common.Extensions;
1415
using DotNetNuke.Common.Utilities;
1516
using DotNetNuke.Entities.Portals;
17+
using DotNetNuke.Internal.SourceGenerators;
1618
using DotNetNuke.Security.Permissions;
1719

1820
using Microsoft.Extensions.DependencyInjection;
@@ -22,14 +24,14 @@ public class FolderPermissions : Permissions
2224
{
2325
/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
2426
public FolderPermissions()
25-
: base(false)
2627
{
2728
}
2829

2930
/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
3031
/// <param name="needDefinitions">A vlaue indicating whether the permissions definitions need to be loaded.</param>
31-
public FolderPermissions(bool needDefinitions)
32-
: base(needDefinitions)
32+
/// <param name="permissionService">The permission service.</param>
33+
public FolderPermissions(bool needDefinitions, IPermissionService permissionService)
34+
: base(needDefinitions, permissionService)
3335
{
3436
foreach (var role in PermissionProvider.Instance().ImplicitRolesForFolders(PortalSettings.Current.PortalId))
3537
{
@@ -40,8 +42,9 @@ public FolderPermissions(bool needDefinitions)
4042
/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
4143
/// <param name="needDefinitions">A value indicating whether the permission definitions need to be loaded.</param>
4244
/// <param name="permissions">A colleciton of folder permissions.</param>
43-
public FolderPermissions(bool needDefinitions, FolderPermissionCollection permissions)
44-
: base(needDefinitions)
45+
/// <param name="permissionService">The permission service.</param>
46+
public FolderPermissions(bool needDefinitions, FolderPermissionCollection permissions, IPermissionService permissionService)
47+
: base(needDefinitions, permissionService)
4548
{
4649
foreach (var role in PermissionProvider.Instance().ImplicitRolesForFolders(PortalSettings.Current.PortalId))
4750
{
@@ -69,10 +72,8 @@ public FolderPermissions(bool needDefinitions, FolderPermissionCollection permis
6972
}
7073

7174
/// <inheritdoc/>
72-
protected override void LoadPermissionDefinitions()
75+
protected override void LoadPermissionDefinitions(IPermissionService permissionService)
7376
{
74-
var permissionService = Globals.GetCurrentServiceProvider().GetRequiredService<IPermissionService>();
75-
7677
foreach (var permission in permissionService.GetDefinitionsByFolder())
7778
{
7879
this.PermissionDefinitions.Add(new Permission

DNN Platform/Modules/ResourceManager/Services/Dto/Permissions.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,36 @@
33
// See the LICENSE file in the project root for more information
44
namespace Dnn.Modules.ResourceManager.Services.Dto
55
{
6+
using System;
67
using System.Collections.Generic;
78
using System.Runtime.Serialization;
89

910
using Dnn.Modules.ResourceManager.Components;
1011

12+
using DotNetNuke.Abstractions.Security.Permissions;
13+
using DotNetNuke.Security.Permissions;
14+
1115
/// <summary>Represents a permissions set.</summary>
1216
[DataContract]
1317
public abstract class Permissions
14-
{
18+
{
1519
/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
1620
protected Permissions()
17-
: this(false)
18-
{
19-
}
20-
21-
/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
22-
/// <param name="needDefinitions">A value indicating whether the permissions need to be loaded.</param>
23-
protected Permissions(bool needDefinitions)
2421
{
2522
this.RolePermissions = new List<RolePermission>();
2623
this.UserPermissions = new List<UserPermission>();
24+
}
2725

26+
/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
27+
/// <param name="needDefinitions">A value indicating whether the permissions need to be loaded.</param>
28+
/// <param name="permissionService">The permission service.</param>
29+
protected Permissions(bool needDefinitions, IPermissionService permissionService)
30+
: this()
31+
{
2832
if (needDefinitions)
2933
{
3034
this.PermissionDefinitions = new List<Permission>();
31-
this.LoadPermissionDefinitions();
35+
this.LoadPermissionDefinitions(permissionService);
3236
this.EnsureDefaultRoles();
3337
}
3438
}
@@ -46,6 +50,7 @@ protected Permissions(bool needDefinitions)
4650
public IList<UserPermission> UserPermissions { get; set; }
4751

4852
/// <summary>Loads the permissions definitions.</summary>
49-
protected abstract void LoadPermissionDefinitions();
53+
/// <param name="permissionService">The permission service.</param>
54+
protected abstract void LoadPermissionDefinitions(IPermissionService permissionService);
5055
}
5156
}

DNN Platform/Modules/ResourceManager/Services/ItemsController.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace Dnn.Modules.ResourceManager.Services
2020
using Dnn.Modules.ResourceManager.Services.Attributes;
2121
using Dnn.Modules.ResourceManager.Services.Dto;
2222
using DotNetNuke.Abstractions.Application;
23+
using DotNetNuke.Abstractions.Security.Permissions;
2324
using DotNetNuke.Common;
2425
using DotNetNuke.Common.Utilities;
2526
using DotNetNuke.Entities.Icons;
@@ -45,14 +46,20 @@ public class ItemsController : DnnApiController
4546
private readonly IModuleControlPipeline modulePipeline;
4647
private readonly IApplicationStatusInfo applicationStatusInfo;
4748
private readonly Hashtable mappedPathsSupported = new Hashtable();
49+
private readonly IPermissionService permissionService;
4850

4951
/// <summary>Initializes a new instance of the <see cref="ItemsController"/> class.</summary>
5052
/// <param name="modulePipeline">An instance of an <see cref="IModuleControlPipeline"/> used to hook into the EditUrl of the webforms folders provider settings UI.</param>
5153
/// <param name="applicationStatusInfo">The application status info.</param>
52-
public ItemsController(IModuleControlPipeline modulePipeline, IApplicationStatusInfo applicationStatusInfo)
54+
/// <param name="permissionService">The permission service.</param>
55+
public ItemsController(
56+
IModuleControlPipeline modulePipeline,
57+
IApplicationStatusInfo applicationStatusInfo,
58+
IPermissionService permissionService)
5359
{
5460
this.modulePipeline = modulePipeline;
5561
this.applicationStatusInfo = applicationStatusInfo;
62+
this.permissionService = permissionService;
5663
}
5764

5865
/// <summary>Gets the content for a specific folder.</summary>
@@ -442,7 +449,7 @@ public HttpResponseMessage GetFolderDetails(int folderId)
442449
lastModifiedBy = lastModifiedBy != null ? lastModifiedBy.Username : string.Empty,
443450
type = FolderMappingController.Instance.GetFolderMapping(folder.FolderMappingID).MappingName,
444451
isVersioned = folder.IsVersioned,
445-
permissions = new FolderPermissions(true, folder.FolderPermissions),
452+
permissions = new FolderPermissions(true, folder.FolderPermissions, this.permissionService),
446453
});
447454
}
448455

0 commit comments

Comments
 (0)