Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Top level pages #5118

Merged
merged 6 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion DNN Platform/Library/Common/Utilities/DataCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ public class DataCache

public const string PortalGroupsCacheKey = "PortalGroups";
public const CacheItemPriority PortalGroupsCachePriority = CacheItemPriority.High;
public const int PortalGroupsCacheTimeOut = 20;
public const int PortalGroupsCacheTimeOut = 20;

public const string PortalPermissionCacheKey = "PortalPermission{0}";
public const CacheItemPriority PortalPermissionCachePriority = CacheItemPriority.High;
public const int PortalPermissionCacheTimeOut = 20;

// Tab cache keys
public const string TabCacheKey = "Tab_Tabs{0}";
Expand Down Expand Up @@ -434,6 +438,11 @@ public static void ClearTabPermissionsCache(int PortalId)
RemoveCache(string.Format(TabPermissionCacheKey, PortalId));
}

public static void ClearPortalPermissionsCache(int PortalId)
{
RemoveCache(string.Format(PortalPermissionCacheKey, PortalId));
}

public static void ClearUserCache(int PortalId, string username)
{
RemoveCache(string.Format(UserCacheKey, PortalId, username));
Expand Down
32 changes: 32 additions & 0 deletions DNN Platform/Library/Data/DataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,38 @@ public virtual int AddFolderPermission(int folderId, int permissionId, int roleI
allowAccess,
this.GetNull(userId),
createdByUserID);
}

public virtual IDataReader GetPortalPermissionsByPortal(int portalId)
{
return this.ExecuteReader("GetPortalPermissionsByPortal", this.GetNull(portalId));
}

public virtual int AddPortalPermission(int portalId, int permissionId, int roleId, bool allowAccess, int userId, int createdByUserId)
{
return this.ExecuteScalar<int>(
"SaveTabPermission",
portalId,
permissionId,
this.GetRoleNull(roleId),
allowAccess,
this.GetNull(userId),
createdByUserId);
}

public virtual void DeletePortalPermission(int portalPermissionId)
{
this.ExecuteNonQuery("DeletePortalPermission", portalPermissionId);
}

public virtual void DeletePortalPermissionsByPortalID(int portalId)
{
this.ExecuteNonQuery("DeletePortalPermissionsByPortalID", portalId);
}

public virtual void DeletePortalPermissionsByUserID(int portalId, int userId)
{
this.ExecuteNonQuery("DeletePortalPermissionsByUserID", portalId, userId);
}

public virtual void DeleteFolderPermission(int folderPermissionId)
Expand Down
4 changes: 4 additions & 0 deletions DNN Platform/Library/DotNetNuke.Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,12 @@
<Compile Include="Security\Cookies\PersistedAuthCookie.cs" />
<Compile Include="Security\FIPSCompliant.cs" />
<Compile Include="Security\Membership\AspNetMembershipProvider.cs" />
<Compile Include="Security\Permissions\ComparePortalPermissions.cs" />
<Compile Include="Security\Permissions\CorePermissionProvider.cs" />
<Compile Include="Security\Permissions\IFolderPermissionController.cs" />
<Compile Include="Security\Permissions\PortalPermissionController.cs" />
<Compile Include="Security\Permissions\PortalPermissionInfo.cs" />
<Compile Include="Security\Permissions\PortalPermissionCollection.cs" />
<Compile Include="Security\Profile\DNNProfileProvider.cs" />
<Compile Include="Security\RegistrationSettings.cs" />
<Compile Include="Security\Roles\DNNRoleProvider.cs" />
Expand Down
13 changes: 13 additions & 0 deletions DNN Platform/Library/Entities/Portals/PortalInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace DotNetNuke.Entities.Portals
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Entities.Users;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;

/// <summary>
Expand Down Expand Up @@ -55,6 +56,7 @@ public class PortalInfo : BaseEntityInfo, IHydratable, IPortalInfo
private string _administratorRoleName;
private int _pages = Null.NullInteger;
private string _registeredRoleName;
private PortalPermissionCollection permissions;

private int _users;

Expand Down Expand Up @@ -226,6 +228,17 @@ public int PortalID
set => this.ThisAsInterface.PortalId = value;
}

/// <summary>Gets the permissions collection for the portal.</summary>
[XmlArray("portalpermissions")]
[XmlArrayItem("permission")]
public PortalPermissionCollection PortalPermissions
{
get
{
return this.permissions ?? (this.permissions = new PortalPermissionCollection(PortalPermissionController.GetPortalPermissions(this.ThisAsInterface.PortalId)));
}
}

/// <inheritdoc />
int IPortalInfo.PortalGroupId { get; set; }

Expand Down
5 changes: 4 additions & 1 deletion DNN Platform/Library/Obsolete/EventLogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,10 @@ public enum EventLogType
WEBSERVER_DISABLED = 150,
WEBSERVER_ENABLED = 151,
WEBSERVER_PINGFAILED = 152,
FOLDER_MOVED = 153,
FOLDER_MOVED = 153,
PORTALPERMISSION_DELETED = 154,
PORTALPERMISSION_CREATED = 155,
PORTALPERMISSION_UPDATED = 156,
}

[Obsolete("Deprecated in 9.8.0. Use Dependency Injection to resolve 'DotNetNuke.Abstractions.Logging.IEventLogger' instead. Scheduled for removal in v11.0.0.")]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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.Collections;

/// -----------------------------------------------------------------------------
/// Project : DotNetNuke
/// Namespace: DotNetNuke.Security.Permissions
/// Class : ComparePortalPermissions
/// -----------------------------------------------------------------------------
/// <summary>
/// ComparePortalPermissions provides the a custom IComparer implementation for
/// PortalPermissionInfo objects.
/// </summary>
/// -----------------------------------------------------------------------------
internal class ComparePortalPermissions : IComparer
{
/// <inheritdoc/>
public int Compare(object x, object y)
{
return ((PortalPermissionInfo)x).PortalPermissionID.CompareTo(((PortalPermissionInfo)y).PortalPermissionID);
}
}
}
179 changes: 175 additions & 4 deletions DNN Platform/Library/Security/Permissions/PermissionProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// 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

using System.Linq;
using DotNetNuke.Abstractions.Portals;

namespace DotNetNuke.Security.Permissions
{
using System;
Expand Down Expand Up @@ -377,7 +381,7 @@ private bool HasPagePermission(TabInfo tab, string permissionKey)
{
return (PortalSecurity.IsInRoles(tab.TabPermissions.ToString(permissionKey))
|| PortalSecurity.IsInRoles(tab.TabPermissions.ToString(AdminPagePermissionKey)))
&& !PortalSecurity.IsDenied(tab.TabPermissions.ToString(permissionKey));
&& !PortalSecurity.IsDenied(tab.TabPermissions.ToString(permissionKey));

// Deny on Edit permission on page shouldn't take away any other explicitly Allowed
// &&!PortalSecurity.IsDenied(tab.TabPermissions.ToString(AdminPagePermissionKey));
Expand Down Expand Up @@ -1263,5 +1267,172 @@ public virtual bool HasDesktopModulePermission(DesktopModulePermissionCollection
{
return PortalSecurity.IsInRoles(desktopModulePermissions.ToString(permissionKey));
}

/// -----------------------------------------------------------------------------
/// <summary>
/// DeletePortalPermissionsByUser deletes a user's Portal Permissions in the Database.
/// </summary>
/// <param name="user">The user.</param>
/// -----------------------------------------------------------------------------
public virtual void DeletePortalPermissionsByUser(UserInfo user)
{
this.dataProvider.DeletePortalPermissionsByUserID(user.PortalID, user.UserID);
DataCache.ClearPortalPermissionsCache(user.PortalID);
}

/// -----------------------------------------------------------------------------
/// <summary>
/// GetPortalPermissions gets a PortalPermissionCollection.
/// </summary>
/// <param name="portalId">The ID of the portal.</param>
/// <param name="portalId">The ID of the portal.</param>
/// <returns></returns>
/// -----------------------------------------------------------------------------
public virtual PortalPermissionCollection GetPortalPermissions(int portalId)
{
// Get the Portal PortalPermission Dictionary
var dicPortalPermissions = this.GetPortalPermissionsDic(portalId);

// Get the Collection from the Dictionary
var bFound = dicPortalPermissions.TryGetValue(portalId, out PortalPermissionCollection portalPermissions);
if (!bFound)
{
// Return empty collection
portalPermissions = new PortalPermissionCollection();
}

return portalPermissions;
}

/// -----------------------------------------------------------------------------
/// <summary>
/// GetPortalPermissions gets a Dictionary of PortalPermissionCollections by
/// PortalId.
/// </summary>
/// <param name="portalID">The ID of the portal.</param>
/// -----------------------------------------------------------------------------
private Dictionary<int, PortalPermissionCollection> GetPortalPermissionsDic(int portalID)
{
string cacheKey = string.Format(DataCache.PortalPermissionCacheKey, portalID);
return CBO.GetCachedObject<Dictionary<int, PortalPermissionCollection>>(
new CacheItemArgs(cacheKey, DataCache.PortalPermissionCacheTimeOut, DataCache.PortalPermissionCachePriority, portalID),
this.GetPortalPermissionsCallBack);
}

/// -----------------------------------------------------------------------------
/// <summary>
/// GetPortalPermissionsCallBack gets a Dictionary of PortalPermissionCollections.
/// </summary>
/// <param name="cacheItemArgs">The CacheItemArgs object that contains the parameters
/// needed for the database call.</param>
/// -----------------------------------------------------------------------------
private object GetPortalPermissionsCallBack(CacheItemArgs cacheItemArgs)
{
var portalID = (int)cacheItemArgs.ParamList[0];
var dic = new Dictionary<int, PortalPermissionCollection>();

if (portalID > -1)
{
var dr = this.dataProvider.GetPortalPermissionsByPortal(portalID);
try
{
while (dr.Read())
{
// fill business object
var portalPermissionInfo = CBO.FillObject<PortalPermissionInfo>(dr, false);

// add Portal Permission to dictionary
if (dic.ContainsKey(portalPermissionInfo.PortalID))
{
// Add TabPermission to TabPermission Collection already in dictionary for TabId
dic[portalPermissionInfo.PortalID].Add(portalPermissionInfo);
}
else
{
// Create new PortalPermission Collection for PortalId
var collection = new PortalPermissionCollection { portalPermissionInfo };

// Add Collection to Dictionary
dic.Add(portalPermissionInfo.PortalID, collection);
}
}
}
catch (Exception exc)
{
Exceptions.LogException(exc);
}
finally
{
// close datareader
CBO.CloseDataReader(dr, true);
}
}

return dic;
}

/// -----------------------------------------------------------------------------
/// <summary>
/// HasPortalPermission checks whether the current user has a specific Portal Permission.
/// </summary>
/// <param name="portalPermissions">The Permissions for the Portal.</param>
/// <param name="permissionKey">The Permission to check.</param>
/// <returns></returns>
/// -----------------------------------------------------------------------------
public virtual bool HasPortalPermission(PortalPermissionCollection portalPermissions, string permissionKey)
{
bool hasPermission = false;
if (permissionKey.Contains(","))
{
if (permissionKey.Split(',').Any(permission => PortalSecurity.IsInRoles(portalPermissions.ToString(permission))))
{
hasPermission = true;
}
}
else
{
hasPermission = PortalSecurity.IsInRoles(portalPermissions.ToString(permissionKey));
}

return hasPermission;
}

/// -----------------------------------------------------------------------------
/// <summary>
/// SavePortalPermissions saves a Portal's permissions.
/// </summary>
/// <param name="portal">The Portal to update.</param>
/// -----------------------------------------------------------------------------
public virtual void SavePortalPermissions(PortalInfo portal)
{
var objCurrentPortalPermissions = this.GetPortalPermissions(portal.PortalID);
if (!objCurrentPortalPermissions.CompareTo(portal.PortalPermissions))
{
var portalSettings = PortalController.Instance.GetCurrentPortalSettings();
var userId = UserController.Instance.GetCurrentUserInfo().UserID;

if (objCurrentPortalPermissions.Count > 0)
{
this.dataProvider.DeletePortalPermissionsByPortalID(portal.PortalID);
EventLogController.Instance.AddLog(portal, portalSettings, userId, string.Empty, EventLogController.EventLogType.PORTALPERMISSION_DELETED);
}

if (portal.PortalPermissions != null && portal.PortalPermissions.Count > 0)
{
foreach (PortalPermissionInfo objPortalPermission in portal.PortalPermissions)
{
objPortalPermission.PortalPermissionID = this.dataProvider.AddPortalPermission(
portal.PortalID,
objPortalPermission.PermissionID,
objPortalPermission.RoleID,
objPortalPermission.AllowAccess,
objPortalPermission.UserID,
userId);
}

EventLogController.Instance.AddLog(portal, portalSettings, userId, string.Empty, EventLogController.EventLogType.PORTALPERMISSION_CREATED);
}
}
}
}
}
Loading