From e121ce136f7872a2bf8a50f36bff40eaf0f4e1ee Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 7 May 2020 10:21:32 +0200 Subject: [PATCH] AB#6233 - Clean up --- .../Exceptions/HttpResponseException.cs | 13 ++++++++++- .../Filters/HttpResponseExceptionFilter.cs | 1 + .../Install/InstallApiController.cs | 23 ++++--------------- .../Macros/MacroRenderer.cs | 2 +- .../Macros/PartialViewMacroEngine.cs | 2 -- 5 files changed, 19 insertions(+), 22 deletions(-) rename src/{Umbraco.Core => Umbraco.Web.Common}/Exceptions/HttpResponseException.cs (81%) diff --git a/src/Umbraco.Core/Exceptions/HttpResponseException.cs b/src/Umbraco.Web.Common/Exceptions/HttpResponseException.cs similarity index 81% rename from src/Umbraco.Core/Exceptions/HttpResponseException.cs rename to src/Umbraco.Web.Common/Exceptions/HttpResponseException.cs index e0db712f40..d88209fea4 100644 --- a/src/Umbraco.Core/Exceptions/HttpResponseException.cs +++ b/src/Umbraco.Web.Common/Exceptions/HttpResponseException.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Net; using System.Runtime.Serialization; -namespace Umbraco.Core.Exceptions +namespace Umbraco.Web.Common.Exceptions { [Serializable] public class HttpResponseException : Exception @@ -39,5 +39,16 @@ namespace Umbraco.Core.Exceptions base.GetObjectData(info, context); } + + public static HttpResponseException CreateValidationErrorResponse(object model) + { + return new HttpResponseException(HttpStatusCode.BadRequest, model) + { + AdditionalHeaders = + { + ["X-Status-Reason"] = "Validation failed" + } + }; + } } } diff --git a/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs b/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs index 3bc68b5eff..46bfd6cdfa 100644 --- a/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs +++ b/src/Umbraco.Web.Common/Filters/HttpResponseExceptionFilter.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; using Umbraco.Core.Exceptions; +using Umbraco.Web.Common.Exceptions; namespace Umbraco.Web.Common.Filters { diff --git a/src/Umbraco.Web.Common/Install/InstallApiController.cs b/src/Umbraco.Web.Common/Install/InstallApiController.cs index d3c4159319..d9771fd7f8 100644 --- a/src/Umbraco.Web.Common/Install/InstallApiController.cs +++ b/src/Umbraco.Web.Common/Install/InstallApiController.cs @@ -1,17 +1,16 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net; using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using Umbraco.Core; -using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Migrations.Install; using Umbraco.Net; using Umbraco.Web.Common.Attributes; +using Umbraco.Web.Common.Exceptions; using Umbraco.Web.Install; using Umbraco.Web.Install.Models; @@ -152,32 +151,20 @@ namespace Umbraco.Web.Common.Install var installException = ex as InstallException; if (installException != null) { - throw new HttpResponseException(HttpStatusCode.BadRequest, new + throw HttpResponseException.CreateValidationErrorResponse(new { view = installException.View, model = installException.ViewModel, message = installException.Message - }) - { - AdditionalHeaders = - { - ["X-Status-Reason"] = "Validation failed" - } - }; + }); } - throw new HttpResponseException(HttpStatusCode.BadRequest,new + throw HttpResponseException.CreateValidationErrorResponse(new { step = step.Name, view = "error", message = ex.Message - }) - { - AdditionalHeaders = - { - ["X-Status-Reason"] = "Validation failed" - } - }; + }); } } diff --git a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs index 461217627d..8685c0b8b1 100644 --- a/src/Umbraco.Web.Common/Macros/MacroRenderer.cs +++ b/src/Umbraco.Web.Common/Macros/MacroRenderer.cs @@ -85,7 +85,7 @@ namespace Umbraco.Web.Macros { object key = 0; - if (_umbracoContextAccessor.UmbracoContext.Security.IsAuthenticated()) + if (_umbracoContextAccessor.GetRequiredUmbracoContext().Security.IsAuthenticated()) { key = _memberUserKeyProvider.GetMemberProviderUserKey() ?? 0; } diff --git a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs index b95494f9f4..ad1e1a06b0 100644 --- a/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs +++ b/src/Umbraco.Web.Common/Macros/PartialViewMacroEngine.cs @@ -74,8 +74,6 @@ namespace Umbraco.Web.Common.Macros //lets render this controller as a child action var viewContext = new ViewContext(); - //try and extract the current view context from the route values, this would be set in the UmbracoViewPage or in - // the UmbracoPageResult if POSTing to an MVC controller but rendering in Webforms routeVals.DataTokens.Add("ParentActionViewContext", viewContext);