From d24ef3650e4bc01c0301e00cbe5210c58732d31b Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Tue, 17 Mar 2015 13:50:33 +0100 Subject: [PATCH 1/2] U4-274 - Adds config option to disable alternative templates --- .../UmbracoSettings/IWebRoutingSection.cs | 2 + .../UmbracoSettings/WebRoutingElement.cs | 6 ++ .../config/umbracoSettings.Release.config | 7 ++- .../config/umbracoSettings.config | 7 ++- .../ContentFinderByNiceUrlAndTemplate.cs | 57 ++++++++++--------- .../Routing/PublishedContentRequestEngine.cs | 5 +- src/Umbraco.Web/Templates/TemplateRenderer.cs | 3 +- .../umbraco.presentation/NotFoundHandlers.cs | 12 ++-- src/Umbraco.Web/umbraco.presentation/page.cs | 38 +++++++------ 9 files changed, 84 insertions(+), 53 deletions(-) diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs index 03fad06d82..393387ecfa 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/IWebRoutingSection.cs @@ -6,6 +6,8 @@ bool InternalRedirectPreservesTemplate { get; } + bool DisableAlternativeTemplates { get; } + string UrlProviderMode { get; } } diff --git a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs b/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs index c1236f571d..82c5a37575 100644 --- a/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs +++ b/src/Umbraco.Core/Configuration/UmbracoSettings/WebRoutingElement.cs @@ -16,6 +16,12 @@ namespace Umbraco.Core.Configuration.UmbracoSettings get { return (bool) base["internalRedirectPreservesTemplate"]; } } + [ConfigurationProperty("disableAlternativeTemplates", DefaultValue = "false")] + public bool DisableAlternativeTemplates + { + get { return (bool) base["disableAlternativeTemplates"]; } + } + [ConfigurationProperty("urlProviderMode", DefaultValue = "AutoLegacy")] public string UrlProviderMode { diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config index dcaaa382e8..2959b0388b 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.Release.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.Release.config @@ -132,10 +132,15 @@ finder or by the alt. template. Set this option to true to preserve the template set by the finder or by the alt. template, in case of an internal redirect. (false by default, and in fact should remain false unless you know what you're doing) + @disableAlternativeTemplates + By default you can add a altTemplate querystring or append a template name to the current URL which + will make Umbraco render the content on the current page with the template you requested, for example: + http://mysite.com/about-us/?altTemplate=Home and http://mysite.com/about-us/Home would render the + "About Us" page with a template with the alias Home. Setting this setting to true stops that behavior --> + internalRedirectPreservesTemplate="false" disableAlternativeTemplates="false"> diff --git a/src/Umbraco.Web.UI/config/umbracoSettings.config b/src/Umbraco.Web.UI/config/umbracoSettings.config index 08f67f5021..e13441b802 100644 --- a/src/Umbraco.Web.UI/config/umbracoSettings.config +++ b/src/Umbraco.Web.UI/config/umbracoSettings.config @@ -290,10 +290,15 @@ finder or by the alt. template. Set this option to true to preserve the template set by the finder or by the alt. template, in case of an internal redirect. (false by default, and in fact should remain false unless you know what you're doing) + @disableAlternativeTemplates + By default you can add a altTemplate querystring or append a template name to the current URL which + will make Umbraco render the content on the current page with the template you requested, for example: + http://mysite.com/about-us/?altTemplate=Home and http://mysite.com/about-us/Home would render the + "About Us" page with a template with the alias Home. Setting this setting to true stops that behavior --> + internalRedirectPreservesTemplate="false" disableAlternativeTemplates="false"> \ No newline at end of file diff --git a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs index 21fd81a8e4..246b109dea 100644 --- a/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs +++ b/src/Umbraco.Web/Routing/ContentFinderByNiceUrlAndTemplate.cs @@ -1,57 +1,58 @@ using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core; +using Umbraco.Core.Configuration; namespace Umbraco.Web.Routing { - /// - /// Provides an implementation of that handles page nice urls and a template. - /// - /// - /// Handles /foo/bar/template where /foo/bar is the nice url of a document, and template a template alias. - /// If successful, then the template of the document request is also assigned. - /// + /// + /// Provides an implementation of that handles page nice urls and a template. + /// + /// + /// Handles /foo/bar/template where /foo/bar is the nice url of a document, and template a template alias. + /// If successful, then the template of the document request is also assigned. + /// public class ContentFinderByNiceUrlAndTemplate : ContentFinderByNiceUrl { - /// - /// Tries to find and assign an Umbraco document to a PublishedContentRequest. - /// - /// The PublishedContentRequest. - /// A value indicating whether an Umbraco document was found and assigned. - /// If successful, also assigns the template. - public override bool TryFindContent(PublishedContentRequest docRequest) + /// + /// Tries to find and assign an Umbraco document to a PublishedContentRequest. + /// + /// The PublishedContentRequest. + /// A value indicating whether an Umbraco document was found and assigned. + /// If successful, also assigns the template. + public override bool TryFindContent(PublishedContentRequest docRequest) { IPublishedContent node = null; - string path = docRequest.Uri.GetAbsolutePathDecoded(); + string path = docRequest.Uri.GetAbsolutePathDecoded(); - if (docRequest.HasDomain) - path = DomainHelper.PathRelativeToDomain(docRequest.DomainUri, path); + if (docRequest.HasDomain) + path = DomainHelper.PathRelativeToDomain(docRequest.DomainUri, path); - if (path != "/") // no template if "/" + if (path != "/") // no template if "/" { - var pos = path.LastIndexOf('/'); - var templateAlias = path.Substring(pos + 1); - path = pos == 0 ? "/" : path.Substring(0, pos); + var pos = path.LastIndexOf('/'); + var templateAlias = path.Substring(pos + 1); + path = pos == 0 ? "/" : path.Substring(0, pos); var template = ApplicationContext.Current.Services.FileService.GetTemplate(templateAlias); if (template != null) { - LogHelper.Debug("Valid template: \"{0}\"", () => templateAlias); + LogHelper.Debug("Valid template: \"{0}\"", () => templateAlias); - var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path; - node = FindContent(docRequest, route); + var route = docRequest.HasDomain ? (docRequest.Domain.RootNodeId.ToString() + path) : path; + node = FindContent(docRequest, route); - if (node != null) - docRequest.TemplateModel = template; + if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == false && node != null) + docRequest.TemplateModel = template; } else { - LogHelper.Debug("Not a valid template: \"{0}\"", () => templateAlias); + LogHelper.Debug("Not a valid template: \"{0}\"", () => templateAlias); } } else { - LogHelper.Debug("No template in path \"/\""); + LogHelper.Debug("No template in path \"/\""); } return node != null; diff --git a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs index fee5b44360..0daf1e1c00 100644 --- a/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs +++ b/src/Umbraco.Web/Routing/PublishedContentRequestEngine.cs @@ -586,8 +586,9 @@ namespace Umbraco.Web.Routing // only if the published content is the initial once, else the alternate template // does not apply // + optionnally, apply the alternate template on internal redirects - var useAltTemplate = _pcr.IsInitialPublishedContent - || (UmbracoConfig.For.UmbracoSettings().WebRouting.InternalRedirectPreservesTemplate && _pcr.IsInternalRedirectPublishedContent); + var useAltTemplate = UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == false + && (_pcr.IsInitialPublishedContent + || (UmbracoConfig.For.UmbracoSettings().WebRouting.InternalRedirectPreservesTemplate && _pcr.IsInternalRedirectPublishedContent)); string altTemplate = useAltTemplate ? _routingContext.UmbracoContext.HttpContext.Request[Constants.Conventions.Url.AltTemplate] : null; diff --git a/src/Umbraco.Web/Templates/TemplateRenderer.cs b/src/Umbraco.Web/Templates/TemplateRenderer.cs index a13ed031f8..22d6b5b54b 100644 --- a/src/Umbraco.Web/Templates/TemplateRenderer.cs +++ b/src/Umbraco.Web/Templates/TemplateRenderer.cs @@ -11,6 +11,7 @@ using Umbraco.Web.Mvc; using Umbraco.Web.Routing; using umbraco; using umbraco.cms.businesslogic.language; +using Umbraco.Core.Configuration; namespace Umbraco.Web.Templates { @@ -80,7 +81,7 @@ namespace Umbraco.Web.Templates //set the doc that was found by id contentRequest.PublishedContent = doc; //set the template, either based on the AltTemplate found or the standard template of the doc - contentRequest.TemplateModel = !AltTemplate.HasValue + contentRequest.TemplateModel = UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates || AltTemplate.HasValue == false ? ApplicationContext.Current.Services.FileService.GetTemplate(doc.TemplateId) : ApplicationContext.Current.Services.FileService.GetTemplate(AltTemplate.Value); diff --git a/src/Umbraco.Web/umbraco.presentation/NotFoundHandlers.cs b/src/Umbraco.Web/umbraco.presentation/NotFoundHandlers.cs index ecfa83b1ae..56021687bd 100644 --- a/src/Umbraco.Web/umbraco.presentation/NotFoundHandlers.cs +++ b/src/Umbraco.Web/umbraco.presentation/NotFoundHandlers.cs @@ -13,6 +13,7 @@ using umbraco.cms.businesslogic.web; using umbraco.interfaces; using Umbraco.Core.IO; using umbraco.NodeFactory; +using Umbraco.Core; namespace umbraco { @@ -277,10 +278,13 @@ namespace umbraco { { _redirectID = int.Parse(urlNode.Attributes.GetNamedItem("id").Value); - HttpContext.Current.Items["altTemplate"] = templateAlias; - HttpContext.Current.Trace.Write("umbraco.altTemplateHandler", - string.Format("Templated changed to: '{0}'", - HttpContext.Current.Items["altTemplate"])); + if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == false) + { + HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate] = templateAlias; + HttpContext.Current.Trace.Write("umbraco.altTemplateHandler", + string.Format("Template changed to: '{0}'", HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate])); + } + _succes = true; } } diff --git a/src/Umbraco.Web/umbraco.presentation/page.cs b/src/Umbraco.Web/umbraco.presentation/page.cs index 6f933ddbd3..ce2b55152b 100644 --- a/src/Umbraco.Web/umbraco.presentation/page.cs +++ b/src/Umbraco.Web/umbraco.presentation/page.cs @@ -17,6 +17,7 @@ using umbraco.cms.businesslogic.property; using umbraco.cms.businesslogic.template; using umbraco.cms.businesslogic.web; using umbraco.interfaces; +using Umbraco.Core.Configuration; using Property = umbraco.cms.businesslogic.property.Property; namespace umbraco @@ -152,22 +153,27 @@ namespace umbraco { populatePageData(node); - // Check for alternative template - if (HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate] != null && - HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate].ToString() != String.Empty) - { - _template = - umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias( - HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate].ToString()); - _elements.Add("template", _template.ToString()); - } - else if (helper.Request(Constants.Conventions.Url.AltTemplate) != String.Empty) - { - _template = - umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias(helper.Request(Constants.Conventions.Url.AltTemplate).ToLower()); - _elements.Add("template", _template.ToString()); - } - if (_template == 0) + if (UmbracoConfig.For.UmbracoSettings().WebRouting.DisableAlternativeTemplates == false) + { + // Check for alternative template + if (HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate] != null && + HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate].ToString() != String.Empty) + { + _template = + umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias( + HttpContext.Current.Items[Constants.Conventions.Url.AltTemplate].ToString()); + _elements.Add("template", _template.ToString()); + } + else if (helper.Request(Constants.Conventions.Url.AltTemplate) != String.Empty) + { + _template = + umbraco.cms.businesslogic.template.Template.GetTemplateIdFromAlias( + helper.Request(Constants.Conventions.Url.AltTemplate).ToLower()); + _elements.Add("template", _template.ToString()); + } + } + + if (_template == 0) { try { From 7210c6cd95d4ca6dd47c48cf9789e45f46436918 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Tue, 17 Mar 2015 17:58:52 +0100 Subject: [PATCH 2/2] U4-6384 Incorrect Error Message When Uploading Large File #U4-6384 Fixed Due in version 7.2.3 --- .../src/common/directives/imaging/umbimagefolder.directive.js | 2 +- .../src/common/services/umbrequesthelper.service.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/imaging/umbimagefolder.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/imaging/umbimagefolder.directive.js index 10f4663588..5b1ad4f0dd 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/imaging/umbimagefolder.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/imaging/umbimagefolder.directive.js @@ -108,7 +108,7 @@ function umbImageFolder($rootScope, assetsService, $timeout, $log, umbRequestHel //check for the file size error which can only be done with dodgy string checking scope.$on('fileuploadfail', function (e, data) { if (data.jqXHR.status === 500 && data.jqXHR.responseText.indexOf("Maximum request length exceeded") >= 0) { - notificationsService.error(data.errorThrown, "The image file size was too big, check with your site administrator to adjust the maximum size allowed"); + notificationsService.error(data.errorThrown, "The uploaded file was too large, check with your site administrator to adjust the maximum size allowed"); } else { diff --git a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js index 382c80c3e2..a494a0220a 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/umbrequesthelper.service.js @@ -225,7 +225,7 @@ function umbRequestHelper($http, $q, umbDataFormatter, angularHelper, dialogServ // we have to just check for the existence of a string value but currently that is the best way to // do this since it's very hacky/difficult to catch this on the server if (data.indexOf("Maximum request length exceeded") >= 0) { - notificationsService.error("Server error", "The image file size was too big, check with your site administrator to adjust the maximum size allowed"); + notificationsService.error("Server error", "The uploaded file was too large, check with your site administrator to adjust the maximum size allowed"); } else if (Umbraco.Sys.ServerVariables["isDebuggingEnabled"] === true) { //show a ysod dialog