Continue replacing HttpResponseException
This commit is contained in:
@@ -404,7 +404,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
}
|
||||
});
|
||||
|
||||
var display = _umbracoMapper.Map<DocumentTypeDisplay>(savedCt);
|
||||
var display = _umbracoMapper.Map<DocumentTypeDisplay>(savedCt.Value);
|
||||
|
||||
display.AddSuccessNotification(
|
||||
_localizedTextService.Localize("speechBubbles/contentTypeSavedHeader"),
|
||||
|
||||
@@ -253,7 +253,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
return CultureDictionary[text].IfNullOrWhiteSpace(text);
|
||||
}
|
||||
|
||||
protected TContentType PerformPostSave<TContentTypeDisplay, TContentTypeSave, TPropertyType>(
|
||||
protected ActionResult<TContentType> PerformPostSave<TContentTypeDisplay, TContentTypeSave, TPropertyType>(
|
||||
TContentTypeSave contentTypeSave,
|
||||
Func<int, TContentType> getContentType,
|
||||
Action<TContentType> saveContentType,
|
||||
@@ -264,7 +264,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
var ctId = Convert.ToInt32(contentTypeSave.Id);
|
||||
var ct = ctId > 0 ? getContentType(ctId) : null;
|
||||
if (ctId > 0 && ct == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
if (ctId > 0 && ct == null) return NotFound();
|
||||
|
||||
//Validate that there's no other ct with the same alias
|
||||
// it in fact cannot be the same as any content type alias (member, content or media) because
|
||||
|
||||
@@ -280,7 +280,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
i => _mediaTypeService.Get(i),
|
||||
type => _mediaTypeService.Save(type));
|
||||
|
||||
var display = _umbracoMapper.Map<MediaTypeDisplay>(savedCt);
|
||||
var display = _umbracoMapper.Map<MediaTypeDisplay>(savedCt.Value);
|
||||
|
||||
display.AddSuccessNotification(
|
||||
_localizedTextService.Localize("speechBubbles/mediaTypeSavedHeader"),
|
||||
|
||||
@@ -230,7 +230,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
getContentType: i => ct,
|
||||
saveContentType: type => _memberTypeService.Save(type));
|
||||
|
||||
var display =_umbracoMapper.Map<MemberTypeDisplay>(savedCt);
|
||||
var display =_umbracoMapper.Map<MemberTypeDisplay>(savedCt.Value);
|
||||
|
||||
display.AddSuccessNotification(
|
||||
_localizedTextService.Localize("speechBubbles/memberTypeSavedHeader"),
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||
@@ -75,7 +75,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
|
||||
// get the first tree in the section and get its root node route path
|
||||
var sectionRoot = appTreeController.GetApplicationTrees(section.Alias, null, null).Result;
|
||||
section.RoutePath = GetRoutePathForFirstTree(sectionRoot);
|
||||
section.RoutePath = GetRoutePathForFirstTree(sectionRoot.Value);
|
||||
}
|
||||
|
||||
return sectionModels;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Umbraco.Core.Mapping;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -9,15 +10,13 @@ using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Web.BackOffice.Filters;
|
||||
using Umbraco.Web.BackOffice.ActionResults;
|
||||
using Umbraco.Web.BackOffice.Filters;
|
||||
using Umbraco.Web.Common.Attributes;
|
||||
using Umbraco.Web.Common.Authorization;
|
||||
using Umbraco.Web.Common.Exceptions;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Security;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Umbraco.Web.Common.Authorization;
|
||||
|
||||
namespace Umbraco.Web.BackOffice.Controllers
|
||||
{
|
||||
@@ -52,7 +51,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
}
|
||||
|
||||
[UserGroupValidate]
|
||||
public UserGroupDisplay PostSaveUserGroup(UserGroupSave userGroupSave)
|
||||
public ActionResult<UserGroupDisplay> PostSaveUserGroup(UserGroupSave userGroupSave)
|
||||
{
|
||||
if (userGroupSave == null) throw new ArgumentNullException(nameof(userGroupSave));
|
||||
|
||||
@@ -62,14 +61,14 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
|
||||
var isAuthorized = authHelper.AuthorizeGroupAccess(_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser, userGroupSave.Alias);
|
||||
if (isAuthorized == false)
|
||||
throw new HttpResponseException(HttpStatusCode.Unauthorized, isAuthorized.Result);
|
||||
return Unauthorized(isAuthorized.Result);
|
||||
|
||||
//if sections were added we need to check that the current user has access to that section
|
||||
isAuthorized = authHelper.AuthorizeSectionChanges(_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
|
||||
userGroupSave.PersistedUserGroup.AllowedSections,
|
||||
userGroupSave.Sections);
|
||||
if (isAuthorized == false)
|
||||
throw new HttpResponseException(HttpStatusCode.Unauthorized, isAuthorized.Result);
|
||||
return Unauthorized(isAuthorized.Result);
|
||||
|
||||
//if start nodes were changed we need to check that the current user has access to them
|
||||
isAuthorized = authHelper.AuthorizeStartNodeChanges(_backofficeSecurityAccessor.BackOfficeSecurity.CurrentUser,
|
||||
@@ -78,7 +77,7 @@ namespace Umbraco.Web.BackOffice.Controllers
|
||||
userGroupSave.PersistedUserGroup.StartMediaId,
|
||||
userGroupSave.StartMediaId);
|
||||
if (isAuthorized == false)
|
||||
throw new HttpResponseException(HttpStatusCode.Unauthorized, isAuthorized.Result);
|
||||
return Unauthorized(isAuthorized.Result);
|
||||
|
||||
//need to ensure current user is in a group if not an admin to avoid a 401
|
||||
EnsureNonAdminUserIsInSavedUserGroup(userGroupSave);
|
||||
|
||||
@@ -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