Fixing trees regression issue

This commit is contained in:
Shannon
2019-01-30 19:48:42 +11:00
parent 7ba4fd7ad1
commit 6c0321ce72
5 changed files with 28 additions and 9 deletions

View File

@@ -81,5 +81,24 @@ namespace Umbraco.Web
? converted.Result
: default(T);
}
/// <summary>
/// Returns the object based in the collection based on it's key. This does this with a conversion so if it doesn't convert or the query string is no there an exception is thrown
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="items"></param>
/// <param name="key"></param>
/// <returns></returns>
public static T GetRequiredValue<T>(this FormDataCollection items, string key)
{
var val = items.Get(key);
if (string.IsNullOrEmpty(val))
throw new InvalidOperationException($"The required query string parameter {key} is missing");
var converted = val.TryConvertTo<T>();
return converted.Success
? converted.Result
: throw new InvalidOperationException($"The required query string parameter {key} cannot be converted to type {typeof(T)}");
}
}
}

View File

@@ -47,11 +47,11 @@ namespace Umbraco.Web.Trees
/// </summary>
/// <param name="application">The application to load tree for</param>
/// <param name="tree">An optional single tree alias, if specified will only load the single tree for the request app</param>
/// <param name="querystring"></param>
/// <param name="queryStrings"></param>
/// <param name="use">Tree use.</param>
/// <returns></returns>
[HttpQueryStringFilter("queryStrings")]
public async Task<TreeRootNode> GetApplicationTrees(string application, string tree, FormDataCollection querystring, TreeUse use = TreeUse.Main)
public async Task<TreeRootNode> GetApplicationTrees(string application, string tree, FormDataCollection queryStrings, TreeUse use = TreeUse.Main)
{
application = application.CleanForXss();
@@ -75,7 +75,7 @@ namespace Umbraco.Web.Trees
if (t == null)
throw new HttpResponseException(HttpStatusCode.NotFound);
var treeRootNode = await GetTreeRootNode(t, Constants.System.Root, querystring);
var treeRootNode = await GetTreeRootNode(t, Constants.System.Root, queryStrings);
if (treeRootNode != null)
return treeRootNode;
@@ -89,7 +89,7 @@ namespace Umbraco.Web.Trees
var nodes = new TreeNodeCollection();
foreach (var t in allTrees)
{
var node = await TryGetRootNode(t, querystring);
var node = await TryGetRootNode(t, queryStrings);
if (node != null)
nodes.Add(node);
}
@@ -115,7 +115,7 @@ namespace Umbraco.Web.Trees
var nodes = new TreeNodeCollection();
foreach (var t in trees)
{
var node = await TryGetRootNode(t, querystring);
var node = await TryGetRootNode(t, queryStrings);
if (node != null)
nodes.Add(node);
}

View File

@@ -281,7 +281,7 @@ namespace Umbraco.Web.Trees
Services.TextService.Localize("general/recycleBin"),
"icon-trash",
RecycleBinSmells,
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin"));
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/recyclebin"));
}

View File

@@ -125,14 +125,14 @@ namespace Umbraco.Web.Trees
{
nodes.Add(
CreateTreeNode(Constants.Conventions.MemberTypes.AllMembersListId, id, queryStrings, Services.TextService.Localize("member/allMembers"), "icon-users", true,
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + Constants.Conventions.MemberTypes.AllMembersListId));
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + Constants.Conventions.MemberTypes.AllMembersListId));
if (_isUmbracoProvider)
{
nodes.AddRange(Services.MemberTypeService.GetAll()
.Select(memberType =>
CreateTreeNode(memberType.Alias, id, queryStrings, memberType.Name, "icon-users", true,
queryStrings.GetValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
queryStrings.GetRequiredValue<string>("application") + TreeAlias.EnsureStartsWith('/') + "/list/" + memberType.Alias)));
}
}

View File

@@ -75,7 +75,7 @@ namespace Umbraco.Web.Trees
//Create the normal create action
var item = menu.Items.Add<ActionNew>(Services.TextService, opensDialog: true);
item.NavigateToRoute($"{queryStrings.GetValue<string>("application")}/templates/edit/{id}?create=true");
item.NavigateToRoute($"{queryStrings.GetRequiredValue<string>("application")}/templates/edit/{id}?create=true");
if (id == Constants.System.Root.ToInvariantString())
{