diff --git a/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IFolderPermissionInfo.cs b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IFolderPermissionInfo.cs
new file mode 100644
index 00000000000..f678ee7fce6
--- /dev/null
+++ b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IFolderPermissionInfo.cs
@@ -0,0 +1,21 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
+
+namespace DotNetNuke.Abstractions.Security.Permissions;
+
+/// Information about the application of an instance of a folder permission.
+public interface IFolderPermissionInfo : IPermissionInfo
+{
+ /// Gets or sets the ID of the folder permission.
+ int FolderPermissionId { get; set; }
+
+ /// Gets or sets the folder ID to which the permission applies.
+ int FolderId { get; set; }
+
+ /// Gets or sets the path of the folder to which the permission applies.
+ string FolderPath { get; set; }
+
+ /// Gets or sets the portal ID of the folder to which the permission applies.
+ int PortalId { get; set; }
+}
diff --git a/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionInfo.cs b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionInfo.cs
new file mode 100644
index 00000000000..d706817d907
--- /dev/null
+++ b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionInfo.cs
@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
+
+namespace DotNetNuke.Abstractions.Security.Permissions;
+
+/// Information about the definition of a permission.
+public interface IPermissionDefinitionInfo
+{
+ /// Gets or sets the Module Definition ID.
+ public int ModuleDefId { get; set; }
+
+ /// Gets or sets the Permission Code.
+ public string PermissionCode { get; set; }
+
+ /// Gets or sets the Permission ID.
+ public int PermissionId { get; set; }
+
+ /// Gets or sets the Permission Key.
+ public string PermissionKey { get; set; }
+
+ /// Gets or sets the Permission Name.
+ public string PermissionName { get; set; }
+}
diff --git a/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionService.cs b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionService.cs
new file mode 100644
index 00000000000..a12906b8c96
--- /dev/null
+++ b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionDefinitionService.cs
@@ -0,0 +1,69 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
+
+namespace DotNetNuke.Abstractions.Security.Permissions;
+
+using System.Collections.Generic;
+
+/// Handles the Business Control Layer for Permissions.
+public interface IPermissionDefinitionService
+{
+ /// Gets the permissions.
+ /// The permissions.
+ IEnumerable GetDefinitions();
+
+ /// Gets the permissions by folder.
+ /// The permissions by folder.
+ IEnumerable GetDefinitionsByFolder();
+
+ /// Gets the permissions by desktop module.
+ /// The permissions by desktop module.
+ IEnumerable GetDefinitionsByPortalDesktopModule();
+
+ /// Gets the permissions by tab.
+ /// The permissions by tab.
+ IEnumerable GetDefinitionsByTab();
+
+ /// Gets the permissions by and .
+ /// The permission code.
+ /// The permission key.
+ /// The permissions by tab.
+ IEnumerable GetDefinitionsByCodeAndKey(string permissionCode, string permissionKey);
+
+ /// Gets the permissions by .
+ /// The module definition ID.
+ /// The permissions by tab.
+ IEnumerable GetDefinitionsByModuleDefId(int moduleDefId);
+
+ /// Gets the permissions by and for the given module in the tab.
+ /// The module ID.
+ /// The tab ID.
+ /// The permissions by tab.
+ IEnumerable GetDefinitionsByModule(int moduleId, int tabId);
+
+ /// Adds a new permission.
+ /// The permission.
+ /// The new permission ID.
+ int AddDefinition(IPermissionDefinitionInfo permissionDefinition);
+
+ /// Deletes an existing permission.
+ /// The permission to delete.
+ void DeleteDefinition(IPermissionDefinitionInfo permissionDefinition);
+
+ /// Gets the permission by the .
+ /// The permission ID.
+ /// The permission.
+ IPermissionDefinitionInfo GetDefinition(int permissionDefinitionId);
+
+ /// Updates an existing permission.
+ /// The permission.
+ void UpdateDefinition(IPermissionDefinitionInfo permission);
+
+ /// Clears the permission definition cache.
+ ///
+ /// , and will clear the cache automatically.
+ /// This method is only needed if you want to clear the cache manually.
+ ///
+ void ClearCache();
+}
diff --git a/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionInfo.cs b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionInfo.cs
new file mode 100644
index 00000000000..c6d274e533b
--- /dev/null
+++ b/DNN Platform/DotNetNuke.Abstractions/Security/Permissions/IPermissionInfo.cs
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
+
+namespace DotNetNuke.Abstractions.Security.Permissions;
+
+/// Information about an applied instance of a permission.
+public interface IPermissionInfo : IPermissionDefinitionInfo
+{
+ /// Gets or sets a value indicating whether gets and sets a flag that indicates whether the user or role has permission.
+ bool AllowAccess { get; set; }
+
+ /// Gets or sets the User's DisplayName.
+ string DisplayName { get; set; }
+
+ /// Gets or sets the Role ID.
+ int RoleId { get; set; }
+
+ /// Gets or sets the Role Name.
+ string RoleName { get; set; }
+
+ /// Gets or sets the User ID.
+ int UserId { get; set; }
+
+ /// Gets or sets the User Name.
+ string Username { get; set; }
+}
diff --git a/DNN Platform/Library/Security/Permissions/FolderPermissionCollection.cs b/DNN Platform/Library/Security/Permissions/FolderPermissionCollection.cs
index e963be2f1eb..6eeada15f7a 100644
--- a/DNN Platform/Library/Security/Permissions/FolderPermissionCollection.cs
+++ b/DNN Platform/Library/Security/Permissions/FolderPermissionCollection.cs
@@ -1,39 +1,39 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
namespace DotNetNuke.Security.Permissions
{
using System;
using System.Collections;
using System.Collections.Generic;
-
- using DotNetNuke.Common.Utilities;
-
+
+ using DotNetNuke.Common.Utilities;
+
[Serializable]
public class FolderPermissionCollection : CollectionBase
- {
- /// Initializes a new instance of the class.
+ {
+ /// Initializes a new instance of the class.
public FolderPermissionCollection()
{
- }
-
- /// Initializes a new instance of the class.
- ///
+ }
+
+ /// Initializes a new instance of the class.
+ ///
public FolderPermissionCollection(ArrayList folderPermissions)
{
this.AddRange(folderPermissions);
- }
-
- /// Initializes a new instance of the class.
- ///
+ }
+
+ /// Initializes a new instance of the class.
+ ///
public FolderPermissionCollection(FolderPermissionCollection folderPermissions)
{
this.AddRange(folderPermissions);
- }
-
- /// Initializes a new instance of the class.
- ///
- ///
+ }
+
+ /// Initializes a new instance of the class.
+ ///
+ ///
public FolderPermissionCollection(ArrayList folderPermissions, string folderPath)
{
foreach (FolderPermissionInfo permission in folderPermissions)
@@ -91,6 +91,14 @@ public int Add(FolderPermissionInfo value, bool checkForDuplicates)
return id;
}
+ public void AddRange(IEnumerable folderPermissions)
+ {
+ foreach (var permission in folderPermissions)
+ {
+ this.List.Add(permission);
+ }
+ }
+
public void AddRange(ArrayList folderPermissions)
{
foreach (FolderPermissionInfo permission in folderPermissions)
diff --git a/DNN Platform/Library/Security/Permissions/FolderPermissionInfo.cs b/DNN Platform/Library/Security/Permissions/FolderPermissionInfo.cs
index 06b348923bf..8c21335f988 100644
--- a/DNN Platform/Library/Security/Permissions/FolderPermissionInfo.cs
+++ b/DNN Platform/Library/Security/Permissions/FolderPermissionInfo.cs
@@ -5,20 +5,21 @@ namespace DotNetNuke.Security.Permissions
{
using System;
using System.Data;
- using System.Xml.Serialization;
-
+ using System.Xml.Serialization;
+
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
- using Newtonsoft.Json;
-
+ using Newtonsoft.Json;
+
[Serializable]
- public class FolderPermissionInfo : PermissionInfoBase, IHydratable
+ public class FolderPermissionInfo : PermissionInfoBase, IHydratable, IFolderPermissionInfo
{
// local property declarations
- private int folderID;
+ private int folderId;
private string folderPath;
- private int folderPermissionID;
- private int portalID;
+ private int folderPermissionId;
+ private int portalId;
///
/// Initializes a new instance of the class.
@@ -26,10 +27,10 @@ public class FolderPermissionInfo : PermissionInfoBase, IHydratable
///
public FolderPermissionInfo()
{
- this.folderPermissionID = Null.NullInteger;
+ this.folderPermissionId = Null.NullInteger;
this.folderPath = Null.NullString;
- this.portalID = Null.NullInteger;
- this.folderID = Null.NullInteger;
+ this.portalId = Null.NullInteger;
+ this.folderId = Null.NullInteger;
}
///
@@ -38,57 +39,118 @@ public FolderPermissionInfo()
///
/// A PermissionInfo object.
public FolderPermissionInfo(PermissionInfo permission)
+ : this((IPermissionInfo)permission)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ /// Constructs a new FolderPermissionInfo.
+ ///
+ /// A PermissionInfo object.
+ public FolderPermissionInfo(IPermissionInfo permission)
: this()
{
- this.ModuleDefID = permission.ModuleDefID;
- this.PermissionCode = permission.PermissionCode;
- this.PermissionID = permission.PermissionID;
- this.PermissionKey = permission.PermissionKey;
- this.PermissionName = permission.PermissionName;
+ var @this = (IPermissionDefinitionInfo)this;
+ @this.ModuleDefId = permission.ModuleDefId;
+ @this.PermissionCode = permission.PermissionCode;
+ @this.PermissionId = permission.PermissionId;
+ @this.PermissionKey = permission.PermissionKey;
+ @this.PermissionName = permission.PermissionName;
}
[XmlIgnore]
[JsonIgnore]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderPermissionId)} instead. Scheduled for removal in v11.0.0.")]
public int FolderPermissionID
{
get
{
- return this.folderPermissionID;
+ return ((IFolderPermissionInfo)this).FolderPermissionId;
}
set
{
- this.folderPermissionID = value;
+ ((IFolderPermissionInfo)this).FolderPermissionId = value;
}
}
[XmlIgnore]
[JsonIgnore]
+ int IFolderPermissionInfo.FolderPermissionId
+ {
+ get
+ {
+ return this.folderPermissionId;
+ }
+
+ set
+ {
+ this.folderPermissionId = value;
+ }
+ }
+
+ [XmlIgnore]
+ [JsonIgnore]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderId)} instead. Scheduled for removal in v11.0.0.")]
public int FolderID
{
get
{
- return this.folderID;
+ return ((IFolderPermissionInfo)this).FolderId;
}
set
{
- this.folderID = value;
+ ((IFolderPermissionInfo)this).FolderId = value;
}
}
[XmlIgnore]
[JsonIgnore]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.FolderId)} instead. Scheduled for removal in v11.0.0.")]
+ int IFolderPermissionInfo.FolderId
+ {
+ get
+ {
+ return this.folderId;
+ }
+
+ set
+ {
+ this.folderId = value;
+ }
+ }
+
+ [XmlIgnore]
+ [JsonIgnore]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.PortalId)} instead. Scheduled for removal in v11.0.0.")]
public int PortalID
{
get
{
- return this.portalID;
+ return ((IFolderPermissionInfo)this).PortalId;
+ }
+
+ set
+ {
+ ((IFolderPermissionInfo)this).PortalId = value;
+ }
+ }
+
+ [XmlIgnore]
+ [JsonIgnore]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IFolderPermissionInfo)}.{nameof(IFolderPermissionInfo.PortalId)} instead. Scheduled for removal in v11.0.0.")]
+ int IFolderPermissionInfo.PortalId
+ {
+ get
+ {
+ return this.portalId;
}
set
{
- this.portalID = value;
+ this.portalId = value;
}
}
@@ -114,12 +176,12 @@ public int KeyID
{
get
{
- return this.FolderPermissionID;
+ return ((IFolderPermissionInfo)this).FolderPermissionId;
}
set
{
- this.FolderPermissionID = value;
+ ((IFolderPermissionInfo)this).FolderPermissionId = value;
}
}
@@ -128,10 +190,12 @@ public int KeyID
public void Fill(IDataReader dr)
{
this.FillInternal(dr);
- this.FolderPermissionID = Null.SetNullInteger(dr["FolderPermissionID"]);
- this.FolderID = Null.SetNullInteger(dr["FolderID"]);
- this.PortalID = Null.SetNullInteger(dr["PortalID"]);
- this.FolderPath = Null.SetNullString(dr["FolderPath"]);
+
+ var @this = (IFolderPermissionInfo)this;
+ @this.FolderPermissionId = Null.SetNullInteger(dr["FolderPermissionID"]);
+ @this.FolderId = Null.SetNullInteger(dr["FolderID"]);
+ @this.PortalId = Null.SetNullInteger(dr["PortalID"]);
+ @this.FolderPath = Null.SetNullString(dr["FolderPath"]);
}
}
}
diff --git a/DNN Platform/Library/Security/Permissions/PermissionController.cs b/DNN Platform/Library/Security/Permissions/PermissionController.cs
index 284dc798f10..d46b7306fce 100644
--- a/DNN Platform/Library/Security/Permissions/PermissionController.cs
+++ b/DNN Platform/Library/Security/Permissions/PermissionController.cs
@@ -9,6 +9,7 @@ namespace DotNetNuke.Security.Permissions
using System.Linq;
using System.Text;
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Data;
@@ -19,7 +20,7 @@ namespace DotNetNuke.Security.Permissions
using DotNetNuke.Security.Roles;
using DotNetNuke.Services.Log.EventLog;
- public partial class PermissionController
+ public partial class PermissionController : IPermissionDefinitionService
{
private static readonly DataProvider Provider = DataProvider.Instance();
@@ -68,27 +69,40 @@ public static string BuildPermissions(IList permissions, string permissionKey)
return permissionsString;
}
- public static ArrayList GetPermissionsByFolder()
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByFolder)} instead.")]
+ public static partial ArrayList GetPermissionsByFolder()
{
- return new ArrayList(GetPermissions().Where(p => p.PermissionCode == "SYSTEM_FOLDER").ToArray());
+ return new ArrayList(GetPermissionsByFolderEnumerable().ToArray());
}
- public static ArrayList GetPermissionsByPortalDesktopModule()
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByPortalDesktopModule)} instead.")]
+ public static partial ArrayList GetPermissionsByPortalDesktopModule()
{
- return new ArrayList(GetPermissions().Where(p => p.PermissionCode == "SYSTEM_DESKTOPMODULE").ToArray());
+ return new ArrayList(GetPermissionsByPortalDesktopModuleEnumerable().ToArray());
}
- public static ArrayList GetPermissionsByTab()
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByTab)} instead.")]
+ public static partial ArrayList GetPermissionsByTab()
{
- return new ArrayList(GetPermissions().Where(p => p.PermissionCode == "SYSTEM_TAB").ToArray());
+ return new ArrayList(GetPermissionsByTabEnumerable().ToArray());
}
+ ///
public int AddPermission(PermissionInfo permission)
+ {
+ return this.AddPermission((IPermissionDefinitionInfo)permission);
+ }
+
+ ///
+ public int AddPermission(IPermissionDefinitionInfo permission)
{
EventLogController.Instance.AddLog(permission, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, string.Empty, EventLogController.EventLogType.PERMISSION_CREATED);
var permissionId = Convert.ToInt32(Provider.AddPermission(
permission.PermissionCode,
- permission.ModuleDefID,
+ permission.ModuleDefId,
permission.PermissionKey,
permission.PermissionName,
UserController.Instance.GetCurrentUserInfo().UserID));
@@ -97,6 +111,7 @@ public int AddPermission(PermissionInfo permission)
return permissionId;
}
+ ///
public void DeletePermission(int permissionID)
{
EventLogController.Instance.AddLog(
@@ -109,36 +124,47 @@ public void DeletePermission(int permissionID)
this.ClearCache();
}
+ ///
public PermissionInfo GetPermission(int permissionID)
{
return GetPermissions().SingleOrDefault(p => p.PermissionID == permissionID);
}
- public ArrayList GetPermissionByCodeAndKey(string permissionCode, string permissionKey)
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByCodeAndKey)} instead.")]
+ public partial ArrayList GetPermissionByCodeAndKey(string permissionCode, string permissionKey)
{
- return new ArrayList(GetPermissions().Where(p => p.PermissionCode.Equals(permissionCode, StringComparison.InvariantCultureIgnoreCase)
- && p.PermissionKey.Equals(permissionKey, StringComparison.InvariantCultureIgnoreCase)).ToArray());
+ return new ArrayList(GetPermissionByCodeAndKeyEnumerable(permissionCode, permissionKey).ToArray());
}
- public ArrayList GetPermissionsByModuleDefID(int moduleDefID)
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByModuleDefId)} instead.")]
+ public partial ArrayList GetPermissionsByModuleDefID(int moduleDefID)
{
- return new ArrayList(GetPermissions().Where(p => p.ModuleDefID == moduleDefID).ToArray());
+ return new ArrayList(GetPermissionsByModuleDefIdEnumerable(moduleDefID).ToArray());
}
- public ArrayList GetPermissionsByModule(int moduleId, int tabId)
+ ///
+ [DnnDeprecated(9, 13, 1, $"Use {nameof(IPermissionDefinitionService)}.{nameof(IPermissionDefinitionService.GetDefinitionsByModule)} instead.")]
+ public partial ArrayList GetPermissionsByModule(int moduleId, int tabId)
{
- var module = ModuleController.Instance.GetModule(moduleId, tabId, false);
-
- return new ArrayList(GetPermissions().Where(p => p.ModuleDefID == module.ModuleDefID || p.PermissionCode == "SYSTEM_MODULE_DEFINITION").ToArray());
+ return new ArrayList(GetPermissionsByModuleEnumerable(moduleId, tabId).ToArray());
}
+ ///
public void UpdatePermission(PermissionInfo permission)
+ {
+ this.UpdatePermission((IPermissionDefinitionInfo)permission);
+ }
+
+ ///
+ public void UpdatePermission(IPermissionDefinitionInfo permission)
{
EventLogController.Instance.AddLog(permission, PortalController.Instance.GetCurrentPortalSettings(), UserController.Instance.GetCurrentUserInfo().UserID, string.Empty, EventLogController.EventLogType.PERMISSION_UPDATED);
Provider.UpdatePermission(
- permission.PermissionID,
+ permission.PermissionId,
permission.PermissionCode,
- permission.ModuleDefID,
+ permission.ModuleDefId,
permission.PermissionKey,
permission.PermissionName,
UserController.Instance.GetCurrentUserInfo().UserID);
@@ -214,6 +240,42 @@ public partial ArrayList GetPermissionsByModuleID(int moduleId)
return this.GetPermissionsByModuleDefID(module.ModuleDefID);
}
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitions() => GetPermissions();
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByFolder() => GetPermissionsByFolderEnumerable();
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByPortalDesktopModule() => GetPermissionsByPortalDesktopModuleEnumerable();
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByTab() => GetPermissionsByTabEnumerable();
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByCodeAndKey(string permissionCode, string permissionKey) => GetPermissionByCodeAndKeyEnumerable(permissionCode, permissionKey);
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByModuleDefId(int moduleDefId) => GetPermissionsByModuleDefIdEnumerable(moduleDefId);
+
+ ///
+ IEnumerable IPermissionDefinitionService.GetDefinitionsByModule(int moduleId, int tabId) => GetPermissionsByModuleEnumerable(moduleId, tabId);
+
+ ///
+ int IPermissionDefinitionService.AddDefinition(IPermissionDefinitionInfo permission) => this.AddPermission(permission);
+
+ ///
+ void IPermissionDefinitionService.DeleteDefinition(IPermissionDefinitionInfo permission) => this.DeletePermission(permission.PermissionId);
+
+ ///
+ IPermissionDefinitionInfo IPermissionDefinitionService.GetDefinition(int permissionDefinitionId) => this.GetPermission(permissionDefinitionId);
+
+ ///
+ void IPermissionDefinitionService.UpdateDefinition(IPermissionDefinitionInfo permission) => this.UpdatePermission(permission);
+
+ ///
+ void IPermissionDefinitionService.ClearCache() => this.ClearCache();
+
private static IEnumerable GetPermissions()
{
return CBO.GetCachedObject>(
@@ -224,6 +286,40 @@ private static IEnumerable GetPermissions()
c => CBO.FillCollection(Provider.ExecuteReader("GetPermissions")));
}
+ private static IEnumerable GetPermissionsByFolderEnumerable()
+ {
+ return GetPermissions().Where(p => p.PermissionCode == "SYSTEM_FOLDER");
+ }
+
+ private static IEnumerable GetPermissionsByPortalDesktopModuleEnumerable()
+ {
+ return GetPermissions().Where(p => p.PermissionCode == "SYSTEM_DESKTOPMODULE");
+ }
+
+ private static IEnumerable GetPermissionsByTabEnumerable()
+ {
+ return GetPermissions().Where(p => p.PermissionCode == "SYSTEM_TAB");
+ }
+
+ private static IEnumerable GetPermissionByCodeAndKeyEnumerable(string permissionCode, string permissionKey)
+ {
+ return GetPermissions().Where(p => p.PermissionCode.Equals(permissionCode, StringComparison.InvariantCultureIgnoreCase)
+ && p.PermissionKey.Equals(permissionKey, StringComparison.InvariantCultureIgnoreCase));
+ }
+
+ private static IEnumerable GetPermissionsByModuleDefIdEnumerable(int moduleDefId)
+ {
+ return GetPermissions().Where(p => p.ModuleDefID == moduleDefId);
+ }
+
+ private static IEnumerable GetPermissionsByModuleEnumerable(int moduleId, int tabId)
+ {
+ var module = ModuleController.Instance.GetModule(moduleId, tabId, false);
+ var moduleDefId = module.ModuleDefID;
+
+ return GetPermissions().Where(p => p.ModuleDefID == moduleDefId || p.PermissionCode == "SYSTEM_MODULE_DEFINITION");
+ }
+
private void ClearCache()
{
DataCache.RemoveCache(DataCache.PermissionsCacheKey);
diff --git a/DNN Platform/Library/Security/Permissions/PermissionInfo.cs b/DNN Platform/Library/Security/Permissions/PermissionInfo.cs
index 4ae42f78184..6a829607cb9 100644
--- a/DNN Platform/Library/Security/Permissions/PermissionInfo.cs
+++ b/DNN Platform/Library/Security/Permissions/PermissionInfo.cs
@@ -1,60 +1,78 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information
namespace DotNetNuke.Security.Permissions
{
using System;
using System.Data;
using System.Xml.Serialization;
-
+
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common.Utilities;
- using DotNetNuke.Entities;
- using Newtonsoft.Json;
-
+ using DotNetNuke.Entities;
+ using Newtonsoft.Json;
+
/// Project : DotNetNuke
/// Namespace: DotNetNuke.Security.Permissions
/// Class : PermissionInfo
/// PermissionInfo provides the Entity Layer for Permissions.
[Serializable]
- public class PermissionInfo : BaseEntityInfo
+ public class PermissionInfo : BaseEntityInfo, IPermissionDefinitionInfo
{
- /// Gets or sets the Mdoule Definition ID.
- /// An Integer.
- [XmlIgnore]
+ ///
+ [XmlIgnore]
[JsonIgnore]
- public int ModuleDefID { get; set; }
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionDefinitionInfo)}.{nameof(IPermissionDefinitionInfo.ModuleDefId)} instead. Scheduled for removal in v11.0.0.")]
+ public int ModuleDefID
+ {
+ get => ((IPermissionDefinitionInfo)this).ModuleDefId;
+ set => ((IPermissionDefinitionInfo)this).ModuleDefId = value;
+ }
- /// Gets or sets the Permission Code.
- /// A String.
+ ///
[XmlElement("permissioncode")]
public string PermissionCode { get; set; }
- /// Gets or sets the Permission ID.
- /// An Integer.
+ ///
[XmlElement("permissionid")]
- public int PermissionID { get; set; }
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionDefinitionInfo)}.{nameof(IPermissionDefinitionInfo.PermissionId)} instead. Scheduled for removal in v11.0.0.")]
+ public int PermissionID
+ {
+ get => ((IPermissionDefinitionInfo)this).PermissionId;
+ set => ((IPermissionDefinitionInfo)this).PermissionId = value;
+ }
- /// Gets or sets the Permission Key.
- /// A String.
+ ///
[XmlElement("permissionkey")]
public string PermissionKey { get; set; }
- /// Gets or sets the Permission Name.
- /// A String.
- [XmlIgnore]
+ ///
+ [XmlIgnore]
[JsonIgnore]
public string PermissionName { get; set; }
+ ///
+ [XmlIgnore]
+ [JsonIgnore]
+ int IPermissionDefinitionInfo.ModuleDefId { get; set; }
+
+ ///
+ [XmlIgnore]
+ [JsonIgnore]
+ int IPermissionDefinitionInfo.PermissionId { get; set; }
+
/// FillInternal fills a PermissionInfo from a Data Reader.
/// The Data Reader to use.
protected override void FillInternal(IDataReader dr)
{
base.FillInternal(dr);
- this.PermissionID = Null.SetNullInteger(dr["PermissionID"]);
- this.ModuleDefID = Null.SetNullInteger(dr["ModuleDefID"]);
- this.PermissionCode = Null.SetNullString(dr["PermissionCode"]);
- this.PermissionKey = Null.SetNullString(dr["PermissionKey"]);
- this.PermissionName = Null.SetNullString(dr["PermissionName"]);
+
+ var @this = (IPermissionDefinitionInfo)this;
+ @this.PermissionId = Null.SetNullInteger(dr["PermissionID"]);
+ @this.ModuleDefId = Null.SetNullInteger(dr["ModuleDefID"]);
+ @this.PermissionCode = Null.SetNullString(dr["PermissionCode"]);
+ @this.PermissionKey = Null.SetNullString(dr["PermissionKey"]);
+ @this.PermissionName = Null.SetNullString(dr["PermissionName"]);
}
}
}
diff --git a/DNN Platform/Library/Security/Permissions/PermissionInfoBase.cs b/DNN Platform/Library/Security/Permissions/PermissionInfoBase.cs
index 3e42cd95d07..c4815d27e98 100644
--- a/DNN Platform/Library/Security/Permissions/PermissionInfoBase.cs
+++ b/DNN Platform/Library/Security/Permissions/PermissionInfoBase.cs
@@ -7,6 +7,7 @@ namespace DotNetNuke.Security.Permissions
using System.Data;
using System.Xml.Serialization;
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
@@ -14,7 +15,7 @@ namespace DotNetNuke.Security.Permissions
/// Namespace: DotNetNuke.Security.Permissions
/// Class : PermissionInfoBase
/// PermissionInfoBase provides a base class for PermissionInfo classes.
- /// All Permission calsses have a common set of properties
+ /// All Permission classes have a common set of properties
/// - AllowAccess
/// - RoleID
/// - RoleName
@@ -25,28 +26,27 @@ namespace DotNetNuke.Security.Permissions
/// and these are implemented in this base class.
///
[Serializable]
- public abstract class PermissionInfoBase : PermissionInfo
+ public abstract class PermissionInfoBase : PermissionInfo, IPermissionInfo
{
private bool allowAccess;
private string displayName;
- private int roleID;
+ private int roleId;
private string roleName;
- private int userID;
+ private int userId;
private string username;
/// Initializes a new instance of the class.
public PermissionInfoBase()
{
- this.roleID = int.Parse(Globals.glbRoleNothing);
+ this.roleId = int.Parse(Globals.glbRoleNothing);
this.allowAccess = false;
this.roleName = Null.NullString;
- this.userID = Null.NullInteger;
+ this.userId = Null.NullInteger;
this.username = Null.NullString;
this.displayName = Null.NullString;
}
- /// Gets or sets a value indicating whether gets and sets aflag that indicates whether the user or role has permission.
- /// A Boolean.
+ ///
[XmlElement("allowaccess")]
public bool AllowAccess
{
@@ -61,8 +61,7 @@ public bool AllowAccess
}
}
- /// Gets or sets the User's DisplayName.
- /// A String.
+ ///
[XmlElement("displayname")]
public string DisplayName
{
@@ -77,24 +76,23 @@ public string DisplayName
}
}
- /// Gets or sets the Role ID.
- /// An Integer.
+ ///
[XmlElement("roleid")]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo)}.{nameof(IPermissionInfo.RoleId)} instead. Scheduled for removal in v11.0.0.")]
public int RoleID
{
get
{
- return this.roleID;
+ return ((IPermissionInfo)this).RoleId;
}
set
{
- this.roleID = value;
+ ((IPermissionInfo)this).RoleId = value;
}
}
- /// Gets or sets the Role Name.
- /// A String.
+ ///
[XmlElement("rolename")]
public string RoleName
{
@@ -109,24 +107,23 @@ public string RoleName
}
}
- /// Gets or sets the User ID.
- /// An Integer.
+ ///
[XmlElement("userid")]
+ [Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo)}.{nameof(IPermissionInfo.UserId)} instead. Scheduled for removal in v11.0.0.")]
public int UserID
{
get
{
- return this.userID;
+ return ((IPermissionInfo)this).UserId;
}
set
{
- this.userID = value;
+ ((IPermissionInfo)this).UserId = value;
}
}
- /// Gets or sets the User Name.
- /// A String.
+ ///
[XmlElement("username")]
public string Username
{
@@ -141,28 +138,43 @@ public string Username
}
}
+ ///
+ int IPermissionInfo.RoleId
+ {
+ get => this.roleId;
+ set => this.roleId = value;
+ }
+
+ ///
+ int IPermissionInfo.UserId
+ {
+ get => this.userId;
+ set => this.userId = value;
+ }
+
/// FillInternal fills the PermissionInfoBase from a Data Reader.
/// The Data Reader to use.
protected override void FillInternal(IDataReader dr)
{
- // Call the base classes fill method to populate base class proeprties
+ // Call the base classes fill method to populate base class properties
base.FillInternal(dr);
- this.UserID = Null.SetNullInteger(dr["UserID"]);
- this.Username = Null.SetNullString(dr["Username"]);
- this.DisplayName = Null.SetNullString(dr["DisplayName"]);
- if (this.UserID == Null.NullInteger)
+ var @this = (IPermissionInfo)this;
+ @this.UserId = Null.SetNullInteger(dr["UserID"]);
+ @this.Username = Null.SetNullString(dr["Username"]);
+ @this.DisplayName = Null.SetNullString(dr["DisplayName"]);
+ if (@this.UserId == Null.NullInteger)
{
- this.RoleID = Null.SetNullInteger(dr["RoleID"]);
- this.RoleName = Null.SetNullString(dr["RoleName"]);
+ @this.RoleId = Null.SetNullInteger(dr["RoleID"]);
+ @this.RoleName = Null.SetNullString(dr["RoleName"]);
}
else
{
- this.RoleID = int.Parse(Globals.glbRoleNothing);
- this.RoleName = string.Empty;
+ @this.RoleId = int.Parse(Globals.glbRoleNothing);
+ @this.RoleName = string.Empty;
}
- this.AllowAccess = Null.SetNullBoolean(dr["AllowAccess"]);
+ @this.AllowAccess = Null.SetNullBoolean(dr["AllowAccess"]);
}
}
}
diff --git a/DNN Platform/Library/Services/FileSystem/FolderManager.cs b/DNN Platform/Library/Services/FileSystem/FolderManager.cs
index f5cc561a11d..687258d7520 100644
--- a/DNN Platform/Library/Services/FileSystem/FolderManager.cs
+++ b/DNN Platform/Library/Services/FileSystem/FolderManager.cs
@@ -17,6 +17,7 @@ namespace DotNetNuke.Services.FileSystem
using System.Threading;
using System.Web;
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.ComponentModel;
@@ -695,16 +696,14 @@ public virtual void CopyParentFolderPermissions(IFolderInfo folder)
var parentFolderPath = folder.FolderPath.Substring(0, folder.FolderPath.Substring(0, folder.FolderPath.Length - 1).LastIndexOf("/", StringComparison.Ordinal) + 1);
- foreach (FolderPermissionInfo objPermission in
- this.GetFolderPermissionsFromSyncData(folder.PortalID, parentFolderPath))
+ foreach (IFolderPermissionInfo objPermission in this.GetFolderPermissionsFromSyncData(folder.PortalID, parentFolderPath))
{
- var folderPermission = new FolderPermissionInfo(objPermission)
- {
- FolderID = folder.FolderID,
- RoleID = objPermission.RoleID,
- UserID = objPermission.UserID,
- AllowAccess = objPermission.AllowAccess,
- };
+ var folderPermission = new FolderPermissionInfo(objPermission);
+ IFolderPermissionInfo iFolderPermission = folderPermission;
+ iFolderPermission.FolderId = folder.FolderID;
+ iFolderPermission.RoleId = objPermission.RoleId;
+ iFolderPermission.UserId = objPermission.UserId;
+ iFolderPermission.AllowAccess = objPermission.AllowAccess;
folder.FolderPermissions.Add(folderPermission, true);
}
diff --git a/DNN Platform/Library/Startup.cs b/DNN Platform/Library/Startup.cs
index f3702af3786..b94b0182800 100644
--- a/DNN Platform/Library/Startup.cs
+++ b/DNN Platform/Library/Startup.cs
@@ -9,6 +9,7 @@ namespace DotNetNuke
using DotNetNuke.Abstractions.Application;
using DotNetNuke.Abstractions.Logging;
using DotNetNuke.Abstractions.Portals;
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Internal;
@@ -16,6 +17,7 @@ namespace DotNetNuke
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Modules.Settings;
using DotNetNuke.Entities.Portals;
+ using DotNetNuke.Security.Permissions;
using DotNetNuke.Services.Log.EventLog;
using DotNetNuke.Services.Mail.OAuth;
using DotNetNuke.UI.Modules;
@@ -50,6 +52,8 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped();
+ services.AddScoped();
+
services.AddTransient();
services.AddTransient();
SmtpOAuthController.RegisterOAuthProviders(services);
diff --git a/DNN Platform/Modules/ResourceManager/Components/ItemsManager.cs b/DNN Platform/Modules/ResourceManager/Components/ItemsManager.cs
index d5a94d25e30..582b847a8a8 100644
--- a/DNN Platform/Modules/ResourceManager/Components/ItemsManager.cs
+++ b/DNN Platform/Modules/ResourceManager/Components/ItemsManager.cs
@@ -134,8 +134,8 @@ public void SaveFolderDetails(IFolderInfo folder, FolderDetailsRequest folderDet
}
folder.FolderPermissions.Clear();
- folder.FolderPermissions.AddRange(folderDetails.Permissions.RolePermissions.ToPermissionInfos(folderDetails.FolderId));
- folder.FolderPermissions.AddRange(folderDetails.Permissions.UserPermissions.ToPermissionInfos(folderDetails.FolderId));
+ folder.FolderPermissions.AddRange(folderDetails.Permissions.RolePermissions.AsFolderPermissions(folderDetails.FolderId));
+ folder.FolderPermissions.AddRange(folderDetails.Permissions.UserPermissions.AsFolderPermissions(folderDetails.FolderId));
FolderManager.Instance.UpdateFolder(folder);
}
diff --git a/DNN Platform/Modules/ResourceManager/Components/PermissionHelper.cs b/DNN Platform/Modules/ResourceManager/Components/PermissionHelper.cs
index b6332788819..1fbe580f9fc 100644
--- a/DNN Platform/Modules/ResourceManager/Components/PermissionHelper.cs
+++ b/DNN Platform/Modules/ResourceManager/Components/PermissionHelper.cs
@@ -4,12 +4,12 @@
namespace Dnn.Modules.ResourceManager.Components
{
- using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Dnn.Modules.ResourceManager.Services.Dto;
+ using DotNetNuke.Abstractions.Security.Permissions;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Portals;
@@ -22,24 +22,24 @@ public static class PermissionHelper
/// Adds user permissions to the dto.
/// data transfer object to extend.
/// Permission to add.
- public static void AddUserPermission(this Permissions dto, PermissionInfoBase permissionInfo)
+ public static void AddUserPermission(this Permissions dto, IPermissionInfo permissionInfo)
{
- var userPermission = dto.UserPermissions.FirstOrDefault(p => p.UserId == permissionInfo.UserID);
+ var userPermission = dto.UserPermissions.FirstOrDefault(p => p.UserId == permissionInfo.UserId);
if (userPermission == null)
{
userPermission = new UserPermission
{
- UserId = permissionInfo.UserID,
+ UserId = permissionInfo.UserId,
DisplayName = permissionInfo.DisplayName,
};
dto.UserPermissions.Add(userPermission);
}
- if (userPermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionID))
+ if (userPermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionId))
{
userPermission.Permissions.Add(new Permission
{
- PermissionId = permissionInfo.PermissionID,
+ PermissionId = permissionInfo.PermissionId,
PermissionName = permissionInfo.PermissionName,
AllowAccess = permissionInfo.AllowAccess,
});
@@ -49,30 +49,30 @@ public static void AddUserPermission(this Permissions dto, PermissionInfoBase pe
/// Adds role permissions to the dto.
/// dto to extend.
/// Permission to add.
- public static void AddRolePermission(this Permissions dto, PermissionInfoBase permissionInfo)
+ public static void AddRolePermission(this Permissions dto, IPermissionInfo permissionInfo)
{
- var rolePermission = dto.RolePermissions.FirstOrDefault(p => p.RoleId == permissionInfo.RoleID);
+ var rolePermission = dto.RolePermissions.FirstOrDefault(p => p.RoleId == permissionInfo.RoleId);
if (rolePermission == null)
{
rolePermission = new RolePermission
{
- RoleId = permissionInfo.RoleID,
+ RoleId = permissionInfo.RoleId,
RoleName = permissionInfo.RoleName,
};
dto.RolePermissions.Add(rolePermission);
}
- if (rolePermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionID))
+ if (rolePermission.Permissions.All(p => p.PermissionId != permissionInfo.PermissionId))
{
rolePermission.Permissions.Add(new Permission
{
- PermissionId = permissionInfo.PermissionID,
+ PermissionId = permissionInfo.PermissionId,
PermissionName = permissionInfo.PermissionName,
AllowAccess = permissionInfo.AllowAccess,
});
}
- }
-
+ }
+
/// Ensures the dto has the default roles.
/// dto to extend.
public static void EnsureDefaultRoles(this Permissions dto)
@@ -124,7 +124,7 @@ public static void EnsureRole(this Permissions dto, RoleInfo role, bool locked,
/// Check if the permission is for full control.
/// The to check.
/// A value indicating whether this permission is for full control.
- public static bool IsFullControl(PermissionInfo permissionInfo)
+ public static bool IsFullControl(IPermissionDefinitionInfo permissionInfo)
{
return (permissionInfo.PermissionKey == "EDIT") && PermissionProvider.Instance().SupportsFullControl();
}
@@ -132,7 +132,7 @@ public static bool IsFullControl(PermissionInfo permissionInfo)
/// Checks if the permission is for view.
/// The to check.
/// A value indicating whether the permission is for view.
- public static bool IsViewPermission(PermissionInfo permissionInfo)
+ public static bool IsViewPermission(IPermissionDefinitionInfo permissionInfo)
{
return permissionInfo.PermissionKey == "VIEW";
}
@@ -144,7 +144,7 @@ public static object GetRoles(int portalId)
{
var data = new { Groups = new List