Wire up notification handlers in a composer

This commit is contained in:
Kenn Jacobsen
2021-03-03 09:02:29 +01:00
parent b3ab0c15e3
commit f8db15dcc7
10 changed files with 54 additions and 14 deletions

View File

@@ -1,5 +1,9 @@
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.PropertyEditors;
using Umbraco.Cms.Core.Routing;
using Umbraco.Cms.Infrastructure.Services.Notifications;
using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Compose
@@ -11,6 +15,49 @@ namespace Umbraco.Cms.Core.Compose
base.Compose(builder);
builder.Services.AddUnique<NotificationsComponent.Notifier>();
// add handlers for sending user notifications (i.e. emails)
builder.Services.AddUnique<UserNotificationsHandler.Notifier>();
builder
.AddNotificationHandler<SavedNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<SortedNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<PublishedNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<MovedNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<MovedToRecycleBinNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<CopiedNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<RolledBackNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<SentToPublishNotification<IContent>, UserNotificationsHandler>()
.AddNotificationHandler<UnpublishedNotification<IContent>, UserNotificationsHandler>();
// add handlers for building content relations
builder
.AddNotificationHandler<CopiedNotification<IContent>, RelateOnCopyHandler>()
.AddNotificationHandler<MovedNotification<IContent>, RelateOnTrashHandler>()
.AddNotificationHandler<MovedToRecycleBinNotification<IContent>, RelateOnTrashHandler>()
.AddNotificationHandler<MovedNotification<IMedia>, RelateOnTrashHandler>()
.AddNotificationHandler<MovedToRecycleBinNotification<IMedia>, RelateOnTrashHandler>();
// add notification handlers for property editors
builder
.AddNotificationHandler<SavingNotification<IContent>, BlockEditorPropertyHandler>()
.AddNotificationHandler<CopyingNotification<IContent>, BlockEditorPropertyHandler>()
.AddNotificationHandler<SavingNotification<IContent>, NestedContentPropertyHandler>()
.AddNotificationHandler<CopyingNotification<IContent>, NestedContentPropertyHandler>()
.AddNotificationHandler<CopiedNotification<IContent>, FileUploadPropertyEditor>()
.AddNotificationHandler<DeletedNotification<IContent>, FileUploadPropertyEditor>()
.AddNotificationHandler<DeletedNotification<IMedia>, FileUploadPropertyEditor>()
.AddNotificationHandler<SavingNotification<IMedia>, FileUploadPropertyEditor>()
.AddNotificationHandler<CopiedNotification<IContent>, ImageCropperPropertyEditor>()
.AddNotificationHandler<DeletedNotification<IContent>, ImageCropperPropertyEditor>()
.AddNotificationHandler<DeletedNotification<IMedia>, ImageCropperPropertyEditor>()
.AddNotificationHandler<SavingNotification<IMedia>, ImageCropperPropertyEditor>();
// add notification handlers for redirect tracking
builder
.AddNotificationHandler<PublishingNotification<IContent>, RedirectTrackingHandler>()
.AddNotificationHandler<PublishedNotification<IContent>, RedirectTrackingHandler>()
.AddNotificationHandler<MovingNotification<IContent>, RedirectTrackingHandler>()
.AddNotificationHandler<MovedNotification<IContent>, RedirectTrackingHandler>();
}
}
}

View File

@@ -1,12 +1,11 @@
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Services.Notifications;
namespace Umbraco.Cms.Infrastructure.Compose
namespace Umbraco.Cms.Core.Compose
{
// TODO: insert these notification handlers in core composition
// TODO: this should probably be moved to another namespace
public class RelateOnCopyHandler : INotificationHandler<CopiedNotification<IContent>>
{
private readonly IRelationService _relationService;

View File

@@ -8,7 +8,7 @@ using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Compose
{
// TODO: insert these notification handlers in core composition
// TODO: this should probably be moved to another namespace
// TODO: lots of duplicate code in this one, refactor
public sealed class RelateOnTrashHandler :
INotificationHandler<MovedNotification<IContent>>,

View File

@@ -21,8 +21,8 @@ using Umbraco.Extensions;
namespace Umbraco.Cms.Core.Compose
{
// TODO: insert these notification handlers in core composition
public sealed class NotificationsHandler :
// TODO: this should probably be moved to another namespace
public sealed class UserNotificationsHandler :
INotificationHandler<SavedNotification<IContent>>,
INotificationHandler<SortedNotification<IContent>>,
INotificationHandler<PublishedNotification<IContent>>,
@@ -37,7 +37,7 @@ namespace Umbraco.Cms.Core.Compose
private readonly ActionCollection _actions;
private readonly IContentService _contentService;
public NotificationsHandler(Notifier notifier, ActionCollection actions, IContentService contentService)
public UserNotificationsHandler(Notifier notifier, ActionCollection actions, IContentService contentService)
{
_notifier = notifier;
_actions = actions;

View File

@@ -11,7 +11,6 @@ namespace Umbraco.Cms.Core.PropertyEditors
/// <summary>
/// A handler for Block editors used to bind to notifications
/// </summary>
// TODO: insert these notification handlers in core composition
public class BlockEditorPropertyHandler : ComplexPropertyEditorContentNotificationHandler
{
private readonly BlockListEditorDataConverter _converter = new BlockListEditorDataConverter();

View File

@@ -9,7 +9,6 @@ using Umbraco.Extensions;
namespace Umbraco.Cms.Core.PropertyEditors
{
// TODO: insert these notification handlers in core composition
public abstract class ComplexPropertyEditorContentNotificationHandler :
INotificationHandler<SavingNotification<IContent>>,
INotificationHandler<CopyingNotification<IContent>>

View File

@@ -25,7 +25,6 @@ namespace Umbraco.Cms.Core.PropertyEditors
"fileupload",
Group = Constants.PropertyEditors.Groups.Media,
Icon = "icon-download-alt")]
// TODO: insert these notification handlers in core composition
public class FileUploadPropertyEditor : DataEditor, IMediaUrlGenerator,
INotificationHandler<CopiedNotification<IContent>>, INotificationHandler<DeletedNotification<IContent>>,
INotificationHandler<DeletedNotification<IMedia>>, INotificationHandler<SavingNotification<IMedia>>

View File

@@ -32,7 +32,6 @@ namespace Umbraco.Cms.Core.PropertyEditors
HideLabel = false,
Group = Constants.PropertyEditors.Groups.Media,
Icon = "icon-crop")]
// TODO: insert these notification handlers in core composition
public class ImageCropperPropertyEditor : DataEditor, IMediaUrlGenerator,
INotificationHandler<CopiedNotification<IContent>>, INotificationHandler<DeletedNotification<IContent>>,
INotificationHandler<DeletedNotification<IMedia>>, INotificationHandler<SavingNotification<IMedia>>

View File

@@ -8,7 +8,6 @@ namespace Umbraco.Cms.Core.PropertyEditors
/// <summary>
/// A handler for NestedContent used to bind to notifications
/// </summary>
// TODO: insert these notification handlers in core composition
public class NestedContentPropertyHandler : ComplexPropertyEditorContentNotificationHandler
{
protected override string EditorAlias => Constants.PropertyEditors.Aliases.NestedContent;

View File

@@ -20,7 +20,6 @@ namespace Umbraco.Cms.Core.Routing
/// strategy using rewriting rules probably
/// </para>
/// <para>recycle bin = moving to and from does nothing: to = the node is gone, where would we redirect? from = same</para>
// TODO: insert these notification handlers in core composition
public sealed class RedirectTrackingHandler :
INotificationHandler<PublishingNotification<IContent>>,
INotificationHandler<PublishedNotification<IContent>>,