From cf342ece457825c9ee9374f742dbfe14d0224e13 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 5 Nov 2013 18:17:16 +1100 Subject: [PATCH] Fixes: U4-3322 MNTP doesn't work when choosing media or members --- .../src/common/resources/entity.resource.js | 11 ----- .../common/dialogs/memberpicker.controller.js | 2 +- src/Umbraco.Web/Editors/EntityController.cs | 16 ++++++-- .../Editors/EntityControllerActionSelector.cs | 40 +++++++++++++++++++ src/Umbraco.Web/Umbraco.Web.csproj | 1 + 5 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/Umbraco.Web/Editors/EntityControllerActionSelector.cs diff --git a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js index e8160ee2d0..e1230dfae8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js +++ b/src/Umbraco.Web.UI.Client/src/common/resources/entity.resource.js @@ -99,17 +99,6 @@ function entityResource($q, $http, umbRequestHelper) { 'Failed to retreive entity data for id ' + id); }, - getByKey: function (key, type) { - return umbRequestHelper.resourcePromise( - $http.get( - umbRequestHelper.getApiUrl( - "entityApiBaseUrl", - "GetByKey", - [{ key: key }, { type: type }])), - 'Failed to retreive entity data for key ' + key); - }, - - /** * @ngdoc method * @name umbraco.resources.entityResource#getByIds diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js index cbdfcc9654..c96c82b9c5 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/memberpicker.controller.js @@ -23,7 +23,7 @@ angular.module("umbraco").controller("Umbraco.Dialogs.MemberPickerController", } else { //otherwise we have to get it from the server - entityResource.getByKey(key, "Member").then(function (ent) { + entityResource.getById(key, "Member").then(function (ent) { $scope.submit(ent); }); } diff --git a/src/Umbraco.Web/Editors/EntityController.cs b/src/Umbraco.Web/Editors/EntityController.cs index 7d769738ab..9a4f008365 100644 --- a/src/Umbraco.Web/Editors/EntityController.cs +++ b/src/Umbraco.Web/Editors/EntityController.cs @@ -19,6 +19,7 @@ using System.Linq; using Umbraco.Core.Models.EntityBase; using Umbraco.Core.Models; using Umbraco.Web.WebApi.Filters; +using umbraco.cms.businesslogic.packager; using Constants = Umbraco.Core.Constants; using Examine; using Examine.LuceneEngine.SearchCriteria; @@ -35,7 +36,14 @@ namespace Umbraco.Web.Editors /// [PluginController("UmbracoApi")] public class EntityController : UmbracoAuthorizedJsonController - { + { + protected override void Initialize(HttpControllerContext controllerContext) + { + base.Initialize(controllerContext); + + controllerContext.Configuration.Services.Replace(typeof(IHttpActionSelector), new EntityControllerActionSelector()); + } + [HttpGet] public IEnumerable Search(string query, UmbracoEntityTypes type) { @@ -112,12 +120,12 @@ namespace Umbraco.Web.Editors /// /// Gets an entity by it's unique id if the entity supports that /// - /// + /// /// /// - public EntityBasic GetByKey(Guid key, UmbracoEntityTypes type) + public EntityBasic GetByKey(Guid id, UmbracoEntityTypes type) { - return GetResultForKey(key, type); + return GetResultForKey(id, type); } public EntityBasic GetById(int id, UmbracoEntityTypes type) diff --git a/src/Umbraco.Web/Editors/EntityControllerActionSelector.cs b/src/Umbraco.Web/Editors/EntityControllerActionSelector.cs new file mode 100644 index 0000000000..69161a31dd --- /dev/null +++ b/src/Umbraco.Web/Editors/EntityControllerActionSelector.cs @@ -0,0 +1,40 @@ +using System; +using System.Web; +using System.Web.Http.Controllers; + +namespace Umbraco.Web.Editors +{ + /// + /// This allows for calling GetById with a GUID... so it will automatically route to GetByKey + /// + internal class EntityControllerActionSelector : ApiControllerActionSelector + { + + public override HttpActionDescriptor SelectAction(HttpControllerContext controllerContext) + { + if (controllerContext.Request.RequestUri.GetLeftPart(UriPartial.Path).ToUpper().EndsWith("GETBYID")) + { + var id = HttpUtility.ParseQueryString(controllerContext.Request.RequestUri.Query).Get("id"); + + if (id != null) + { + Guid parsed; + if (Guid.TryParse(id, out parsed)) + { + var controllerType = controllerContext.Controller.GetType(); + var method = controllerType.GetMethod("GetByKey"); + if (method != null) + { + return new ReflectedHttpActionDescriptor(controllerContext.ControllerDescriptor, method); + } + } + } + } + + + + return base.SelectAction(controllerContext); + } + + } +} \ No newline at end of file diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 8715e8cc1c..f560cd8e68 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -308,6 +308,7 @@ +