From c8c4e2437b18495690f9ea0448b1761d9fb983e3 Mon Sep 17 00:00:00 2001 From: "NielsHartvig@UMBRACORATI.localdomain" Date: Thu, 25 Oct 2012 13:00:31 -0200 Subject: [PATCH] Implements U4-1022: Request: Disable Canvas mode by default --- .../Configuration/UmbracoSettings.cs | 45 ++- .../config/umbracoSettings.Release.config | 381 +++++++++--------- .../umbraco/Trees/loadContent.cs | 11 +- .../umbraco/canvas.aspx.cs | 6 +- .../umbraco/login.aspx.cs | 24 +- .../umbraco/users/EditUser.aspx.cs | 58 ++- src/umbraco.businesslogic/UmbracoSettings.cs | 10 +- 7 files changed, 298 insertions(+), 237 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings.cs b/src/Umbraco.Core/Configuration/UmbracoSettings.cs index 2b5ef086fb..9c3bd8bdc7 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings.cs @@ -221,22 +221,37 @@ namespace Umbraco.Core.Configuration } } - /// - /// Keep user alive as long as they have their browser open? Default is true - /// - public static bool KeepUserLoggedIn - { - get - { - var value = GetKey("/settings/security/keepUserLoggedIn"); - bool result; - if (!string.IsNullOrEmpty(value) && bool.TryParse(value, out result)) - return result; - return true; - } - } + /// + /// Keep user alive as long as they have their browser open? Default is true + /// + public static bool KeepUserLoggedIn + { + get + { + var value = GetKey("/settings/security/keepUserLoggedIn"); + bool result; + if (!string.IsNullOrEmpty(value) && bool.TryParse(value, out result)) + return result; + return true; + } + } - /// + /// + /// Enables the experimental canvas (live) editing on the frontend of the website + /// + public static bool EnableCanvasEditing + { + get + { + var value = GetKey("/settings/content/EnableCanvasEditing"); + bool result; + if (!string.IsNullOrEmpty(value) && bool.TryParse(value, out result)) + return result; + return true; + } + } + + /// /// Show disabled users in the tree in the Users section in the backoffice /// public static bool HideDisabledUsersInBackoffice diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config index d62cc88e51..d213e0909e 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config @@ -1,158 +1,161 @@ - - - - jpeg,jpg,gif,bmp,png,tiff,tif - - alt,border,class,style,align,id,name,onclick,usemap - - - - umbracoWidth - umbracoHeight - umbracoBytes - umbracoExtension - - - - - - /scripts - - js,xml - - false - + + + + jpeg,jpg,gif,bmp,png,tiff,tif + + alt,border,class,style,align,id,name,onclick,usemap + + + + umbracoWidth + umbracoHeight + umbracoBytes + umbracoExtension + + + + + + /scripts + + js,xml + + false + - - True - - - + - 1 - - - - your@email.here - + 1 + + + + your@email.here + - - True + + True - - False + + False - - UTF8 + + UTF8 - - false + + false - - - true + + + true - - True + + True - - True + + True - - False + + False - - False + + False - - text + + text - - In Preview Mode - click to end]]> + + false - - - 1800 + + In Preview Mode - click to end]]> - - - - false - + + + 1800 - - - true + + + + false + - - false - + + + true - - - false - - true - - - - - - - - - - - - - plus - star - - - ae - oe - aa - ae - oe - ue - ss - ae - oe - - - - - - + + false + - - true - WebForms - + + + false + + true + + - + + + + + + + + + + plus + star + + + ae + oe + aa + ae + oe + ue + ss + ae + oe + - + + + + + + + true + WebForms + - - - - cs - vb - - + + + + cs + vb + + - - - - - p - div - ul - span - - - + + p + div + ul + span + + + - - - + + + - - + + - - - true - true - - - - - - - + + true + true + + + + + + + - - - - + + + + - - - - - 0 - - - - - - - + + + + + 0 + + + + + + + - - - - - your-username - your-username - your-username - your-username - your-username - - css,xslt - + + + + + your-username + your-username + your-username + your-username + your-username + + css,xslt + - - - - - + + + + + - - - - - UsersMembershipProvider - - + + + + + UsersMembershipProvider + + - - - - - + + + + + diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadContent.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadContent.cs index ada4aad1f6..f34a5365c8 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadContent.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/Trees/loadContent.cs @@ -87,7 +87,7 @@ namespace umbraco allowedRootActions.Add(ActionSort.Instance); List allowedMenu = GetUserAllowedActions(allowedRootActions, nodeActions); actions.AddRange(allowedMenu); - if (allowedMenu.Count > 0 ) + if (allowedMenu.Count > 0) actions.Add(ContextMenuSeperator.Instance); // default actions for all users @@ -102,7 +102,10 @@ namespace umbraco { actions.Clear(); actions.Add(ActionNew.Instance); - actions.Add(ActionLiveEdit.Instance); + if (UmbracoSettings.EnableCanvasEditing) + { + actions.Add(ActionLiveEdit.Instance); + } actions.Add(ContextMenuSeperator.Instance); actions.Add(ActionDelete.Instance); actions.Add(ContextMenuSeperator.Instance); @@ -124,7 +127,7 @@ namespace umbraco actions.Add(ActionNotify.Instance); actions.Add(ActionSendToTranslate.Instance); actions.Add(ContextMenuSeperator.Instance); - actions.Add(ActionRefresh.Instance); + actions.Add(ActionRefresh.Instance); } /// @@ -147,7 +150,7 @@ namespace umbraco } else { - rootNode = CreateNode(doc, RootNodeActions); + rootNode = CreateNode(doc, RootNodeActions); } } else diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/canvas.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/canvas.aspx.cs index acfe99e253..44d5441efe 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/canvas.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/canvas.aspx.cs @@ -1,5 +1,6 @@ using System; using umbraco.BasePages; +using umbraco.businesslogic.Exceptions; namespace umbraco.presentation { @@ -7,7 +8,7 @@ namespace umbraco.presentation { protected void Page_Load(object sender, EventArgs e) { - if (base.getUser() != null) + if ((UmbracoSettings.EnableCanvasEditing || !String.IsNullOrEmpty(UmbracoContext.Current.Request["umbSkinning"]) ) && base.getUser() != null) { UmbracoContext.Current.LiveEditingContext.Enabled = true; @@ -20,6 +21,9 @@ namespace umbraco.presentation Response.Redirect(redirUrl + (string.IsNullOrEmpty(UmbracoContext.Current.Request["umbSkinning"]) ? "" : "?umbSkinning=true") + (string.IsNullOrEmpty(UmbracoContext.Current.Request["umbSkinningConfigurator"]) ? "" : "&umbSkinningConfigurator=true"), true); } + else if (!UmbracoSettings.EnableCanvasEditing) + throw new UserAuthorizationException( + "Canvas editing isn't enabled. It can be enabled via the UmbracoSettings.config"); else { throw new Exception("User not logged in"); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/login.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/login.aspx.cs index 9e56dfd0c6..e07d7ff2f9 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/login.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/login.aspx.cs @@ -25,18 +25,18 @@ namespace umbraco.cms.presentation { protected umbWindow treeWindow; - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); - ClientLoader.DataBind(); + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + ClientLoader.DataBind(); // validate redirect url - string redirUrl = Request["redir"]; + string redirUrl = Request["redir"]; if (!String.IsNullOrEmpty(redirUrl)) { validateRedirectUrl(redirUrl); } - } + } protected override void OnPreRender(EventArgs e) @@ -90,7 +90,7 @@ namespace umbraco.cms.presentation doLogin(u); // Check if the user should be redirected to live editing - if (u.DefaultToLiveEditing) + if (UmbracoSettings.EnableCanvasEditing && u.DefaultToLiveEditing) { int startNode = u.StartNodeId; // If the startnode is -1 (access to all content), we'll redirect to the top root node @@ -110,6 +110,11 @@ namespace umbraco.cms.presentation string redir = String.Format("{0}/canvas.aspx?redir=/{1}.aspx", SystemDirectories.Umbraco, startNode); Response.Redirect(redir, true); } + else if (u.DefaultToLiveEditing) + { + throw new UserAuthorizationException( + "Canvas editing isn't enabled. It can be enabled via the UmbracoSettings.config"); + } if (hf_height.Value != "undefined") { @@ -126,7 +131,8 @@ namespace umbraco.cms.presentation Response.Redirect(redirUrl, true); } } - else { + else + { loginError.Visible = true; } } @@ -158,7 +164,7 @@ namespace umbraco.cms.presentation return String.Equals(HttpContext.Current.Request.Url.Host, absoluteUri.Host, StringComparison.OrdinalIgnoreCase); } - + bool isLocal = !url.StartsWith("http:", StringComparison.OrdinalIgnoreCase) && !url.StartsWith("https:", StringComparison.OrdinalIgnoreCase) && Uri.IsWellFormedUriString(url, UriKind.Relative); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs index 75f4bcde76..c61fa281ac 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/users/EditUser.aspx.cs @@ -77,6 +77,9 @@ namespace umbraco.cms.presentation.user throw new Exception("Admin users can only be edited by admins"); } + // check if canvas editing is enabled + DefaultToLiveEditing.Visible = UmbracoSettings.EnableCanvasEditing; + // Populate usertype list foreach (UserType ut in UserType.getAll) { @@ -152,7 +155,10 @@ namespace umbraco.cms.presentation.user //Generel umrbaco access Pane ppAccess = new Pane(); - ppAccess.addProperty(ui.Text("user", "defaultToLiveEditing", base.getUser()), DefaultToLiveEditing); + if (UmbracoSettings.EnableCanvasEditing) + { + ppAccess.addProperty(ui.Text("user", "defaultToLiveEditing", base.getUser()), DefaultToLiveEditing); + } ppAccess.addProperty(ui.Text("user", "noConsole", base.getUser()), NoConsole); ppAccess.addProperty(ui.Text("user", "disabled", base.getUser()), Disabled); @@ -183,13 +189,14 @@ namespace umbraco.cms.presentation.user setupForm(); setupChannel(); - ClientTools - .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) + ClientTools + .SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias) .SyncTree(UID.ToString(), IsPostBack); } - void sectionValidator_ServerValidate(object source, ServerValidateEventArgs args) { + void sectionValidator_ServerValidate(object source, ServerValidateEventArgs args) + { args.IsValid = false; if (lapps.SelectedIndex >= 0) @@ -382,20 +389,24 @@ namespace umbraco.cms.presentation.user /// The instance containing the event data. private void saveUser_Click(object sender, ImageClickEventArgs e) { - if (base.IsValid) { - try { + if (base.IsValid) + { + try + { MembershipUser user = Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].GetUser(u.LoginName, true); string tempPassword = ((controls.passwordChanger)passw.Controls[0]).Password; - if (!string.IsNullOrEmpty(tempPassword.Trim())) { + if (!string.IsNullOrEmpty(tempPassword.Trim())) + { // make sure password is not empty if (string.IsNullOrEmpty(u.Password)) u.Password = "default"; user.ChangePassword(u.Password, tempPassword); } // Is it using the default membership provider - if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is UsersMembershipProvider) { + if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is UsersMembershipProvider) + { // Save user in membership provider UsersMembershipUser umbracoUser = user as UsersMembershipUser; umbracoUser.FullName = uname.Text.Trim(); @@ -406,7 +417,9 @@ namespace umbraco.cms.presentation.user // Save user details u.Email = email.Text.Trim(); u.Language = userLanguage.SelectedValue; - } else { + } + else + { u.Name = uname.Text.Trim(); u.Language = userLanguage.SelectedValue; u.UserType = UserType.GetUserType(int.Parse(userType.SelectedValue)); @@ -417,11 +430,11 @@ namespace umbraco.cms.presentation.user u.LoginName = lname.Text; //u.StartNodeId = int.Parse(startNode.Value); - + int startNode; - if(!int.TryParse(contentPicker.Value, out startNode)) + if (!int.TryParse(contentPicker.Value, out startNode)) { - //set to default if nothing is choosen + //set to default if nothing is choosen if (u.StartNodeId > 0) startNode = u.StartNodeId; else @@ -449,18 +462,23 @@ namespace umbraco.cms.presentation.user u.clearApplications(); - foreach (ListItem li in lapps.Items) { + foreach (ListItem li in lapps.Items) + { if (li.Selected) u.addApplication(li.Value); } u.Save(); // save data - if (cName.Text != "") { + if (cName.Text != "") + { Channel c; - try { + try + { c = new Channel(u.Id); - } catch { + } + catch + { c = new Channel(); c.User = u; } @@ -484,11 +502,15 @@ namespace umbraco.cms.presentation.user } speechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editUserSaved", base.getUser()), ""); - } catch (Exception ex) { + } + catch (Exception ex) + { speechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", base.getUser()), ""); Log.Add(LogTypes.Error, 0, ex.Message); } - } else { + } + else + { speechBubble(speechBubbleIcon.error, ui.Text("speechBubbles", "editUserError", base.getUser()), ""); } } diff --git a/src/umbraco.businesslogic/UmbracoSettings.cs b/src/umbraco.businesslogic/UmbracoSettings.cs index 6e30200699..22133c3945 100644 --- a/src/umbraco.businesslogic/UmbracoSettings.cs +++ b/src/umbraco.businesslogic/UmbracoSettings.cs @@ -113,7 +113,15 @@ namespace umbraco /// public static bool KeepUserLoggedIn { - get { return Umbraco.Core.Configuration.UmbracoSettings.KeepUserLoggedIn; } + get { return Umbraco.Core.Configuration.UmbracoSettings.KeepUserLoggedIn; } + } + + /// + /// Enables the experimental canvas (live) editing on the frontend of the website + /// + public static bool EnableCanvasEditing + { + get { return Umbraco.Core.Configuration.UmbracoSettings.EnableCanvasEditing; } } ///