Special case where the user is not authorized

This commit is contained in:
Elitsa Marinovska
2021-01-13 16:17:39 +01:00
parent 7c5e045868
commit ded3a06170
2 changed files with 16 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Net;
using System.Threading.Tasks;
@@ -60,7 +60,7 @@ namespace Umbraco.Web.BackOffice.ModelBinders
if (parts.Length < 2)
{
bindingContext.HttpContext.SetReasonPhrase( "The request was not formatted correctly the file name's must be underscore delimited");
throw new HttpResponseException(HttpStatusCode.BadRequest);
return null;
}
var propAlias = parts[1];

View File

@@ -160,25 +160,17 @@ namespace Umbraco.Web.BackOffice.Trees
/// Tries to get the root node of a tree.
/// </summary>
/// <remarks>
/// <para>Returns null if the root node could not be obtained due to an HttpResponseException,
/// which probably indicates that the user isn't authorized to view that tree.</para>
/// <para>Returns null if the root node could not be obtained due to that
/// the user isn't authorized to view that tree. In this case since we are
/// loading multiple trees we will just return null so that it's not added
/// to the list</para>
/// </remarks>
private async Task<TreeNode> TryGetRootNode(Tree tree, FormCollection querystring)
{
if (tree == null)
throw new ArgumentNullException(nameof(tree));
try
{
return await GetRootNode(tree, querystring);
}
catch (HttpResponseException)
{
// if this occurs its because the user isn't authorized to view that tree,
// in this case since we are loading multiple trees we will just return
// null so that it's not added to the list.
return null;
}
return await GetRootNode(tree, querystring);
}
/// <summary>
@@ -219,7 +211,15 @@ namespace Umbraco.Web.BackOffice.Trees
if (tree == null)
throw new ArgumentNullException(nameof(tree));
var controller = (TreeControllerBase)(await GetApiControllerProxy(tree.TreeControllerType, "GetRootNode", querystring)).Value;
var result = await GetApiControllerProxy(tree.TreeControllerType, "GetRootNode", querystring);
// return null if the user isn't authorized to view that tree
if (!((ForbidResult)result.Result is null))
{
return null;
}
var controller = (TreeControllerBase)result.Value;
var rootNode = controller.GetRootNode(querystring);
if (rootNode == null)
throw new InvalidOperationException($"Failed to get root node for tree \"{tree.TreeAlias}\".");