Skip to content

Commit

Permalink
Refactored PermissionInfo and added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valadas committed Jan 29, 2024
1 parent 2a7c3ef commit e966c96
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 217 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace DotNetNuke.Security.Permissions
{
using System;
using System.Data;
using System.Data;
using System.Xml.Serialization;

using DotNetNuke.Common.Utilities;
Expand Down Expand Up @@ -41,9 +41,9 @@ public ModulePermissionInfo()
public ModulePermissionInfo(PermissionInfo permission)
: this()
{
this.ModuleDefID = permission.ModuleDefID;
this.ModuleDefId = permission.ModuleDefId;
this.PermissionCode = permission.PermissionCode;
this.PermissionID = permission.PermissionID;
this.PermissionId = permission.PermissionId;
this.PermissionKey = permission.PermissionKey;
this.PermissionName = permission.PermissionName;
}
Expand Down
79 changes: 11 additions & 68 deletions DNN Platform/Library/Security/Permissions/PermissionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DotNetNuke.Security.Permissions
using System;
using System.Data;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

using DotNetNuke.Abstractions.Security.Permissions;
Expand All @@ -16,34 +15,31 @@ namespace DotNetNuke.Security.Permissions

/// <summary>PermissionInfo provides the Entity Layer for Permissions.</summary>
[Serializable]
public class PermissionInfo : BaseEntityInfo, IPermissionDefinitionInfo, IXmlSerializable
public class PermissionInfo : BaseEntityInfo, IPermissionDefinitionInfo
{
private int permissionId;
private int moduleDefId;

/// <inheritdoc cref="IPermissionDefinitionInfo.ModuleDefId" />
[XmlIgnore]
[JsonIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionDefinitionInfo)}.{nameof(IPermissionDefinitionInfo.ModuleDefId)} instead. Scheduled for removal in v11.0.0.")]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(ModuleDefId)} instead. Scheduled for removal in v11.0.0.")]
[CLSCompliant(false)]
public int ModuleDefID
{
get => this.moduleDefId;
set => this.moduleDefId = value;
get => this.ModuleDefId;
set => this.ModuleDefId = value;
}

/// <inheritdoc />
[XmlElement("permissioncode")]
public string PermissionCode { get; set; }

/// <inheritdoc cref="IPermissionDefinitionInfo.PermissionID" />
[XmlElement("permissionid")]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionDefinitionInfo)}.{nameof(IPermissionDefinitionInfo.PermissionId)} instead. Scheduled for removal in v11.0.0.")]
[XmlIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(PermissionId)} instead. Scheduled for removal in v11.0.0.")]
[CLSCompliant(false)]
public int PermissionID
{
get => this.permissionId;
set => this.permissionId = value;
get => this.PermissionId;
set => this.PermissionId = value;
}

/// <inheritdoc />
Expand All @@ -58,64 +54,11 @@ public int PermissionID
/// <inheritdoc />
[XmlIgnore]
[JsonIgnore]
int IPermissionDefinitionInfo.ModuleDefId
{
get => this.moduleDefId;
set => this.moduleDefId = value;
}
public int ModuleDefId { get; set; }

/// <inheritdoc />
[XmlIgnore]
[JsonIgnore]
int IPermissionDefinitionInfo.PermissionId
{
get => this.permissionId;
set => this.permissionId = value;
}

/// <inheritdoc/>
public XmlSchema GetSchema()
{
return null;
}

/// <inheritdoc/>
public void ReadXml(XmlReader reader)
{
if (reader.MoveToContent() == XmlNodeType.Element && reader.LocalName == "PermissionInfo")
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
string elementName = reader.LocalName;
reader.Read();
switch (elementName)
{
case "permissioncode":
this.PermissionCode = reader.Value;
break;
case "permissionid":
var permissionId = int.Parse(reader.Value);
(this as IPermissionDefinitionInfo).PermissionId = permissionId;
break;
case "permissionkey":
this.PermissionKey = reader.Value;
break;
}
}
}
}
}

/// <inheritdoc/>
public void WriteXml(XmlWriter writer)
{
var @this = (IPermissionDefinitionInfo)this;
writer.WriteElementString(nameof(@this.PermissionCode).ToLowerInvariant(), @this.PermissionCode);
writer.WriteElementString(nameof(@this.PermissionId).ToLowerInvariant(), @this.PermissionId.ToString());
writer.WriteElementString(nameof(@this.PermissionKey).ToLowerInvariant(), @this.PermissionKey);
}
[XmlElement("permissionid")]
public int PermissionId { get; set; }

/// <summary>FillInternal fills a PermissionInfo from a Data Reader.</summary>
/// <param name="dr">The Data Reader to use.</param>
Expand Down
50 changes: 13 additions & 37 deletions DNN Platform/Library/Security/Permissions/PermissionInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,7 @@ namespace DotNetNuke.Security.Permissions
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;

/// Project : DotNetNuke
/// Namespace: DotNetNuke.Security.Permissions
/// Class : PermissionInfoBase
/// <summary>PermissionInfoBase provides a base class for PermissionInfo classes.</summary>
/// <remarks>All Permission classes have a common set of properties
/// - AllowAccess
/// - RoleID
/// - RoleName
/// - UserID
/// - Username
/// - DisplayName
///
/// and these are implemented in this base class.
/// </remarks>
/// <summary>PermissionInfoBase provides a base class for Permission classes.</summary>
[Serializable]
public abstract class PermissionInfoBase : PermissionInfo, IPermissionInfo
{
Expand Down Expand Up @@ -77,19 +64,13 @@ public string DisplayName
}

/// <inheritdoc cref="IPermissionInfo.RoleId" />
[XmlElement("roleid")]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo)}.{nameof(IPermissionInfo.RoleId)} instead. Scheduled for removal in v11.0.0.")]
[XmlIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo.RoleId)} instead. Scheduled for removal in v11.0.0.")]
[CLSCompliant(false)]
public int RoleID
{
get
{
return ((IPermissionInfo)this).RoleId;
}

set
{
((IPermissionInfo)this).RoleId = value;
}
get => this.RoleId;
set => this.RoleId = value;
}

/// <inheritdoc />
Expand All @@ -108,8 +89,9 @@ public string RoleName
}

/// <inheritdoc cref="IPermissionInfo.UserId" />
[XmlElement("userid")]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo)}.{nameof(IPermissionInfo.UserId)} instead. Scheduled for removal in v11.0.0.")]
[XmlIgnore]
[Obsolete($"Deprecated in DotNetNuke 9.13.1. Use {nameof(IPermissionInfo.UserId)} instead. Scheduled for removal in v11.0.0.")]
[CLSCompliant(false)]
public int UserID
{
get
Expand Down Expand Up @@ -139,18 +121,12 @@ public string Username
}

/// <inheritdoc />
int IPermissionInfo.RoleId
{
get => this.roleId;
set => this.roleId = value;
}
[XmlElement("roleid")]
public int RoleId { get; set; }

/// <inheritdoc />
int IPermissionInfo.UserId
{
get => this.userId;
set => this.userId = value;
}
[XmlElement("userid")]
public int UserId { get; set; }

/// <summary>FillInternal fills the PermissionInfoBase from a Data Reader.</summary>
/// <param name="dr">The Data Reader to use.</param>
Expand Down
Loading

0 comments on commit e966c96

Please sign in to comment.