This commit is contained in:
Stephan
2018-11-26 14:43:19 +01:00
parent 334fd778dd
commit 27c2b3ba5e
3 changed files with 15 additions and 16 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Composing;
@@ -22,19 +21,21 @@ namespace Umbraco.Web.Actions
internal IEnumerable<IAction> GetByLetters(IEnumerable<string> letters)
{
var all = this.ToArray();
return letters.Select(x => all.FirstOrDefault(y => y.Letter.ToString(CultureInfo.InvariantCulture) == x))
var actions = this.ToArray(); // no worry: internally, it's already an array
return letters
.Where(x => x.Length == 1)
.Select(x => actions.FirstOrDefault(y => y.Letter == x[0]))
.WhereNotNull()
.ToArray();
.ToList();
}
internal IReadOnlyList<IAction> FromEntityPermission(EntityPermission entityPermission)
{
var actions = this.ToArray(); // no worry: internally, it's already an array
return entityPermission.AssignedPermissions
.Where(x => x.Length == 1)
.Select(x => x.ToCharArray()[0])
.SelectMany(c => this.Where(x => x.Letter == c))
.Where(action => action != null)
.SelectMany(x => actions.Where(y => y.Letter == x[0]))
.WhereNotNull()
.ToList();
}
}

View File

@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using LightInject;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Actions
{
internal class ActionCollectionBuilder : LazyCollectionBuilderBase<ActionCollectionBuilder, ActionCollection, IAction>
@@ -19,13 +17,13 @@ namespace Umbraco.Web.Actions
protected override IEnumerable<IAction> CreateItems(params object[] args)
{
var items = base.CreateItems(args).ToList();
//validate the items, no actions should exist that do not either expose notifications or permissions
var invalid = items.Where(x => !x.CanBePermissionAssigned && !x.ShowInNotifier).ToList();
if (invalid.Count > 0)
{
throw new InvalidOperationException($"Invalid actions '{string.Join(", ", invalid.Select(x => x.Alias))}'. All {typeof(IAction)} implementations must be true for either {nameof(IAction.CanBePermissionAssigned)} or {nameof(IAction.ShowInNotifier)}");
}
return items;
var invalidItems = items.Where(x => !x.CanBePermissionAssigned && !x.ShowInNotifier).ToList();
if (invalidItems.Count == 0) return items;
var invalidActions = string.Join(", ", invalidItems.Select(x => "'" + x.Alias + "'"));
throw new InvalidOperationException($"Invalid actions {invalidActions}'. All {typeof(IAction)} implementations must be true for either {nameof(IAction.CanBePermissionAssigned)} or {nameof(IAction.ShowInNotifier)}.");
}
}
}

View File

@@ -181,7 +181,7 @@ namespace Umbraco.Web.Runtime
.Append<ContentFinderByRedirectUrl>();
composition.Container.RegisterSingleton<ISiteDomainHelper, SiteDomainHelper>();
composition.Container.RegisterSingleton<ICultureDictionaryFactory, DefaultCultureDictionaryFactory>();
// register *all* checks, except those marked [HideFromTypeFinder] of course