Skip to content

Commit

Permalink
Revert making GetCurrentServiceProvider public
Browse files Browse the repository at this point in the history
Changed LoadPermissionDefinitions to accept the IPermissionService instead
  • Loading branch information
GerardSmit committed Oct 13, 2023
1 parent 9a567a1 commit 2d18572
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
14 changes: 7 additions & 7 deletions DNN Platform/Library/Common/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3444,13 +3444,6 @@ public static partial string PreventSQLInjection(string strSQL)
return PortalSecurity.Instance.InputFilter(strSQL, PortalSecurity.FilterFlag.NoSQL);
}

/// <summary>Gets an <see cref="IServiceProvider"/> for the current request, or the global provider if not available.</summary>
/// <returns>An <see cref="IServiceProvider"/> instance.</returns>
public static IServiceProvider GetCurrentServiceProvider()
{
return HttpContextSource.Current?.GetScope()?.ServiceProvider ?? DependencyProvider;
}

/// <summary>Looks at various file artifacts to determine if DotNetNuke has already been installed.</summary>
/// <returns>true if installed else false.</returns>
/// <remarks>
Expand Down Expand Up @@ -3502,6 +3495,13 @@ internal static IServiceScope GetOrCreateServiceScope()
DependencyProvider.CreateScope);
}

/// <summary>Gets an <see cref="IServiceProvider"/> for the current request, or the global provider if not available.</summary>
/// <returns>An <see cref="IServiceProvider"/> instance.</returns>
internal static IServiceProvider GetCurrentServiceProvider()
{
return HttpContextSource.Current?.GetScope()?.ServiceProvider ?? DependencyProvider;
}

/// <summary>Check whether the Filename matches extensions.</summary>
/// <param name="filename">The filename.</param>
/// <param name="strExtensions">The valid extensions.</param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace DotNetNuke.Security.Permissions
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

Expand All @@ -20,6 +21,8 @@ namespace DotNetNuke.Security.Permissions
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Log.EventLog;

using Microsoft.Extensions.DependencyInjection;

public partial class PermissionController : IPermissionService
{
private static readonly DataProvider Provider = DataProvider.Instance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information
namespace Dnn.Modules.ResourceManager.Services.Dto
{
using System;
using System.Linq;
using System.Web;

Expand All @@ -13,6 +14,7 @@ namespace Dnn.Modules.ResourceManager.Services.Dto
using DotNetNuke.Common.Extensions;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Internal.SourceGenerators;
using DotNetNuke.Security.Permissions;

using Microsoft.Extensions.DependencyInjection;
Expand All @@ -22,14 +24,14 @@ public class FolderPermissions : Permissions
{
/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
public FolderPermissions()
: base(false)
{
}

/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
/// <param name="needDefinitions">A vlaue indicating whether the permissions definitions need to be loaded.</param>
public FolderPermissions(bool needDefinitions)
: base(needDefinitions)
/// <param name="permissionService">The permission service.</param>
public FolderPermissions(bool needDefinitions, IPermissionService permissionService)
: base(needDefinitions, permissionService)
{
foreach (var role in PermissionProvider.Instance().ImplicitRolesForFolders(PortalSettings.Current.PortalId))
{
Expand All @@ -40,8 +42,9 @@ public FolderPermissions(bool needDefinitions)
/// <summary>Initializes a new instance of the <see cref="FolderPermissions"/> class.</summary>
/// <param name="needDefinitions">A value indicating whether the permission definitions need to be loaded.</param>
/// <param name="permissions">A colleciton of folder permissions.</param>
public FolderPermissions(bool needDefinitions, FolderPermissionCollection permissions)
: base(needDefinitions)
/// <param name="permissionService">The permission service.</param>
public FolderPermissions(bool needDefinitions, FolderPermissionCollection permissions, IPermissionService permissionService)
: base(needDefinitions, permissionService)
{
foreach (var role in PermissionProvider.Instance().ImplicitRolesForFolders(PortalSettings.Current.PortalId))
{
Expand Down Expand Up @@ -69,10 +72,8 @@ public FolderPermissions(bool needDefinitions, FolderPermissionCollection permis
}

/// <inheritdoc/>
protected override void LoadPermissionDefinitions()
protected override void LoadPermissionDefinitions(IPermissionService permissionService)
{
var permissionService = Globals.GetCurrentServiceProvider().GetRequiredService<IPermissionService>();

foreach (var permission in permissionService.GetDefinitionsByFolder())
{
this.PermissionDefinitions.Add(new Permission
Expand Down
25 changes: 15 additions & 10 deletions DNN Platform/Modules/ResourceManager/Services/Dto/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,36 @@
// See the LICENSE file in the project root for more information
namespace Dnn.Modules.ResourceManager.Services.Dto
{
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;

using Dnn.Modules.ResourceManager.Components;

using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Security.Permissions;

/// <summary>Represents a permissions set.</summary>
[DataContract]
public abstract class Permissions
{
{
/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
protected Permissions()
: this(false)
{
}

/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
/// <param name="needDefinitions">A value indicating whether the permissions need to be loaded.</param>
protected Permissions(bool needDefinitions)
{
this.RolePermissions = new List<RolePermission>();
this.UserPermissions = new List<UserPermission>();
}

/// <summary>Initializes a new instance of the <see cref="Permissions"/> class.</summary>
/// <param name="needDefinitions">A value indicating whether the permissions need to be loaded.</param>
/// <param name="permissionService">The permission service.</param>
protected Permissions(bool needDefinitions, IPermissionService permissionService)
: this()
{
if (needDefinitions)
{
this.PermissionDefinitions = new List<Permission>();
this.LoadPermissionDefinitions();
this.LoadPermissionDefinitions(permissionService);
this.EnsureDefaultRoles();
}
}
Expand All @@ -46,6 +50,7 @@ protected Permissions(bool needDefinitions)
public IList<UserPermission> UserPermissions { get; set; }

/// <summary>Loads the permissions definitions.</summary>
protected abstract void LoadPermissionDefinitions();
/// <param name="permissionService">The permission service.</param>
protected abstract void LoadPermissionDefinitions(IPermissionService permissionService);
}
}
11 changes: 9 additions & 2 deletions DNN Platform/Modules/ResourceManager/Services/ItemsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Dnn.Modules.ResourceManager.Services
using Dnn.Modules.ResourceManager.Services.Attributes;
using Dnn.Modules.ResourceManager.Services.Dto;
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Icons;
Expand All @@ -45,14 +46,20 @@ public class ItemsController : DnnApiController
private readonly IModuleControlPipeline modulePipeline;
private readonly IApplicationStatusInfo applicationStatusInfo;
private readonly Hashtable mappedPathsSupported = new Hashtable();
private readonly IPermissionService permissionService;

/// <summary>Initializes a new instance of the <see cref="ItemsController"/> class.</summary>
/// <param name="modulePipeline">An instance of an <see cref="IModuleControlPipeline"/> used to hook into the EditUrl of the webforms folders provider settings UI.</param>
/// <param name="applicationStatusInfo">The application status info.</param>
public ItemsController(IModuleControlPipeline modulePipeline, IApplicationStatusInfo applicationStatusInfo)
/// <param name="permissionService">The permission service.</param>
public ItemsController(
IModuleControlPipeline modulePipeline,
IApplicationStatusInfo applicationStatusInfo,
IPermissionService permissionService)
{
this.modulePipeline = modulePipeline;
this.applicationStatusInfo = applicationStatusInfo;
this.permissionService = permissionService;
}

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

Expand Down

0 comments on commit 2d18572

Please sign in to comment.