Continue replacing HttpResponseException
This commit is contained in:
@@ -62,16 +62,16 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
/// <param name="queryStrings"></param>
|
||||
/// <param name="use">Tree use.</param>
|
||||
/// <returns></returns>
|
||||
public async Task<TreeRootNode> GetApplicationTrees(string application, string tree, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings, TreeUse use = TreeUse.Main)
|
||||
public async Task<ActionResult<TreeRootNode>> GetApplicationTrees(string application, string tree, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings, TreeUse use = TreeUse.Main)
|
||||
{
|
||||
application = application.CleanForXss();
|
||||
|
||||
if (string.IsNullOrEmpty(application))
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return NotFound();
|
||||
|
||||
var section = _sectionService.GetByAlias(application);
|
||||
if (section == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return NotFound();
|
||||
|
||||
//find all tree definitions that have the current application alias
|
||||
var groupedTrees = _treeService.GetBySectionGrouped(application, use);
|
||||
@@ -93,13 +93,13 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
: allTrees.FirstOrDefault(x => x.TreeAlias == tree);
|
||||
|
||||
if (t == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return NotFound();
|
||||
|
||||
var treeRootNode = await GetTreeRootNode(t, Constants.System.Root, queryStrings);
|
||||
if (treeRootNode != null)
|
||||
return treeRootNode;
|
||||
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
// handle requests for all trees
|
||||
@@ -219,7 +219,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
if (tree == null)
|
||||
throw new ArgumentNullException(nameof(tree));
|
||||
|
||||
var controller = (TreeControllerBase)await GetApiControllerProxy(tree.TreeControllerType, "GetRootNode", querystring);
|
||||
var controller = (TreeControllerBase)(await GetApiControllerProxy(tree.TreeControllerType, "GetRootNode", querystring)).Value;
|
||||
var rootNode = controller.GetRootNode(querystring);
|
||||
if (rootNode == null)
|
||||
throw new InvalidOperationException($"Failed to get root node for tree \"{tree.TreeAlias}\".");
|
||||
@@ -241,7 +241,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
d["id"] = StringValues.Empty;
|
||||
var proxyQuerystring = new FormCollection(d);
|
||||
|
||||
var controller = (TreeControllerBase)await GetApiControllerProxy(tree.TreeControllerType, "GetNodes", proxyQuerystring);
|
||||
var controller = (TreeControllerBase)(await GetApiControllerProxy(tree.TreeControllerType, "GetNodes", proxyQuerystring)).Value;
|
||||
return controller.GetNodes(id.ToInvariantString(), querystring);
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
/// and context etc. so it can execute the specified <paramref name="action"/>. Runs the authorization
|
||||
/// filters for that action, to ensure that the user has permission to execute it.</para>
|
||||
/// </remarks>
|
||||
private async Task<object> GetApiControllerProxy(Type controllerType, string action, FormCollection querystring)
|
||||
private async Task<ActionResult<object>> GetApiControllerProxy(Type controllerType, string action, FormCollection querystring)
|
||||
{
|
||||
// note: this is all required in order to execute the auth-filters for the sub request, we
|
||||
// need to "trick" mvc into thinking that it is actually executing the proxied controller.
|
||||
@@ -289,11 +289,9 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
|
||||
var isAllowed = await controller.ControllerContext.InvokeAuthorizationFiltersForRequest(actionContext);
|
||||
if (!isAllowed)
|
||||
throw new HttpResponseException(HttpStatusCode.Forbidden);
|
||||
return Forbid();
|
||||
|
||||
return controller;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -21,6 +21,7 @@ using Umbraco.Core.Configuration.Models;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Web.Trees;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Web.Common.Authorization;
|
||||
using Umbraco.Core.Trees;
|
||||
|
||||
@@ -236,7 +237,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
return HasPathAccess(entity, queryStrings);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IEntitySlim> GetChildEntities(string id, FormCollection queryStrings)
|
||||
protected override ActionResult<IEnumerable<IEntitySlim>> GetChildEntities(string id, FormCollection queryStrings)
|
||||
{
|
||||
var result = base.GetChildEntities(id, queryStrings);
|
||||
var culture = queryStrings["culture"].TryConvertTo<string>();
|
||||
@@ -245,7 +246,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
var cultureVal = (culture.Success ? culture.Result : null) ?? _localizationService.GetDefaultLanguageIsoCode();
|
||||
|
||||
// set names according to variations
|
||||
foreach (var entity in result)
|
||||
foreach (var entity in result.Value)
|
||||
{
|
||||
EnsureName(entity, cultureVal);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -211,7 +211,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
|
||||
// get child entities - if id is root, but user's start nodes do not contain the
|
||||
// root node, this returns the start nodes instead of root's children
|
||||
var entities = GetChildEntities(id, queryStrings).ToList();
|
||||
var entities = GetChildEntities(id, queryStrings).Value.ToList();
|
||||
|
||||
//get the current user start node/paths
|
||||
GetUserStartNodes(out var userStartNodes, out var userStartNodePaths);
|
||||
@@ -257,7 +257,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
|
||||
protected abstract UmbracoObjectTypes UmbracoObjectType { get; }
|
||||
|
||||
protected virtual IEnumerable<IEntitySlim> GetChildEntities(string id, FormCollection queryStrings)
|
||||
protected virtual ActionResult<IEnumerable<IEntitySlim>> GetChildEntities(string id, FormCollection queryStrings)
|
||||
{
|
||||
// try to parse id as an integer else use GetEntityFromId
|
||||
// which will grok Guids, Udis, etc and let use obtain the id
|
||||
@@ -265,7 +265,7 @@ namespace Umbraco.Web.BackOffice.Trees
|
||||
{
|
||||
var entity = GetEntityFromId(id);
|
||||
if (entity == null)
|
||||
throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
return NotFound();
|
||||
|
||||
entityId = entity.Id;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user