From 5c614a88a2efc6101d66d2e7785f48c96c160ea5 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 15 Jan 2014 13:29:17 +1100 Subject: [PATCH] ensures webapi plugincontrollers are routed to /backoffice if [IsBackOffice] is specified --- src/Umbraco.Core/UriExtensions.cs | 6 +----- src/Umbraco.Tests/UriExtensionsTests.cs | 2 -- src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs | 15 ++++++++++++--- src/Umbraco.Web/Mvc/PluginControllerArea.cs | 4 +++- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Core/UriExtensions.cs b/src/Umbraco.Core/UriExtensions.cs index 058c53892c..45cb906eef 100644 --- a/src/Umbraco.Core/UriExtensions.cs +++ b/src/Umbraco.Core/UriExtensions.cs @@ -27,8 +27,6 @@ namespace Umbraco.Core /// These are def back office: /// /Umbraco/RestServices = back office /// /Umbraco/BackOffice = back office - /// /Umbraco/UmbracpApi = back office - /// /Umbraco/UmbracoTrees = back office /// If it's not any of the above, and there's no extension then we cannot determine if it's back office or front-end /// so we can only assume that it is not back office. This will occur if people use an UmbracoApiController for the backoffice /// but do not inherit from UmbracoAuthorizedApiController and do not use [IsBackOffice] attribute. @@ -75,9 +73,7 @@ namespace Umbraco.Core } //check for special back office paths - if (urlPath.InvariantStartsWith("/" + GlobalSettings.UmbracoMvcArea + "/UmbracoApi/") - || urlPath.InvariantStartsWith("/" + GlobalSettings.UmbracoMvcArea + "/UmbracoTrees/") - || urlPath.InvariantStartsWith("/" + GlobalSettings.UmbracoMvcArea + "/BackOffice/") + if (urlPath.InvariantStartsWith("/" + GlobalSettings.UmbracoMvcArea + "/BackOffice/") || urlPath.InvariantStartsWith("/" + GlobalSettings.UmbracoMvcArea + "/RestServices/")) { return true; diff --git a/src/Umbraco.Tests/UriExtensionsTests.cs b/src/Umbraco.Tests/UriExtensionsTests.cs index 9a6cfcae17..8e826fc428 100644 --- a/src/Umbraco.Tests/UriExtensionsTests.cs +++ b/src/Umbraco.Tests/UriExtensionsTests.cs @@ -23,8 +23,6 @@ namespace Umbraco.Tests [TestCase("http://www.domain.com/test/umbraco.aspx", "", false)] [TestCase("http://www.domain.com/Umbraco/restServices/blah", "", true)] [TestCase("http://www.domain.com/Umbraco/Backoffice/blah", "", true)] - [TestCase("http://www.domain.com/Umbraco/umbracoapi/blah", "", true)] - [TestCase("http://www.domain.com/Umbraco/umbracotrees/blah", "", true)] [TestCase("http://www.domain.com/Umbraco/anything", "", true)] [TestCase("http://www.domain.com/Umbraco/anything/", "", true)] [TestCase("http://www.domain.com/Umbraco/surface/blah", "", false)] diff --git a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs index 833fe92906..2836c458fb 100644 --- a/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs +++ b/src/Umbraco.Web/Mvc/AreaRegistrationExtensions.cs @@ -27,13 +27,20 @@ namespace Umbraco.Web.Mvc /// The DataToken value to set for the 'umbraco' key, this defaults to 'backoffice' /// By default this value is just {action}/{id} but can be modified for things like web api routes /// Default is true for MVC, otherwise false for WebAPI + /// + /// If specified will add this string to the path between the umbraco path and the area path name, for example: + /// /umbraco/CUSTOMPATHPREFIX/areaname + /// if not specified, will just route like: + /// /umbraco/areaname + /// /// /// internal static Route RouteControllerPlugin(this AreaRegistration area, string controllerName, Type controllerType, RouteCollection routes, string controllerSuffixName, string defaultAction, object defaultId, string umbracoTokenValue = "backoffice", string routeTokens = "{action}/{id}", - bool isMvc = true) + bool isMvc = true, + string areaPathPrefix = "") { Mandate.ParameterNotNullOrEmpty(controllerName, "controllerName"); Mandate.ParameterNotNull(controllerSuffixName, "controllerSuffixName"); @@ -44,8 +51,10 @@ namespace Umbraco.Web.Mvc var umbracoArea = GlobalSettings.UmbracoMvcArea; - //routes are explicitly name with controller names and IDs - var url = umbracoArea + "/" + area.AreaName + "/" + controllerName + "/" + routeTokens; + //routes are explicitly named with controller names and IDs + var url = umbracoArea + "/" + + (areaPathPrefix.IsNullOrWhiteSpace() ? "" : areaPathPrefix + "/") + + area.AreaName + "/" + controllerName + "/" + routeTokens; Route controllerPluginRoute; //var meta = PluginController.GetMetadata(controllerType); diff --git a/src/Umbraco.Web/Mvc/PluginControllerArea.cs b/src/Umbraco.Web/Mvc/PluginControllerArea.cs index 2d4c1a56ce..e197804031 100644 --- a/src/Umbraco.Web/Mvc/PluginControllerArea.cs +++ b/src/Umbraco.Web/Mvc/PluginControllerArea.cs @@ -85,7 +85,9 @@ namespace Umbraco.Web.Mvc { foreach (var s in apiControllers) { - this.RouteControllerPlugin(s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api", isMvc: false); + this.RouteControllerPlugin(s.ControllerName, s.ControllerType, routes, "", "", UrlParameter.Optional, "api", + isMvc: false, + areaPathPrefix: s.IsBackOffice ? "backoffice" : null); } } }