Support async in TreeController (#12016)

This commit is contained in:
Chad
2022-02-27 21:16:33 +13:00
committed by GitHub
parent b56f0f7062
commit 7ddddb7500
3 changed files with 78 additions and 13 deletions

View File

@@ -349,7 +349,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
var actionContext = new ActionContext(HttpContext, routeData, actionDescriptor);
var proxyControllerContext = new ControllerContext(actionContext);
var controller = (TreeController)_controllerFactory.CreateController(proxyControllerContext);
var controller = (TreeControllerBase)_controllerFactory.CreateController(proxyControllerContext);
// TODO: What about other filters? Will they execute?
var isAllowed = await controller.ControllerContext.InvokeAuthorizationFiltersForRequest(actionContext);

View File

@@ -47,6 +47,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
[Obsolete("See GetTreeNodesAsync")]
protected abstract ActionResult<TreeNodeCollection> GetTreeNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
/// <summary>
@@ -55,8 +56,40 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
[Obsolete("See GetMenuForNodeAsync")]
protected abstract ActionResult<MenuItemCollection> GetMenuForNode(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings);
/// <summary>
/// The method called to render the contents of the tree structure
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings">
/// All of the query string parameters passed from jsTree
/// </param>
/// <remarks>
/// If overriden, GetTreeNodes will not be called
/// We are allowing an arbitrary number of query strings to be passed in so that developers are able to persist custom data from the front-end
/// to the back end to be used in the query for model data.
/// </remarks>
protected virtual async Task<ActionResult<TreeNodeCollection>> GetTreeNodesAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetTreeNodes(id, queryStrings);
}
/// <summary>
/// Returns the menu structure for the node
/// </summary>
/// <param name="id"></param>
/// <param name="queryStrings"></param>
/// <returns></returns>
/// <remarks>
/// If overriden, GetMenuForNode will not be called
/// </remarks>
protected virtual async Task<ActionResult<MenuItemCollection>> GetMenuForNodeAsync(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))] FormCollection queryStrings)
{
return GetMenuForNode(id, queryStrings);
}
/// <summary>
/// The name to display on the root node
/// </summary>
@@ -132,7 +165,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public async Task<ActionResult<TreeNodeCollection>> GetNodes(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
{
if (queryStrings == null) queryStrings = FormCollection.Empty;
var nodesResult = GetTreeNodes(id, queryStrings);
var nodesResult = await GetTreeNodesAsync(id, queryStrings);
if (!(nodesResult.Result is null))
{
@@ -150,7 +183,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
node.RoutePath = "#";
//raise the event
await _eventAggregator.PublishAsync(new TreeNodesRenderingNotification(nodes, queryStrings, TreeAlias));
await _eventAggregator.PublishAsync(new TreeNodesRenderingNotification(nodes, queryStrings, TreeAlias, id));
return nodes;
}
@@ -164,7 +197,7 @@ namespace Umbraco.Cms.Web.BackOffice.Trees
public async Task<ActionResult<MenuItemCollection>> GetMenu(string id, [ModelBinder(typeof(HttpQueryStringModelBinder))]FormCollection queryStrings)
{
if (queryStrings == null) queryStrings = FormCollection.Empty;
var menuResult = GetMenuForNode(id, queryStrings);
var menuResult = await GetMenuForNodeAsync(id, queryStrings);
if (!(menuResult.Result is null))
{
return menuResult.Result;

View File

@@ -1,3 +1,4 @@
using System;
using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core.Trees;
@@ -11,26 +12,57 @@ namespace Umbraco.Cms.Core.Notifications
/// </remarks>
public class TreeNodesRenderingNotification : INotification
{
/// <summary>
/// The tree nodes being rendered
/// </summary>
public TreeNodeCollection Nodes { get; }
/// <summary>
/// The query string of the current request
/// Initializes a new instance of the <see cref="TreeNodesRenderingNotification"/> class.
/// </summary>
public FormCollection QueryString { get; }
/// <param name="nodes">The tree nodes being rendered</param>
/// <param name="queryString">The query string of the current request</param>
/// <param name="treeAlias">The alias of the tree rendered</param>
/// <param name="id">The id of the node rendered</param>
public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias, string id)
{
Nodes = nodes;
QueryString = queryString;
TreeAlias = treeAlias;
Id = id;
}
/// <summary>
/// The alias of the tree rendered
/// Initializes a new instance of the <see cref="TreeNodesRenderingNotification"/> class.
/// Constructor
/// </summary>
public string TreeAlias { get; }
/// <param name="nodes">The tree nodes being rendered</param>
/// <param name="queryString">The query string of the current request</param>
/// <param name="treeAlias">The alias of the tree rendered</param>
[Obsolete("Use ctor with all parameters")]
public TreeNodesRenderingNotification(TreeNodeCollection nodes, FormCollection queryString, string treeAlias)
{
Nodes = nodes;
QueryString = queryString;
TreeAlias = treeAlias;
Id = default;
}
/// <summary>
/// Gets the tree nodes being rendered
/// </summary>
public TreeNodeCollection Nodes { get; }
/// <summary>
/// Gets the query string of the current request
/// </summary>
public FormCollection QueryString { get; }
/// <summary>
/// Gets the alias of the tree rendered
/// </summary>
public string TreeAlias { get; }
/// <summary>
/// Gets the id of the node rendered
/// </summary>
public string Id { get; }
}
}