diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 730e2e80b1..930db50828 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -198,7 +198,6 @@ - diff --git a/src/Umbraco.Tests/Web/Mvc/MergeParentContextViewDataAttributeTests.cs b/src/Umbraco.Tests/Web/Mvc/MergeParentContextViewDataAttributeTests.cs deleted file mode 100644 index 019f95ba75..0000000000 --- a/src/Umbraco.Tests/Web/Mvc/MergeParentContextViewDataAttributeTests.cs +++ /dev/null @@ -1,86 +0,0 @@ -using System.Web.Mvc; -using System.Web.Routing; -using NUnit.Framework; -using Umbraco.Tests.TestHelpers; -using Umbraco.Web.Mvc; - -namespace Umbraco.Tests.Web.Mvc -{ - [TestFixture] - public class MergeParentContextViewDataAttributeTests - { - [Test] - public void Ensure_All_Ancestor_ViewData_Is_Merged() - { - var http = new FakeHttpContextFactory("http://localhost"); - - //setup an heirarchy - var rootViewCtx = new ViewContext {Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary()}; - var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() }; - parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx); - var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) {RouteData = new RouteData()}; - controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx); - - //set up the view data - controllerCtx.Controller.ViewData["Test1"] = "Test1"; - controllerCtx.Controller.ViewData["Test2"] = "Test2"; - controllerCtx.Controller.ViewData["Test3"] = "Test3"; - parentViewCtx.ViewData["Test4"] = "Test4"; - parentViewCtx.ViewData["Test5"] = "Test5"; - parentViewCtx.ViewData["Test6"] = "Test6"; - rootViewCtx.ViewData["Test7"] = "Test7"; - rootViewCtx.ViewData["Test8"] = "Test8"; - rootViewCtx.ViewData["Test9"] = "Test9"; - - var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) {RouteData = controllerCtx.RouteData}; - var att = new MergeParentContextViewDataAttribute(); - - Assert.IsTrue(filter.IsChildAction); - att.OnResultExecuting(filter); - - Assert.AreEqual(9, controllerCtx.Controller.ViewData.Count); - } - - [Test] - public void Ensure_All_Ancestor_ViewData_Is_Merged_Without_Data_Loss() - { - var http = new FakeHttpContextFactory("http://localhost"); - - //setup an heirarchy - var rootViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, ViewData = new ViewDataDictionary() }; - var parentViewCtx = new ViewContext { Controller = new MyController(), RequestContext = http.RequestContext, RouteData = new RouteData(), ViewData = new ViewDataDictionary() }; - parentViewCtx.RouteData.DataTokens.Add("ParentActionViewContext", rootViewCtx); - var controllerCtx = new ControllerContext(http.RequestContext, new MyController()) { RouteData = new RouteData() }; - controllerCtx.RouteData.DataTokens.Add("ParentActionViewContext", parentViewCtx); - - //set up the view data with overlapping keys - controllerCtx.Controller.ViewData["Test1"] = "Test1"; - controllerCtx.Controller.ViewData["Test2"] = "Test2"; - controllerCtx.Controller.ViewData["Test3"] = "Test3"; - parentViewCtx.ViewData["Test2"] = "Test4"; - parentViewCtx.ViewData["Test3"] = "Test5"; - parentViewCtx.ViewData["Test4"] = "Test6"; - rootViewCtx.ViewData["Test3"] = "Test7"; - rootViewCtx.ViewData["Test4"] = "Test8"; - rootViewCtx.ViewData["Test5"] = "Test9"; - - var filter = new ResultExecutingContext(controllerCtx, new ContentResult()) { RouteData = controllerCtx.RouteData }; - var att = new MergeParentContextViewDataAttribute(); - - Assert.IsTrue(filter.IsChildAction); - att.OnResultExecuting(filter); - - Assert.AreEqual(5, controllerCtx.Controller.ViewData.Count); - Assert.AreEqual("Test1", controllerCtx.Controller.ViewData["Test1"]); - Assert.AreEqual("Test2", controllerCtx.Controller.ViewData["Test2"]); - Assert.AreEqual("Test3", controllerCtx.Controller.ViewData["Test3"]); - Assert.AreEqual("Test6", controllerCtx.Controller.ViewData["Test4"]); - Assert.AreEqual("Test9", controllerCtx.Controller.ViewData["Test5"]); - } - - internal class MyController : Controller - { - - } - } -} diff --git a/src/Umbraco.Web.Website/Controllers/SurfaceController.cs b/src/Umbraco.Web.Website/Controllers/SurfaceController.cs index e8d7523adb..8a9772eab9 100644 --- a/src/Umbraco.Web.Website/Controllers/SurfaceController.cs +++ b/src/Umbraco.Web.Website/Controllers/SurfaceController.cs @@ -17,9 +17,6 @@ namespace Umbraco.Cms.Web.Website.Controllers /// /// Provides a base class for front-end add-in controllers. /// - // TODO: Migrate MergeModelStateToChildAction and MergeParentContextViewData action filters - // [MergeModelStateToChildAction] - // [MergeParentContextViewData] [AutoValidateAntiforgeryToken] public abstract class SurfaceController : PluginController { diff --git a/src/Umbraco.Web/Mvc/MergeModelStateToChildActionAttribute.cs b/src/Umbraco.Web/Mvc/MergeModelStateToChildActionAttribute.cs deleted file mode 100644 index 23603f8b59..0000000000 --- a/src/Umbraco.Web/Mvc/MergeModelStateToChildActionAttribute.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.Linq; -using System.Web.Mvc; - -namespace Umbraco.Web.Mvc -{ - /// - /// When a ChildAction is executing and we want the ModelState from the Parent context to be merged in - /// to help with validation, this filter can be used. - /// - /// - /// By default, this filter will only merge when an Http POST is detected but this can be modified in the ctor - /// - public class MergeModelStateToChildActionAttribute : ActionFilterAttribute - { - private readonly string[] _verb; - - public MergeModelStateToChildActionAttribute() - : this(HttpVerbs.Post) - { - - } - - public MergeModelStateToChildActionAttribute(params HttpVerbs[] verb) - { - _verb = verb.Select(x => x.ToString().ToUpper()).ToArray(); - } - - public override void OnActionExecuting(ActionExecutingContext filterContext) - { - //check if the verb matches, if so merge the ModelState before the action is executed. - if (_verb.Contains(filterContext.HttpContext.Request.HttpMethod)) - { - if (filterContext.Controller.ControllerContext.IsChildAction) - { - filterContext.Controller.ViewData.ModelState.Merge( - filterContext.Controller.ControllerContext.ParentActionViewContext.ViewData.ModelState); - } - } - base.OnActionExecuting(filterContext); - } - } -} diff --git a/src/Umbraco.Web/Mvc/MergeParentContextViewDataAttribute.cs b/src/Umbraco.Web/Mvc/MergeParentContextViewDataAttribute.cs deleted file mode 100644 index ce9bf9f45f..0000000000 --- a/src/Umbraco.Web/Mvc/MergeParentContextViewDataAttribute.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Linq; -using System.Web.Mvc; - -namespace Umbraco.Web.Mvc -{ - /// - /// This attribute can be used for when child actions execute and will automatically merge in the viewdata from the parent context to the - /// child action result. - /// - /// - /// This will retain any custom viewdata put into the child viewdata if the same key persists in the parent context's view data. You can always still - /// access the parent's view data normally. - /// This just simplifies working with ChildActions and view data. - /// - /// NOTE: This does not mean that the parent context's view data will be merged before the action executes, if you need access to the parent context's view - /// data during controller execution you can access it normally. - /// - /// NOTE: This recursively merges in all ParentActionViewContext ancestry in case there's child actions inside of child actions. - /// - public class MergeParentContextViewDataAttribute : ActionFilterAttribute - { - /// - /// Merge in the parent context's view data if this is a child action when the result is being executed - /// - /// - public override void OnResultExecuting(ResultExecutingContext filterContext) - { - if (filterContext.IsChildAction) - { - MergeCurrentParent(filterContext.Controller, filterContext.ParentActionViewContext); - } - - base.OnResultExecuting(filterContext); - } - - /// - /// Recursively merges in each parent view context into the target - /// - /// - /// - private static void MergeCurrentParent(ControllerBase target, ViewContext currentParent) - { - if (currentParent != null && currentParent.ViewData != null && currentParent.ViewData.Any()) - { - target.ViewData.MergeViewDataFrom(currentParent.ViewData); - - //Recurse! - if (currentParent.IsChildAction) - { - MergeCurrentParent(target, currentParent.ParentActionViewContext); - } - - } - } - } -} diff --git a/src/Umbraco.Web/Mvc/SurfaceController.cs b/src/Umbraco.Web/Mvc/SurfaceController.cs index 9534ab84cc..af1a89dedd 100644 --- a/src/Umbraco.Web/Mvc/SurfaceController.cs +++ b/src/Umbraco.Web/Mvc/SurfaceController.cs @@ -1,22 +1,10 @@ -using System; -using Umbraco.Core; -using System.Collections.Specialized; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Web; -using Umbraco.Core.Cache; -using Umbraco.Core.Logging; using Umbraco.Core.Persistence; -using Umbraco.Core.Services; -using Umbraco.Web.Composing; namespace Umbraco.Web.Mvc { - /// Migrated already to .Net Core without MergeModelStateToChildAction and MergeParentContextViewData action filters - /// TODO: Migrate MergeModelStateToChildAction and MergeParentContextViewData action filters - [MergeModelStateToChildAction] - [MergeParentContextViewData] public abstract class SurfaceController : PluginController { protected SurfaceController() diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8b4d742aeb..b56b4b1450 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -176,7 +176,6 @@ - @@ -193,7 +192,6 @@ - True