From fb89c3da3c03ebb1def64613f778e07123e8479e Mon Sep 17 00:00:00 2001 From: Claus Date: Fri, 9 Feb 2018 12:58:50 +0100 Subject: [PATCH 1/3] allowing to disable the template check when sending content through to render. --- src/Umbraco.Web/Features/DisabledFeatures.cs | 8 ++++++- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 25 +++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Web/Features/DisabledFeatures.cs b/src/Umbraco.Web/Features/DisabledFeatures.cs index d771c101f4..a4adb42557 100644 --- a/src/Umbraco.Web/Features/DisabledFeatures.cs +++ b/src/Umbraco.Web/Features/DisabledFeatures.cs @@ -20,5 +20,11 @@ namespace Umbraco.Web.Features /// Gets the disabled controllers. /// public TypeList Controllers { get; private set; } + + /// + /// Specifies if rendering pipeline should ignore HasTemplate check when handling a request. + /// This is to allow JSON preview of content with no template set. + /// + public bool AllowRenderWithoutTemplate { get; set; } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index d7ce36b4a4..da64048ada 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using System.Text; using System.Web; using System.Web.Compilation; using System.Web.Mvc; @@ -8,12 +7,10 @@ using System.Web.Routing; using System.Web.SessionState; using Umbraco.Core; using Umbraco.Core.Logging; -using Umbraco.Core.Configuration; -using Umbraco.Core.Models; using Umbraco.Web.Models; using Umbraco.Web.Routing; -using umbraco.cms.businesslogic.template; using System.Collections.Generic; +using Umbraco.Web.Features; namespace Umbraco.Web.Mvc { @@ -311,8 +308,8 @@ namespace Umbraco.Web.Mvc if (controllerType != null) { //ensure the controller is of type IRenderMvcController and ControllerBase - if (TypeHelper.IsTypeAssignableFrom(controllerType) - && TypeHelper.IsTypeAssignableFrom(controllerType)) + if (TypeHelper.IsTypeAssignableFrom(controllerType) && + TypeHelper.IsTypeAssignableFrom(controllerType)) { //set the controller and name to the custom one def.ControllerType = controllerType; @@ -337,7 +334,7 @@ namespace Umbraco.Web.Mvc } //store the route definition - requestContext.RouteData.DataTokens[Umbraco.Core.Constants.Web.UmbracoRouteDefinitionDataToken] = def; + requestContext.RouteData.DataTokens[Core.Constants.Web.UmbracoRouteDefinitionDataToken] = def; return def; } @@ -349,11 +346,11 @@ namespace Umbraco.Web.Mvc // missing template, so we're in a 404 here // so the content, if any, is a custom 404 page of some sort - if (!pcr.HasPublishedContent) + if (pcr.HasPublishedContent == false) // means the builder could not find a proper document to handle 404 return new PublishedContentNotFoundHandler(); - if (!pcr.HasTemplate) + if (pcr.HasTemplate == false) // means the engine could find a proper document, but the document has no template // at that point there isn't much we can do and there is no point returning // to Mvc since Mvc can't do much @@ -398,7 +395,9 @@ namespace Umbraco.Web.Mvc //here we need to check if there is no hijacked route and no template assigned, if this is the case //we want to return a blank page, but we'll leave that up to the NoTemplateHandler. - if (!publishedContentRequest.HasTemplate && !routeDef.HasHijackedRoute) + if (publishedContentRequest.HasTemplate == false && + routeDef.HasHijackedRoute == false && + FeaturesResolver.Current.Features.Disabled.AllowRenderWithoutTemplate == false) { publishedContentRequest.UpdateOnMissingTemplate(); // will go 404 @@ -431,7 +430,7 @@ namespace Umbraco.Web.Mvc //no post values, just route to the controller/action requried (local) requestContext.RouteData.Values["controller"] = routeDef.ControllerName; - if (!string.IsNullOrWhiteSpace(routeDef.ActionName)) + if (string.IsNullOrWhiteSpace(routeDef.ActionName) == false) { requestContext.RouteData.Values["action"] = routeDef.ActionName; } @@ -459,7 +458,5 @@ namespace Umbraco.Web.Mvc { return _controllerFactory.GetControllerSessionBehavior(requestContext, controllerName); } - - } -} \ No newline at end of file +} From 633d1bb0aeb1cec72424b95960455d1c690e93af Mon Sep 17 00:00:00 2001 From: Claus Date: Fri, 9 Feb 2018 13:19:56 +0100 Subject: [PATCH 2/3] changing the template check to an enabled check instead. --- src/Umbraco.Web/Features/DisabledFeatures.cs | 6 ------ src/Umbraco.Web/Features/EnabledFeatures.cs | 22 ++++++++++++++++++++ src/Umbraco.Web/Features/UmbracoFeatures.cs | 8 ++++++- src/Umbraco.Web/Mvc/RenderRouteHandler.cs | 3 ++- src/Umbraco.Web/Umbraco.Web.csproj | 1 + 5 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 src/Umbraco.Web/Features/EnabledFeatures.cs diff --git a/src/Umbraco.Web/Features/DisabledFeatures.cs b/src/Umbraco.Web/Features/DisabledFeatures.cs index a4adb42557..b9d8d0a2d9 100644 --- a/src/Umbraco.Web/Features/DisabledFeatures.cs +++ b/src/Umbraco.Web/Features/DisabledFeatures.cs @@ -20,11 +20,5 @@ namespace Umbraco.Web.Features /// Gets the disabled controllers. /// public TypeList Controllers { get; private set; } - - /// - /// Specifies if rendering pipeline should ignore HasTemplate check when handling a request. - /// This is to allow JSON preview of content with no template set. - /// - public bool AllowRenderWithoutTemplate { get; set; } } } diff --git a/src/Umbraco.Web/Features/EnabledFeatures.cs b/src/Umbraco.Web/Features/EnabledFeatures.cs new file mode 100644 index 0000000000..afa1988988 --- /dev/null +++ b/src/Umbraco.Web/Features/EnabledFeatures.cs @@ -0,0 +1,22 @@ +namespace Umbraco.Web.Features +{ + /// + /// Represents enabled features. + /// + internal class EnabledFeatures + { + /// + /// Initializes a new instance of the class. + /// + public EnabledFeatures() + { + + } + + /// + /// Specifies if rendering pipeline should ignore HasTemplate check when handling a request. + /// This is to allow JSON preview of content with no template set. + /// + public bool RenderNoTemplate { get; set; } + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Features/UmbracoFeatures.cs b/src/Umbraco.Web/Features/UmbracoFeatures.cs index 5dc64ff5e4..8f65d6efb8 100644 --- a/src/Umbraco.Web/Features/UmbracoFeatures.cs +++ b/src/Umbraco.Web/Features/UmbracoFeatures.cs @@ -14,6 +14,7 @@ namespace Umbraco.Web.Features public UmbracoFeatures() { Disabled = new DisabledFeatures(); + Enabled = new EnabledFeatures(); } // note @@ -28,6 +29,11 @@ namespace Umbraco.Web.Features /// public DisabledFeatures Disabled { get; set; } + /// + /// Gets the enabled features. + /// + public EnabledFeatures Enabled { get; set; } + /// /// Determines whether a feature is enabled. /// @@ -39,4 +45,4 @@ namespace Umbraco.Web.Features throw new NotSupportedException("Not a supported feature type."); } } -} \ No newline at end of file +} diff --git a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs index da64048ada..c4b0593979 100644 --- a/src/Umbraco.Web/Mvc/RenderRouteHandler.cs +++ b/src/Umbraco.Web/Mvc/RenderRouteHandler.cs @@ -395,9 +395,10 @@ namespace Umbraco.Web.Mvc //here we need to check if there is no hijacked route and no template assigned, if this is the case //we want to return a blank page, but we'll leave that up to the NoTemplateHandler. + //we also check if we're allowed to render even though there's no template (json render in headless). if (publishedContentRequest.HasTemplate == false && routeDef.HasHijackedRoute == false && - FeaturesResolver.Current.Features.Disabled.AllowRenderWithoutTemplate == false) + FeaturesResolver.Current.Features.Enabled.RenderNoTemplate == false) { publishedContentRequest.UpdateOnMissingTemplate(); // will go 404 diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 2a164b6ea1..0d195b5630 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -329,6 +329,7 @@ + From c1cfea7ebd8f0988f646e3e4870bcdb323ff3b0c Mon Sep 17 00:00:00 2001 From: Claus Date: Mon, 12 Feb 2018 11:12:46 +0100 Subject: [PATCH 3/3] removing constructor. --- src/Umbraco.Web/Features/EnabledFeatures.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Umbraco.Web/Features/EnabledFeatures.cs b/src/Umbraco.Web/Features/EnabledFeatures.cs index afa1988988..7f0d047992 100644 --- a/src/Umbraco.Web/Features/EnabledFeatures.cs +++ b/src/Umbraco.Web/Features/EnabledFeatures.cs @@ -5,18 +5,10 @@ namespace Umbraco.Web.Features /// internal class EnabledFeatures { - /// - /// Initializes a new instance of the class. - /// - public EnabledFeatures() - { - - } - /// /// Specifies if rendering pipeline should ignore HasTemplate check when handling a request. /// This is to allow JSON preview of content with no template set. /// public bool RenderNoTemplate { get; set; } } -} \ No newline at end of file +}