Skip to content

Commit

Permalink
Moved UserMode from PortalSettings to Personalization class (#4225)
Browse files Browse the repository at this point in the history
* Moved UserMode from PortalSettings to Personalization class

Closes #4213

I am open to any feedback on this, I do believe this way would not be a breaking change...

* Update DNN Platform/Library/Services/Personalization/Personalization.cs

Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>

* Update DNN Platform/Library/Services/Personalization/Personalization.cs

Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>

* Prevent duplication of code

Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>
  • Loading branch information
valadas and bdukes authored Oct 20, 2020
1 parent 4afcc81 commit 37c119a
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Dnn.Modules.Console.Components
using DotNetNuke.Entities.Modules;

/// <summary>Implements the module's business controller interface(s).</summary>

public class BusinessController : IUpgradeable
{
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ protected void CmdAddModuleClick(object sender, EventArgs e)
}

// set view mode to edit after add module.
if (this.PortalSettings.UserMode != PortalSettings.Mode.Edit)
if (Personalization.GetUserMode() != PortalSettings.Mode.Edit)
{
Personalization.SetProfile("Usability", "UserMode" + this.PortalSettings.PortalId, "EDIT");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ private void AutoSetUserMode()
HttpCookie cookie = this.Request.Cookies["StayInEditMode"];
if (cookie != null && cookie.Value == "YES")
{
if (PortalSettings.Current.UserMode != PortalSettings.Mode.Edit)
if (Personalization.GetUserMode() != PortalSettings.Mode.Edit)
{
this.SetUserMode("EDIT");
this.SetLastPageHistory(pageId);
Expand All @@ -998,7 +998,7 @@ private void AutoSetUserMode()
if (lastPageId != pageId && !isShowAsCustomError)
{
// navigate between pages
if (PortalSettings.Current.UserMode != PortalSettings.Mode.View)
if (Personalization.GetUserMode() != PortalSettings.Mode.View)
{
this.SetUserMode("VIEW");
this.SetLastPageHistory(pageId);
Expand Down
5 changes: 3 additions & 2 deletions DNN Platform/Library/Common/Globals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace DotNetNuke.Common
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Personalization;
using DotNetNuke.Services.Url.FriendlyUrl;
using DotNetNuke.UI.Utilities;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -1709,7 +1710,7 @@ public static bool IsEditMode()
return false;
}

return portalSettings.UserMode == PortalSettings.Mode.Edit && TabPermissionController.CanAddContentToPage();
return Personalization.GetUserMode() == PortalSettings.Mode.Edit && TabPermissionController.CanAddContentToPage();
}

/// -----------------------------------------------------------------------------
Expand All @@ -1722,7 +1723,7 @@ public static bool IsEditMode()
/// -----------------------------------------------------------------------------
public static bool IsLayoutMode()
{
return TabPermissionController.CanAddContentToPage() && PortalController.Instance.GetCurrentPortalSettings().UserMode == PortalSettings.Mode.Layout;
return TabPermissionController.CanAddContentToPage() && Personalization.GetUserMode() == PortalSettings.Mode.Layout;
}

/// <summary>
Expand Down
46 changes: 19 additions & 27 deletions DNN Platform/Library/Entities/Portals/PortalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,24 @@ public enum ControlPanelPermission
ModuleEditor,
}

/// <summary>
/// Enumerates the possible view modes of a page.
/// </summary>
public enum Mode
{
/// <summary>
/// The user is viewing the page in normal mode like a visitor.
/// </summary>
View,

/// <summary>
/// The user is editing the page.
/// </summary>
Edit,

/// <summary>
/// The user is viewing the page in layout mode.
/// </summary>
Layout,
}

Expand Down Expand Up @@ -201,35 +215,13 @@ public UserInfo UserInfo
}
}

/// <summary>
/// Gets the mode the user is viewing the page in.
/// </summary>
[Obsolete("Deprecated in v9.8.1, use Personalization.GetUserMode() instead, Scheduled for removal in v10.")]
public Mode UserMode
{
get
{
Mode mode;
if (HttpContext.Current != null && HttpContext.Current.Request.IsAuthenticated)
{
mode = this.DefaultControlPanelMode;
string setting = Convert.ToString(Personalization.GetProfile("Usability", "UserMode" + this.PortalId));
switch (setting.ToUpper())
{
case "VIEW":
mode = Mode.View;
break;
case "EDIT":
mode = Mode.Edit;
break;
case "LAYOUT":
mode = Mode.Layout;
break;
}
}
else
{
mode = Mode.View;
}

return mode;
}
get => Personalization.GetUserMode();
}

/// <summary>
Expand Down
Loading

0 comments on commit 37c119a

Please sign in to comment.