2018-10-29 17:27:33 +11:00
using System ;
using System.Collections.Generic ;
2018-10-29 23:23:21 +11:00
using System.Linq ;
2018-10-29 17:27:33 +11:00
using LightInject ;
using Umbraco.Core.Composing ;
namespace Umbraco.Web.Actions
{
internal class ActionCollectionBuilder : LazyCollectionBuilderBase < ActionCollectionBuilder , ActionCollection , IAction >
{
public ActionCollectionBuilder ( IServiceContainer container )
: base ( container )
{ }
protected override ActionCollectionBuilder This = > this ;
2018-10-29 23:23:21 +11:00
protected override IEnumerable < IAction > CreateItems ( params object [ ] args )
{
var items = base . CreateItems ( args ) . ToList ( ) ;
2018-11-26 14:43:19 +01:00
2018-10-29 23:23:21 +11:00
//validate the items, no actions should exist that do not either expose notifications or permissions
2018-11-26 14:43:19 +01:00
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)}." ) ;
2018-10-29 23:23:21 +11:00
}
2018-10-29 17:27:33 +11:00
}
}