From ded3a061701775a34f144eedc5c964fe97e71da3 Mon Sep 17 00:00:00 2001 From: Elitsa Marinovska Date: Wed, 13 Jan 2021 16:17:39 +0100 Subject: [PATCH] Special case where the user is not authorized --- .../ModelBinders/ContentModelBinderHelper.cs | 4 +-- .../Trees/ApplicationTreeController.cs | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Web.BackOffice/ModelBinders/ContentModelBinderHelper.cs b/src/Umbraco.Web.BackOffice/ModelBinders/ContentModelBinderHelper.cs index adea4dcc3c..0ed360214b 100644 --- a/src/Umbraco.Web.BackOffice/ModelBinders/ContentModelBinderHelper.cs +++ b/src/Umbraco.Web.BackOffice/ModelBinders/ContentModelBinderHelper.cs @@ -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]; diff --git a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs index c19229b1e6..1a5aa688d4 100644 --- a/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs +++ b/src/Umbraco.Web.BackOffice/Trees/ApplicationTreeController.cs @@ -160,25 +160,17 @@ namespace Umbraco.Web.BackOffice.Trees /// Tries to get the root node of a tree. /// /// - /// 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. + /// 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 /// private async Task 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); } /// @@ -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}\".");