diff --git a/src/Umbraco.Web.BackOffice/Controllers/RelationController.cs b/src/Umbraco.Web.BackOffice/Controllers/RelationController.cs new file mode 100644 index 0000000000..699c06f1d9 --- /dev/null +++ b/src/Umbraco.Web.BackOffice/Controllers/RelationController.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Net.Http; +using Microsoft.AspNetCore.Mvc; +using Umbraco.Core; +using Umbraco.Core.Mapping; +using Umbraco.Core.Models; +using Umbraco.Core.Services; +using Umbraco.Web.BackOffice.Filters; +using Umbraco.Web.Common.ActionsResults; +using Umbraco.Web.Common.Attributes; +using Umbraco.Web.Editors; +using Umbraco.Web.Models.ContentEditing; +using Constants = Umbraco.Core.Constants; + +namespace Umbraco.Web.BackOffice.Controllers +{ + [PluginController("UmbracoApi")] + [TypeFilter(typeof(UmbracoApplicationAuthorizeAttribute), Arguments = new object[]{new string[]{Constants.Applications.Content} })] + public class RelationController : UmbracoAuthorizedJsonController + { + private readonly UmbracoMapper _umbracoMapper; + private readonly IRelationService _relationService; + + public RelationController(UmbracoMapper umbracoMapper, + IRelationService relationService) + { + _umbracoMapper = umbracoMapper ?? throw new ArgumentNullException(nameof(umbracoMapper)); + _relationService = relationService ?? throw new ArgumentNullException(nameof(relationService)); + } + + public RelationDisplay GetById(int id) + { + return _umbracoMapper.Map(_relationService.GetById(id)); + } + + //[EnsureUserPermissionForContent("childId")] + public IEnumerable GetByChildId(int childId, string relationTypeAlias = "") + { + var relations = _relationService.GetByChildId(childId).ToArray(); + + if (relations.Any() == false) + { + return Enumerable.Empty(); + } + + if (string.IsNullOrWhiteSpace(relationTypeAlias) == false) + { + return + _umbracoMapper.MapEnumerable( + relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))); + } + + return _umbracoMapper.MapEnumerable(relations); + } + + [HttpDelete] + [HttpPost] + public IActionResult DeleteById(int id) + { + var foundRelation = _relationService.GetById(id); + + if (foundRelation == null) + { + return new UmbracoProblemResult("No relation found with the specified id", HttpStatusCode.NotFound); + } + + _relationService.Delete(foundRelation); + + return Ok(); + } + } +} diff --git a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs index 46995fd7ba..689fa39553 100644 --- a/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs +++ b/src/Umbraco.Web/Editors/BackOfficeServerVariables.cs @@ -233,10 +233,10 @@ namespace Umbraco.Web.Editors // "packageApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( // controller => controller.GetCreatedPackages()) // }, - { - "relationApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( - controller => controller.GetById(0)) - }, + // { + // "relationApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( + // controller => controller.GetById(0)) + // }, // { // "rteApiBaseUrl", _urlHelper.GetUmbracoApiServiceBaseUrl( // controller => controller.GetConfiguration()) diff --git a/src/Umbraco.Web/Editors/RelationController.cs b/src/Umbraco.Web/Editors/RelationController.cs deleted file mode 100644 index b7f9baba55..0000000000 --- a/src/Umbraco.Web/Editors/RelationController.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using Umbraco.Core; -using Umbraco.Core.Models; -using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Mvc; -using Umbraco.Web.WebApi.Filters; -using Constants = Umbraco.Core.Constants; - -namespace Umbraco.Web.Editors -{ - [PluginController("UmbracoApi")] - [UmbracoApplicationAuthorize(Constants.Applications.Content)] - public class RelationController : UmbracoAuthorizedJsonController - { - public RelationDisplay GetById(int id) - { - return Mapper.Map(Services.RelationService.GetById(id)); - } - - //[EnsureUserPermissionForContent("childId")] - public IEnumerable GetByChildId(int childId, string relationTypeAlias = "") - { - var relations = Services.RelationService.GetByChildId(childId).ToArray(); - - if (relations.Any() == false) - { - return Enumerable.Empty(); - } - - if (string.IsNullOrWhiteSpace(relationTypeAlias) == false) - { - return - Mapper.MapEnumerable( - relations.Where(x => x.RelationType.Alias.InvariantEquals(relationTypeAlias))); - } - - return Mapper.MapEnumerable(relations); - } - - [HttpDelete] - [HttpPost] - public HttpResponseMessage DeleteById(int id) - { - var foundRelation = Services.RelationService.GetById(id); - - if (foundRelation == null) - { - return Request.CreateErrorResponse(HttpStatusCode.NotFound, "No relation found with the specified id"); - } - - Services.RelationService.Delete(foundRelation); - - return Request.CreateResponse(HttpStatusCode.OK); - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 87c653e71f..a5ed5fdde3 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -331,7 +331,6 @@ -