Skip to content

Commit

Permalink
Merge branch 'release/9.4.x' into fix-merge-build
Browse files Browse the repository at this point in the history
  • Loading branch information
valadas authored Oct 18, 2019
2 parents a7cc452 + 6eef816 commit 8ee3c08
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions DNN Platform/Library/Entities/Modules/ModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
using DotNetNuke.Entities.Content;
using DotNetNuke.Entities.Content.Common;
using DotNetNuke.Entities.Content.Taxonomy;
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Entities.Modules.Definitions;
using DotNetNuke.Entities.Portals;
Expand Down Expand Up @@ -250,6 +251,90 @@ private void CopyTabModuleSettingsInternal(ModuleInfo fromModule, ModuleInfo toM
}
}

/// <summary>
/// Checks whether module VIEW permission is inherited from its tab
/// </summary>
/// <param name="module">The module</param>
/// <param name="permission">The module permission.</param>
private bool IsModuleViewPermissionInherited(ModuleInfo module, ModulePermissionInfo permission)
{
Requires.NotNull(module);

Requires.NotNull(permission);

var permissionViewKey = "VIEW";

if (!module.InheritViewPermissions || permission.PermissionKey != permissionViewKey)
{
return false;
}

var tabPermissions = TabPermissionController.GetTabPermissions(module.TabID, module.PortalID);

return tabPermissions?.Where(x => x.RoleID == permission.RoleID && x.PermissionKey == permissionViewKey).Any() == true;
}

/// <summary>
/// Checks whether given permission is granted for translator role
/// </summary>
/// <param name="permission">The module permission.</param>
/// <param name="portalId">The portal ID.</param>
/// <param name="culture">The culture code.</param>
private bool IsTranslatorRolePermission(ModulePermissionInfo permission, int portalId, string culture)
{
Requires.NotNull(permission);

if (string.IsNullOrWhiteSpace(culture) || portalId == Null.NullInteger)
{
return false;
}

var translatorSettingKey = $"DefaultTranslatorRoles-{ culture }";

var translatorSettingValue =
PortalController.GetPortalSetting(translatorSettingKey, portalId, null) ??
HostController.Instance.GetString(translatorSettingKey, null);

var translatorRoles =
translatorSettingValue?.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

return translatorRoles?.Any(r => r.Equals(permission.RoleName, StringComparison.OrdinalIgnoreCase)) == true;
}

/// <summary>
/// Copies permissions from source to new tab
/// </summary>
/// <param name="sourceModule">Source module.</param>
/// <param name="newModule">New module.</param>
private void CopyModulePermisions(ModuleInfo sourceModule, ModuleInfo newModule)
{
Requires.NotNull(sourceModule);

Requires.NotNull(newModule);

foreach (ModulePermissionInfo permission in sourceModule.ModulePermissions)
{
// skip inherited view and translator permissions
if (IsModuleViewPermissionInherited(newModule, permission) ||
IsTranslatorRolePermission(permission, sourceModule.PortalID, sourceModule.CultureCode))
{
continue;
}

// need to force vew permission to be copied
permission.PermissionKey = newModule.InheritViewPermissions && permission.PermissionKey == "VIEW" ?
null :
permission.PermissionKey;

AddModulePermission(
newModule,
permission,
permission.RoleID,
permission.UserID,
permission.AllowAccess);
}
}

private static ModuleInfo DeserializeModule(XmlNode nodeModule, XmlNode nodePane, int portalId, int tabId, int moduleDefId)
{
//Create New Module
Expand Down Expand Up @@ -615,6 +700,9 @@ private int LocalizeModuleInternal(ModuleInfo sourceModule)
}
}

// copy permisions from source to new module
CopyModulePermisions(sourceModule, newModule);

//Add Module
AddModuleInternal(newModule);

Expand Down

0 comments on commit 8ee3c08

Please sign in to comment.